Skip to content

Commit

Permalink
修复静态页面开启时,文章url前缀设为空无法访问的bug
Browse files Browse the repository at this point in the history
  • Loading branch information
tangly1024 committed Jun 4, 2024
1 parent a7a8135 commit 0a5c8c6
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 6 deletions.
5 changes: 3 additions & 2 deletions blog.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -205,9 +205,10 @@ const BLOG = {
'link,wechat,qq,weibo,email,facebook,twitter,telegram,messenger,line,reddit,whatsapp,linkedin', // 分享的服務,按顺序显示,逗号隔开
// 所有支持的分享服务:link(复制链接),wechat(微信),qq,weibo(微博),email(邮件),facebook,twitter,telegram,messenger,line,reddit,whatsapp,linkedin,vkshare,okshare,tumblr,livejournal,mailru,viber,workplace,pocket,instapaper,hatena

POST_URL_PREFIX: process.env.NEXT_PUBLIC_POST_URL_PREFIX || 'article',
// 文章URL前缀
POST_URL_PREFIX: process.env.NEXT_PUBLIC_POST_URL_PREFIX ?? 'article',
// POST类型文章的默认路径前缀,例如默认POST类型的路径是 /article/[slug]
// 如果此项配置为 '' 空, 则文章将没有前缀路径,使用场景: 希望文章前缀路径为 /post 的情况 支持多级
// 如果此项配置为 '' 空, 则文章将没有前缀路径
// 支援類似 WP 可自訂文章連結格式的功能:https://wordpress.org/documentation/article/customize-permalinks/,目前只先實作 %year%/%month%/%day%
// 例:如想連結改成前綴 article + 時間戳記,可變更為: 'article/%year%/%month%/%day%'

Expand Down
2 changes: 1 addition & 1 deletion lib/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export const siteConfig = (key, defaultVal = null, extendConfig = {}) => {
return null
}

// 特殊配置处理;某些配置只在服务端生效;而Global的NOTION_CONFIG仅限前端组件使用,因此需要从extendConfig中读取
// 特殊配置处理;以下配置只在服务端生效;而Global的NOTION_CONFIG仅限前端组件使用,因此需要从extendConfig中读取
switch (key) {
case 'NEXT_REVALIDATE_SECOND':
case 'POST_RECOMMEND_COUNT':
Expand Down
2 changes: 1 addition & 1 deletion lib/notion/getPageProperties.js
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ export function adjustPageProperties(properties, NOTION_CONFIG) {
}

// 开启伪静态路径
if (JSON.parse(NOTION_CONFIG?.PSEUDO_STATIC || BLOG.PSEUDO_STATIC)) {
if (siteConfig('PSEUDO_STATIC', false, NOTION_CONFIG)) {
if (
!properties?.href?.endsWith('.html') &&
!properties?.href?.startsWith('http')
Expand Down
4 changes: 2 additions & 2 deletions pages/[prefix]/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ export async function getStaticProps({ params: { prefix }, locale }) {
let fullSlug = prefix
const from = `slug-props-${fullSlug}`
const props = await getGlobalData({ from, locale })
if (siteConfig('PSEUDO_STATIC', BLOG.PSEUDO_STATIC, props.NOTION_CONFIG)) {
if (siteConfig('PSEUDO_STATIC', false, props.NOTION_CONFIG)) {
if (!fullSlug.endsWith('.html')) {
fullSlug += '.html'
}
Expand All @@ -134,7 +134,7 @@ export async function getStaticProps({ params: { prefix }, locale }) {
props.post = props?.allPages?.find(p => {
return (
p.type.indexOf('Menu') < 0 &&
(p.slug === fullSlug || p.id === idToUuid(fullSlug))
(p.slug === prefix || p.id === idToUuid(prefix))
)
})

Expand Down

0 comments on commit 0a5c8c6

Please sign in to comment.