diff --git a/package.json b/package.json index 8d68b740..3024d51a 100644 --- a/package.json +++ b/package.json @@ -14,7 +14,7 @@ }, "scripts": { "dev": "next dev", - "build": "next build && next-sitemap --config next-sitemap.config.js", + "build": "next build", "start": "next start", "post-build": "next-sitemap --config next-sitemap.config.js", "bundle-report": "ANALYZE=true yarn build" diff --git a/pages/sitemap.xml.js b/pages/sitemap.xml.js new file mode 100644 index 00000000..403d6cd7 --- /dev/null +++ b/pages/sitemap.xml.js @@ -0,0 +1,55 @@ +// pages/sitemap.xml.js +import { getServerSideSitemap } from 'next-sitemap' +import { getGlobalNotionData } from '@/lib/notion/getNotionData' +import BLOG from '@/blog.config' + +export const getServerSideProps = async (ctx) => { + const { allPages } = await getGlobalNotionData({ from: 'rss' }) + const defaultFields = [ + { + loc: `${BLOG.LINK}`, // Absolute url + lastmod: new Date(), + changefreq: 'daily', + priority: '0.7' + }, { + loc: `${BLOG.LINK}/archive`, // Absolute url + lastmod: new Date(), + changefreq: 'daily', + priority: '0.7' + }, { + loc: `${BLOG.LINK}/category`, // Absolute url + lastmod: new Date(), + changefreq: 'daily', + priority: '0.7' + }, { + loc: `${BLOG.LINK}/feed`, // Absolute url + lastmod: new Date(), + changefreq: 'daily', + priority: '0.7' + }, { + loc: `${BLOG.LINK}/search`, // Absolute url + lastmod: new Date(), + changefreq: 'daily', + priority: '0.7' + }, { + loc: `${BLOG.LINK}/tag`, // Absolute url + lastmod: new Date(), + changefreq: 'daily', + priority: '0.7' + } + ] + const postFields = allPages?.map(post => { + console.log(post) + return { + loc: `${BLOG.LINK}/${post.slug}`, // Absolute url + lastmod: new Date(post?.date?.start_date || post?.createdTime), + changefreq: 'daily', + priority: '0.7' + } + }) + const fields = defaultFields.concat(postFields) + + return getServerSideSitemap(ctx, fields) +} + +export default () => { }