diff --git a/lib/db/getSiteData.js b/lib/db/getSiteData.js index fb916374..84e764fb 100755 --- a/lib/db/getSiteData.js +++ b/lib/db/getSiteData.js @@ -5,7 +5,7 @@ import getAllPageIds from '@/lib/notion/getAllPageIds' import { getAllTags } from '@/lib/notion/getAllTags' import { getConfigMapFromConfigPage } from '@/lib/notion/getNotionConfig' import getPageProperties, { - adjustPageProperties + adjustPageProperties } from '@/lib/notion/getPageProperties' import { fetchInBatches, getPage } from '@/lib/notion/getPostBlocks' import { compressImage, mapImgUrl } from '@/lib/notion/mapImage' @@ -512,6 +512,7 @@ async function getDataBaseInfoByNotionAPI({ pageId, from }) { adjustPageProperties(element, NOTION_CONFIG) }) + // 站点基础信息 const siteInfo = getSiteInfo({ collection, block, pageId }) // 文章计数 diff --git a/next.config.js b/next.config.js index ce46d750..54b30cac 100644 --- a/next.config.js +++ b/next.config.js @@ -32,6 +32,16 @@ const locales = (function () { return langs })() +// 编译前执行 +const preBuild = (function () { + // 删除 public/sitemap.xml 文件 ; 否则会和/pages/sitemap.xml.js 冲突。 + const sitemapPath = path.resolve(__dirname, 'public', 'sitemap.xml') + if (fs.existsSync(sitemapPath)) { + fs.unlinkSync(sitemapPath) + console.log('Deleted existing sitemap.xml from public directory') + } +})() + /** * 扫描指定目录下的文件夹名,用于获取所有主题 * @param {*} directory diff --git a/pages/[prefix]/[slug]/[...suffix].js b/pages/[prefix]/[slug]/[...suffix].js index 8e645faa..d9567c4c 100644 --- a/pages/[prefix]/[slug]/[...suffix].js +++ b/pages/[prefix]/[slug]/[...suffix].js @@ -30,17 +30,17 @@ export async function getStaticPaths() { const from = 'slug-paths' const { allPages } = await getGlobalData({ from }) - + const paths = allPages + ?.filter(row => checkSlugHasMorThanTwoSlash(row)) + .map(row => ({ + params: { + prefix: row.slug.split('/')[0], + slug: row.slug.split('/')[1], + suffix: row.slug.split('/').slice(2) + } + })) return { - paths: allPages - ?.filter(row => checkSlugHasMorThanTwoSlash(row)) - .map(row => ({ - params: { - prefix: row.slug.split('/')[0], - slug: row.slug.split('/')[1], - suffix: row.slug.split('/').slice(1) - } - })), + paths: paths, fallback: true } }