mirror of
https://github.com/d0zingcat/NotionNext.git
synced 2026-05-19 07:26:50 +00:00
feat(post): support customize post's permalink format
This commit is contained in:
@@ -77,7 +77,7 @@ export default async function getPageProperties(id, block, schema, authToken, ta
|
||||
mapProperties(properties)
|
||||
|
||||
if (properties.type === BLOG.NOTION_PROPERTY_NAME.type_post) {
|
||||
properties.slug = BLOG.POST_URL_PREFIX ? (BLOG.POST_URL_PREFIX + '/' + (properties.slug ?? properties.id)) : (properties.slug ?? properties.id)
|
||||
properties.slug = (BLOG.POST_URL_PREFIX) ? generateCustomizeUrl(properties) : (properties.slug ?? properties.id)
|
||||
} else if (properties.type === BLOG.NOTION_PROPERTY_NAME.type_page) {
|
||||
properties.slug = properties.slug ?? properties.id
|
||||
} else if (properties.type === BLOG.NOTION_PROPERTY_NAME.type_menu || properties.type === BLOG.NOTION_PROPERTY_NAME.type_sub_menu) {
|
||||
@@ -147,3 +147,30 @@ function mapProperties(properties) {
|
||||
properties.status = 'Invisible'
|
||||
}
|
||||
}
|
||||
|
||||
function generateCustomizeUrl(postProperties) {
|
||||
let fullSlug = ''
|
||||
const allSlugPatterns = BLOG.POST_URL_PREFIX.split('/')
|
||||
allSlugPatterns.forEach((pattern, idx) => {
|
||||
if (pattern === '%year%' && postProperties?.date?.start_date) {
|
||||
const formatPostCreatedDate = new Date(postProperties?.date?.start_date)
|
||||
fullSlug += formatPostCreatedDate.getUTCFullYear()
|
||||
} else if (pattern === '%month%' && postProperties?.date?.start_date) {
|
||||
const formatPostCreatedDate = new Date(postProperties?.date?.start_date)
|
||||
fullSlug += (formatPostCreatedDate.getUTCMonth() + 1)
|
||||
} else if (pattern === '%day%' && postProperties?.date?.start_date) {
|
||||
const formatPostCreatedDate = new Date(postProperties?.date?.start_date)
|
||||
fullSlug += formatPostCreatedDate.getUTCDate()
|
||||
} else if (pattern === '%slug%') {
|
||||
fullSlug += (postProperties.slug ?? postProperties.id)
|
||||
} else if (!pattern.includes('%')) {
|
||||
fullSlug += pattern
|
||||
} else {
|
||||
return
|
||||
}
|
||||
if (idx !== allSlugPatterns.length - 1) {
|
||||
fullSlug += '/'
|
||||
}
|
||||
})
|
||||
return `${fullSlug}/${(postProperties.slug ?? postProperties.id)}`
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user