url前缀 %category% 支持映射

This commit is contained in:
tangly1024
2024-05-12 17:39:47 +08:00
parent 6f03028181
commit a5bab22409

View File

@@ -224,6 +224,8 @@ function generateCustomizeSlug(postProperties, NOTION_CONFIG) {
NOTION_CONFIG
).split('/')
const POST_URL_PREFIX_MAPPING_CATEGORY = siteConfig('POST_URL_PREFIX_MAPPING_CATEGORY',{},NOTION_CONFIG)
allSlugPatterns.forEach((pattern, idx) => {
if (pattern === '%year%' && postProperties?.publishDay) {
const formatPostCreatedDate = new Date(postProperties?.publishDay)
@@ -240,7 +242,12 @@ function generateCustomizeSlug(postProperties, NOTION_CONFIG) {
} else if (pattern === '%slug%') {
fullPrefix += postProperties.slug ?? postProperties.id
} else if (pattern === '%category%' && postProperties?.category) {
fullPrefix += postProperties.category
let categoryPrefix = postProperties.category
// 允许映射分类名通常用来将中文分类映射成英文美化url.
if(POST_URL_PREFIX_MAPPING_CATEGORY[postProperties?.category]){
categoryPrefix = POST_URL_PREFIX_MAPPING_CATEGORY[postProperties?.category]
}
fullPrefix += categoryPrefix
} else if (!pattern.includes('%')) {
fullPrefix += pattern
} else {