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

This commit is contained in:
tangly1024.com
2023-07-05 12:30:45 +08:00
37 changed files with 338 additions and 100 deletions

View File

@@ -13,7 +13,6 @@ export default function formatDate (date, local) {
? res.replace('年', '-').replace('月', '-').replace('日', '')
: res
}
export function formatDateFmt (timestamp, fmt) {
const date = new Date(timestamp)
const o = {

View File

@@ -45,7 +45,7 @@ export async function getAllPosts({ notionPageData, from, pageType }) {
// Sort by date
if (BLOG.POSTS_SORT_BY === 'date') {
posts.sort((a, b) => {
return b?.sortDate - a?.sortDate
return b?.publishDate - a?.publishDate
})
}
return posts

View File

@@ -20,23 +20,23 @@ import { mapImgUrl, compressImage } from './mapImage'
* @returns
*
*/
export async function getGlobalNotionData({
export async function getGlobalData({
pageId = BLOG.NOTION_PAGE_ID,
from
}) {
// 获取Notion数据
const notionPageData = deepClone(await getNotionPageData({ pageId, from }))
notionPageData.allNavPages = getNavPages({ allPages: notionPageData.allPages })
delete notionPageData.block
delete notionPageData.schema
delete notionPageData.rawMetadata
delete notionPageData.pageIds
delete notionPageData.viewIds
delete notionPageData.collection
delete notionPageData.collectionQuery
delete notionPageData.collectionId
delete notionPageData.collectionView
return notionPageData
// 从notion获取
const db = deepClone(await getNotionPageData({ pageId, from }))
// 不返回的敏感数据
delete db.block
delete db.schema
delete db.rawMetadata
delete db.pageIds
delete db.viewIds
delete db.collection
delete db.collectionQuery
delete db.collectionId
delete db.collectionView
return db
}
/**
@@ -48,8 +48,8 @@ function getLatestPosts({ allPages, from, latestPostCount }) {
const allPosts = allPages?.filter(page => page.type === 'Post' && page.status === 'Published')
const latestPosts = Object.create(allPosts).sort((a, b) => {
const dateA = new Date(a?.lastEditedTime || a?.sortDate)
const dateB = new Date(b?.lastEditedTime || b?.sortDate)
const dateA = new Date(a?.lastEditedTime || a?.publishDate)
const dateB = new Date(b?.lastEditedTime || b?.publishDate)
return dateB - dateA
})
return latestPosts.slice(0, latestPostCount)
@@ -69,12 +69,12 @@ export async function getNotionPageData({ pageId, from }) {
console.log('[缓存]:', `from:${from}`, `root-page-id:${pageId}`)
return data
}
const pageRecordMap = await getDataBaseInfoByNotionAPI({ pageId, from })
const db = await getDataBaseInfoByNotionAPI({ pageId, from })
// 存入缓存
if (pageRecordMap) {
await setDataToCache(cacheKey, pageRecordMap)
if (db) {
await setDataToCache(cacheKey, db)
}
return pageRecordMap
return db
}
/**
@@ -298,7 +298,7 @@ async function getDataBaseInfoByNotionAPI({ pageId, from }) {
// Sort by date
if (BLOG.POSTS_SORT_BY === 'date') {
allPages.sort((a, b) => {
return b?.sortDate - a?.sortDate
return b?.publishDate - a?.publishDate
})
}

View File

@@ -92,11 +92,9 @@ export default async function getPageProperties(id, block, schema, authToken, ta
properties.slug += '.html'
}
}
properties.sortDate = value?.date?.start_date || value.created_time
properties.createdTime = formatDate(new Date(value.created_time).toString(), BLOG.LANG)
properties.publishTime = value?.date?.start_date ? formatDate(new Date(value?.date?.start_date).toString, BLOG.LANG) : properties.createdTime
properties.lastEditedTime = formatDate(new Date(value?.last_edited_time).toString(), BLOG.LANG)
properties.publishDate = new Date(properties?.date?.start_date || value.created_time).getTime()
properties.publishTime = formatDate(properties.publishDate, BLOG.LANG)
properties.lastEditedTime = formatDate(new Date(value?.last_edited_time), BLOG.LANG)
properties.fullWidth = value.format?.page_full_width ?? false
properties.pageIcon = mapImgUrl(block[id].value?.format?.page_icon, block[id].value) ?? ''
properties.pageCover = mapImgUrl(block[id].value?.format?.page_cover, block[id].value) ?? ''

View File

@@ -46,7 +46,7 @@ export async function generateRss(posts) {
link: `${BLOG.LINK}/${post.slug}`,
description: post.summary,
content: await createFeedContent(post),
date: new Date(post?.publishTime || post?.createdTime)
date: new Date(post?.publishTime)
})
}

View File

@@ -24,7 +24,7 @@ export async function generateSitemapXml({ allPages }) {
allPages?.forEach(post => {
urls.push({
loc: `${BLOG.LINK}/${post.slug}`,
lastmod: new Date(post?.publishTime || post?.createdTime).toISOString().split('T')[0],
lastmod: new Date(post?.publishTime).toISOString().split('T')[0],
changefreq: 'daily'
})
})