slug 链接调试

This commit is contained in:
tangly1024.com
2024-05-08 16:39:31 +08:00
parent 9b78eb499c
commit 651f6370cf
3 changed files with 51 additions and 29 deletions

View File

@@ -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) => {

View File

@@ -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))
)
})

View File

@@ -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 (
<header className="text-center justify-between items-center px-6 bg-white h-80 dark:bg-black relative z-10">
<div className="float-none inline-block py-12">
<Link href='/'>
{/* 可使用一张单图作为logo */}
<div className='flex space-x-6'>
<div className='hover:rotate-45 hover:scale-125 transform duration-200 cursor-pointer justify-center items-center flex'>
<LazyImage priority={true} src={siteInfo?.icon} className='rounded-full' width={100} height={100} alt={siteConfig('AUTHOR')} />
</div>
<div className='flex-col flex justify-center'>
<div className='text-2xl font-serif dark:text-white py-2 hover:scale-105 transform duration-200'>{siteConfig('AUTHOR')}</div>
<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) }} />
</div>
</div>
</Link>
<div className='flex justify-center'>
<SocialButton />
</div>
<div className='text-xs mt-4 text-gray-500 dark:text-gray-300'>{siteConfig('DESCRIPTION')}</div>
<header className='text-center justify-between items-center px-6 bg-white h-80 dark:bg-black relative z-10'>
<div className='float-none inline-block py-12'>
<Link href='/'>
{/* 可使用一张单图作为logo */}
<div className='flex space-x-6 justify-center'>
<div className='hover:rotate-45 hover:scale-125 transform duration-200 cursor-pointer justify-center items-center flex'>
<LazyImage
priority={true}
src={siteInfo?.icon}
className='rounded-full'
width={100}
height={100}
alt={siteConfig('AUTHOR')}
/>
</div>
</header>
<div className='flex-col flex justify-center'>
<div className='text-2xl font-serif dark:text-white py-2 hover:scale-105 transform duration-200'>
{siteConfig('AUTHOR')}
</div>
<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)
}}
/>
</div>
</div>
</Link>
<div className='flex justify-center'>
<SocialButton />
</div>
<div className='text-xs mt-4 text-gray-500 dark:text-gray-300'>
{siteConfig('DESCRIPTION')}
</div>
</div>
</header>
)
}