mirror of
https://github.com/d0zingcat/NotionNext.git
synced 2026-05-14 07:26:52 +00:00
修复日期文章格式的bug
This commit is contained in:
@@ -36,6 +36,7 @@ export async function getGlobalData({
|
||||
delete db.collectionQuery
|
||||
delete db.collectionId
|
||||
delete db.collectionView
|
||||
console.log(db)
|
||||
return db
|
||||
}
|
||||
|
||||
|
||||
@@ -76,16 +76,6 @@ export default async function getPageProperties(id, block, schema, authToken, ta
|
||||
// 映射值:用户个性化type和status字段的下拉框选项,在此映射回代码的英文标识
|
||||
mapProperties(properties)
|
||||
|
||||
if (properties.type === BLOG.NOTION_PROPERTY_NAME.type_post) {
|
||||
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) {
|
||||
// 菜单路径为空、作为可展开菜单使用
|
||||
properties.to = properties.slug ?? null
|
||||
properties.name = properties.title ?? ''
|
||||
}
|
||||
|
||||
// 开启伪静态路径
|
||||
if (BLOG.PSEUDO_STATIC) {
|
||||
if (!properties?.slug?.endsWith('.html') && !properties?.slug?.startsWith('http')) {
|
||||
@@ -105,6 +95,18 @@ export default async function getPageProperties(id, block, schema, authToken, ta
|
||||
return { name: tag, color: tagOptions?.find(t => t.value === tag)?.color || 'gray' }
|
||||
}) || []
|
||||
delete properties.content
|
||||
|
||||
// 处理URL
|
||||
if (properties.type === BLOG.NOTION_PROPERTY_NAME.type_post) {
|
||||
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) {
|
||||
// 菜单路径为空、作为可展开菜单使用
|
||||
properties.to = properties.slug ?? null
|
||||
properties.name = properties.title ?? ''
|
||||
}
|
||||
|
||||
return properties
|
||||
}
|
||||
|
||||
@@ -129,33 +131,40 @@ function mapProperties(properties) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取自定义URL
|
||||
* @param {*} postProperties
|
||||
* @returns
|
||||
*/
|
||||
function generateCustomizeUrl(postProperties) {
|
||||
let fullSlug = ''
|
||||
let fullPrefix = ''
|
||||
const allSlugPatterns = BLOG.POST_URL_PREFIX.split('/')
|
||||
allSlugPatterns.forEach((pattern, idx) => {
|
||||
if (pattern === '%year%' && postProperties?.publishTime) {
|
||||
const formatPostCreatedDate = new Date(postProperties?.publishTime)
|
||||
fullSlug += formatPostCreatedDate.getUTCFullYear()
|
||||
fullPrefix += formatPostCreatedDate.getUTCFullYear()
|
||||
} else if (pattern === '%month%' && postProperties?.publishTime) {
|
||||
const formatPostCreatedDate = new Date(postProperties?.publishTime)
|
||||
fullSlug += String(formatPostCreatedDate.getUTCMonth() + 1).padStart(2, 0)
|
||||
fullPrefix += String(formatPostCreatedDate.getUTCMonth() + 1).padStart(2, 0)
|
||||
} else if (pattern === '%day%' && postProperties?.publishTime) {
|
||||
const formatPostCreatedDate = new Date(postProperties?.publishTime)
|
||||
fullSlug += String(formatPostCreatedDate.getUTCDate()).padStart(2, 0)
|
||||
fullPrefix += String(formatPostCreatedDate.getUTCDate()).padStart(2, 0)
|
||||
} else if (pattern === '%slug%') {
|
||||
fullSlug += (postProperties.slug ?? postProperties.id)
|
||||
fullPrefix += (postProperties.slug ?? postProperties.id)
|
||||
} else if (!pattern.includes('%')) {
|
||||
fullSlug += pattern
|
||||
fullPrefix += pattern
|
||||
} else {
|
||||
return
|
||||
}
|
||||
if (idx !== allSlugPatterns.length - 1) {
|
||||
fullSlug += '/'
|
||||
fullPrefix += '/'
|
||||
}
|
||||
})
|
||||
if (fullSlug.startsWith('/')) {
|
||||
fullSlug = fullSlug.substring(1) // 去掉头部的"/"
|
||||
if (fullPrefix.startsWith('/')) {
|
||||
fullPrefix = fullPrefix.substring(1) // 去掉头部的"/"
|
||||
}
|
||||
|
||||
return `${fullSlug}/${(postProperties.slug ?? postProperties.id)}`
|
||||
if (fullPrefix.endsWith('/')) {
|
||||
fullPrefix = fullPrefix.substring(0, fullPrefix.length - 1) // 去掉尾部部的"/"
|
||||
}
|
||||
return `${fullPrefix}/${(postProperties.slug ?? postProperties.id)}`
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user