Merge branch 'main' into feat/new-theme-landing

This commit is contained in:
tangly1024.com
2023-07-06 10:37:05 +08:00
3 changed files with 33 additions and 22 deletions

View File

@@ -36,6 +36,7 @@ export async function getGlobalData({
delete db.collectionQuery
delete db.collectionId
delete db.collectionView
console.log(db)
return db
}

View File

@@ -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')) {
@@ -100,11 +90,23 @@ export default async function getPageProperties(id, block, schema, authToken, ta
properties.pageCover = mapImgUrl(block[id].value?.format?.page_cover, block[id].value) ?? ''
properties.pageCoverThumbnail = mapImgUrl(block[id].value?.format?.page_cover, block[id].value, 'block', 'pageCoverThumbnail') ?? ''
properties.content = value.content ?? []
properties.password = properties.password ? md5(properties.slug + properties.password) : ''
properties.tagItems = properties?.tags?.map(tag => {
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 ?? ''
}
properties.password = properties.password ? md5(properties.slug + properties.password) : ''
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)}`
}

View File

@@ -28,6 +28,7 @@ const Slug = props => {
*/
const validPassword = passInput => {
const encrypt = md5(post.slug + passInput)
console.log('passInput', passInput, post.slug)
if (passInput && encrypt === post.password) {
setLock(false)
return true