From dd6dc5a93ad49630acfef7d1358a8a38554793f6 Mon Sep 17 00:00:00 2001 From: tangly1024 Date: Fri, 7 Jul 2023 21:10:37 +0800 Subject: [PATCH] fix/slug-undefined-html --- blog.config.js | 2 +- lib/notion/getPageProperties.js | 12 ++++++------ pages/[...slug].js | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/blog.config.js b/blog.config.js index 9ee86fbd..da297c0c 100644 --- a/blog.config.js +++ b/blog.config.js @@ -3,7 +3,7 @@ const BLOG = { // Important page_id!!!Duplicate Template from https://www.notion.so/tanghh/02ab3b8678004aa69e9e415905ef32a5 NOTION_PAGE_ID: process.env.NOTION_PAGE_ID || '02ab3b8678004aa69e9e415905ef32a5', - PSEUDO_STATIC: false, // 伪静态路径,开启后所有文章URL都以 .html 结尾。 + PSEUDO_STATIC: process.env.NEXT_PUBLIC_PSEUDO_STATIC || false, // 伪静态路径,开启后所有文章URL都以 .html 结尾。 NEXT_REVALIDATE_SECOND: process.env.NEXT_PUBLIC_REVALIDATE_SECOND || 5, // 更新内容缓存间隔 单位(秒);即每个页面有5秒的纯静态期、此期间无论多少次访问都不会抓取notion数据;调大该值有助于节省Vercel资源、同时提升访问速率,但也会使文章更新有延迟。 THEME: process.env.NEXT_PUBLIC_THEME || 'hexo', // 主题, 支持 ['next','hexo',"fukasawa','medium','example','matery','gitbook','simple'] @see https://preview.tangly1024.com THEME_SWITCH: process.env.NEXT_PUBLIC_THEME_SWITCH || false, // 是否显示切换主题按钮 diff --git a/lib/notion/getPageProperties.js b/lib/notion/getPageProperties.js index 7c47462f..47e497ce 100644 --- a/lib/notion/getPageProperties.js +++ b/lib/notion/getPageProperties.js @@ -76,12 +76,6 @@ export default async function getPageProperties(id, block, schema, authToken, ta // 映射值:用户个性化type和status字段的下拉框选项,在此映射回代码的英文标识 mapProperties(properties) - // 开启伪静态路径 - if (BLOG.PSEUDO_STATIC) { - if (!properties?.slug?.endsWith('.html') && !properties?.slug?.startsWith('http')) { - properties.slug += '.html' - } - } properties.publishDate = new Date(properties?.date?.start_date || value.created_time).getTime() properties.publishTime = formatDate(properties.publishDate, BLOG.LANG) properties.lastEditedTime = formatDate(new Date(value?.last_edited_time), BLOG.LANG) @@ -107,6 +101,12 @@ export default async function getPageProperties(id, block, schema, authToken, ta } properties.password = properties.password ? md5(properties.slug + properties.password) : '' + // 开启伪静态路径 + if (JSON.parse(BLOG.PSEUDO_STATIC)) { + if (!properties?.slug?.endsWith('.html') && !properties?.slug?.startsWith('http')) { + properties.slug += '.html' + } + } return properties } diff --git a/pages/[...slug].js b/pages/[...slug].js index 65be2306..b106350d 100644 --- a/pages/[...slug].js +++ b/pages/[...slug].js @@ -97,7 +97,7 @@ export async function getStaticPaths() { export async function getStaticProps({ params: { slug } }) { let fullSlug = slug.join('/') - if (BLOG.PSEUDO_STATIC) { + if (JSON.parse(BLOG.PSEUDO_STATIC)) { if (!fullSlug.endsWith('.html')) { fullSlug += '.html' }