Skip to content

Commit 651f637

Browse files
committed
slug 链接调试
1 parent 9b78eb4 commit 651f637

File tree

3 files changed

+50
-28
lines changed

3 files changed

+50
-28
lines changed

lib/notion/getPageProperties.js

+8-5
Original file line numberDiff line numberDiff line change
@@ -118,11 +118,14 @@ export default async function getPageProperties(
118118
}) || []
119119
delete properties.content
120120

121-
// 处理URL ,为文章添加一个href字段,专门用来跳转访问
121+
// 处理URL
122+
// 1.按照用户配置的URL_PREFIX 转换一下slug
123+
// 2.为文章添加一个href字段,存储最终调整的路径
122124
if (properties.type === 'Post') {
123-
properties.href = BLOG.POST_URL_PREFIX
124-
? generateCustomizeUrl(properties)
125-
: properties.slug ?? properties.id
125+
if (BLOG.POST_URL_PREFIX) {
126+
properties.slug = generateCustomizeSlug(properties)
127+
}
128+
properties.href = properties.slug ?? properties.id
126129
} else if (properties.type === 'Page') {
127130
properties.href = properties.slug ?? properties.id
128131
} else if (properties.type === 'Menu' || properties.type === 'SubMenu') {
@@ -206,7 +209,7 @@ function mapProperties(properties) {
206209
* @param {*} postProperties
207210
* @returns
208211
*/
209-
function generateCustomizeUrl(postProperties) {
212+
function generateCustomizeSlug(postProperties) {
210213
let fullPrefix = ''
211214
const allSlugPatterns = BLOG.POST_URL_PREFIX.split('/')
212215
allSlugPatterns.forEach((pattern, idx) => {

pages/[prefix]/[slug]/[...suffix].js

+4-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,10 @@ export async function getStaticProps({
6262
props.post = props?.allPages?.find(p => {
6363
return (
6464
p.type.indexOf('Menu') < 0 &&
65-
(p.slug === slug || p.slug === fullSlug || p.id === idToUuid(fullSlug))
65+
(p.slug === suffix ||
66+
p.slug === fullSlug.substring(fullSlug.lastIndexOf('/') + 1) ||
67+
p.slug === fullSlug ||
68+
p.id === idToUuid(fullSlug))
6669
)
6770
})
6871

themes/simple/components/Header.js

+38-22
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,54 @@
11
import LazyImage from '@/components/LazyImage'
2+
import { siteConfig } from '@/lib/config'
23
import Link from 'next/link'
34
import CONFIG from '../config'
45
import SocialButton from './SocialButton'
5-
import { siteConfig } from '@/lib/config'
66

77
/**
88
* 网站顶部
99
* @returns
1010
*/
11-
export default function Header (props) {
11+
export default function Header(props) {
1212
const { siteInfo } = props
1313

1414
return (
15-
<header className="text-center justify-between items-center px-6 bg-white h-80 dark:bg-black relative z-10">
16-
<div className="float-none inline-block py-12">
17-
<Link href='/'>
18-
{/* 可使用一张单图作为logo */}
19-
<div className='flex space-x-6'>
20-
<div className='hover:rotate-45 hover:scale-125 transform duration-200 cursor-pointer justify-center items-center flex'>
21-
<LazyImage priority={true} src={siteInfo?.icon} className='rounded-full' width={100} height={100} alt={siteConfig('AUTHOR')} />
22-
</div>
23-
24-
<div className='flex-col flex justify-center'>
25-
<div className='text-2xl font-serif dark:text-white py-2 hover:scale-105 transform duration-200'>{siteConfig('AUTHOR')}</div>
26-
<div className='font-light dark:text-white py-2 hover:scale-105 transform duration-200 text-center' dangerouslySetInnerHTML={{ __html: siteConfig('SIMPLE_LOGO_DESCRIPTION', null, CONFIG) }} />
27-
</div>
28-
</div>
29-
</Link>
15+
<header className='text-center justify-between items-center px-6 bg-white h-80 dark:bg-black relative z-10'>
16+
<div className='float-none inline-block py-12'>
17+
<Link href='/'>
18+
{/* 可使用一张单图作为logo */}
19+
<div className='flex space-x-6 justify-center'>
20+
<div className='hover:rotate-45 hover:scale-125 transform duration-200 cursor-pointer justify-center items-center flex'>
21+
<LazyImage
22+
priority={true}
23+
src={siteInfo?.icon}
24+
className='rounded-full'
25+
width={100}
26+
height={100}
27+
alt={siteConfig('AUTHOR')}
28+
/>
29+
</div>
3030

31-
<div className='flex justify-center'>
32-
<SocialButton />
33-
</div>
34-
<div className='text-xs mt-4 text-gray-500 dark:text-gray-300'>{siteConfig('DESCRIPTION')}</div>
31+
<div className='flex-col flex justify-center'>
32+
<div className='text-2xl font-serif dark:text-white py-2 hover:scale-105 transform duration-200'>
33+
{siteConfig('AUTHOR')}
34+
</div>
35+
<div
36+
className='font-light dark:text-white py-2 hover:scale-105 transform duration-200 text-center'
37+
dangerouslySetInnerHTML={{
38+
__html: siteConfig('SIMPLE_LOGO_DESCRIPTION', null, CONFIG)
39+
}}
40+
/>
3541
</div>
36-
</header>
42+
</div>
43+
</Link>
44+
45+
<div className='flex justify-center'>
46+
<SocialButton />
47+
</div>
48+
<div className='text-xs mt-4 text-gray-500 dark:text-gray-300'>
49+
{siteConfig('DESCRIPTION')}
50+
</div>
51+
</div>
52+
</header>
3753
)
3854
}

0 commit comments

Comments
 (0)