mirror of
https://github.com/d0zingcat/NotionNext.git
synced 2026-05-14 07:26:52 +00:00
sitemap.xml手动实现
This commit is contained in:
@@ -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"
|
||||
|
||||
55
pages/sitemap.xml.js
Normal file
55
pages/sitemap.xml.js
Normal file
@@ -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 () => { }
|
||||
Reference in New Issue
Block a user