mirror of
https://github.com/d0zingcat/NotionNext.git
synced 2026-05-14 07:26:52 +00:00
Merge pull request #1243 from tangly1024/fix/article-prefix-date
Fix/article prefix date
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)}`
|
||||
}
|
||||
|
||||
@@ -28,8 +28,8 @@ export const MenuItemDrop = ({ link }) => {
|
||||
|
||||
{/* 子菜单 */}
|
||||
{hasSubMenu && <ul style={{ backdropFilter: 'blur(3px)' }} className={`${show ? 'visible opacity-100 top-12' : 'invisible opacity-0 top-20'} drop-shadow-md overflow-hidden rounded-md bg-white transition-all duration-300 z-20 absolute block `}>
|
||||
{link.subMenus.map(sLink => {
|
||||
return <li key={sLink.id} className='cursor-pointer hover:bg-indigo-300 text-gray-900 hover:text-black tracking-widest transition-all duration-200 dark:border-gray-800 py-1 pr-6 pl-2'>
|
||||
{link.subMenus.map((sLink, index) => {
|
||||
return <li key={index} className='cursor-pointer hover:bg-indigo-300 text-gray-900 hover:text-black tracking-widest transition-all duration-200 dark:border-gray-800 py-1 pr-6 pl-2'>
|
||||
<Link href={sLink.to}>
|
||||
<span className='text-sm text-nowrap font-extralight'>{link?.icon && <i className={sLink?.icon} > </i>}{sLink.title}</span>
|
||||
</Link>
|
||||
|
||||
Reference in New Issue
Block a user