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