diff --git a/lib/notion/getPageProperties.js b/lib/notion/getPageProperties.js index 64257eb6..5f68d904 100644 --- a/lib/notion/getPageProperties.js +++ b/lib/notion/getPageProperties.js @@ -118,11 +118,14 @@ export default async function getPageProperties( }) || [] delete properties.content - // 处理URL ,为文章添加一个href字段,专门用来跳转访问 + // 处理URL + // 1.按照用户配置的URL_PREFIX 转换一下slug + // 2.为文章添加一个href字段,存储最终调整的路径 if (properties.type === 'Post') { - properties.href = BLOG.POST_URL_PREFIX - ? generateCustomizeUrl(properties) - : properties.slug ?? properties.id + if (BLOG.POST_URL_PREFIX) { + properties.slug = generateCustomizeSlug(properties) + } + properties.href = properties.slug ?? properties.id } else if (properties.type === 'Page') { properties.href = properties.slug ?? properties.id } else if (properties.type === 'Menu' || properties.type === 'SubMenu') { @@ -206,7 +209,7 @@ function mapProperties(properties) { * @param {*} postProperties * @returns */ -function generateCustomizeUrl(postProperties) { +function generateCustomizeSlug(postProperties) { let fullPrefix = '' const allSlugPatterns = BLOG.POST_URL_PREFIX.split('/') allSlugPatterns.forEach((pattern, idx) => { diff --git a/pages/[prefix]/[slug]/[...suffix].js b/pages/[prefix]/[slug]/[...suffix].js index 5b2ceced..2050e81d 100644 --- a/pages/[prefix]/[slug]/[...suffix].js +++ b/pages/[prefix]/[slug]/[...suffix].js @@ -62,7 +62,10 @@ export async function getStaticProps({ props.post = props?.allPages?.find(p => { return ( p.type.indexOf('Menu') < 0 && - (p.slug === slug || p.slug === fullSlug || p.id === idToUuid(fullSlug)) + (p.slug === suffix || + p.slug === fullSlug.substring(fullSlug.lastIndexOf('/') + 1) || + p.slug === fullSlug || + p.id === idToUuid(fullSlug)) ) }) diff --git a/themes/simple/components/Header.js b/themes/simple/components/Header.js index f2b359ad..e5d71756 100644 --- a/themes/simple/components/Header.js +++ b/themes/simple/components/Header.js @@ -1,38 +1,54 @@ import LazyImage from '@/components/LazyImage' +import { siteConfig } from '@/lib/config' import Link from 'next/link' import CONFIG from '../config' import SocialButton from './SocialButton' -import { siteConfig } from '@/lib/config' /** * 网站顶部 * @returns */ -export default function Header (props) { +export default function Header(props) { const { siteInfo } = props return ( -
-
- - {/* 可使用一张单图作为logo */} -
-
- -
- -
-
{siteConfig('AUTHOR')}
-
-
-
- - -
- -
-
{siteConfig('DESCRIPTION')}
+
+
+ + {/* 可使用一张单图作为logo */} +
+
+
-
+ +
+
+ {siteConfig('AUTHOR')} +
+
+
+
+ + +
+ +
+
+ {siteConfig('DESCRIPTION')} +
+
+
) }