最后更新时间

This commit is contained in:
tangly1024
2022-04-06 15:45:24 +08:00
parent ac51b696cd
commit ef62044a99
11 changed files with 125 additions and 68 deletions

View File

@@ -2,6 +2,7 @@ import BLOG from '@/blog.config'
import getAllPageIds from './getAllPageIds'
import getPageProperties from './getPageProperties'
import { defaultMapImageUrl } from 'react-notion-x'
import formatDate from '@/lib/formatDate'
import { getNotionPageData } from '@/lib/notion/getNotionData'
import { delCacheData } from '@/lib/cache/cache_manager'
@@ -12,7 +13,7 @@ import { delCacheData } from '@/lib/cache/cache_manager'
* @param pageType 页面类型数组 ['Post','Page']
* @returns {Promise<*[]>}
*/
export async function getAllPosts ({ notionPageData, from, pageType }) {
export async function getAllPosts({ notionPageData, from, pageType }) {
if (!notionPageData) {
notionPageData = await getNotionPageData({ from })
}
@@ -31,8 +32,8 @@ export async function getAllPosts ({ notionPageData, from, pageType }) {
const id = pageIds[i]
const properties = (await getPageProperties(id, pageBlock, schema)) || null
properties.slug = properties.slug ?? properties.id
properties.createdTime = new Date(pageBlock[id].value?.created_time).toString() // FIXME 似乎没有created_time 字段了
properties.lastEditedTime = new Date(pageBlock[id].value?.last_edited_time).toString() // FIXME 似乎没有created_time 字段了
properties.createdTime = formatDate(new Date(pageBlock[id].value?.created_time).toString(), BLOG.LANG)
properties.lastEditedTime = formatDate(new Date(pageBlock[id].value?.last_edited_time).toString(), BLOG.LANG)
properties.fullWidth = pageBlock[id].value?.format?.page_full_width ?? false
properties.page_cover = getPostCover(id, pageBlock) ?? null
properties.content = pageBlock[id].value?.content ?? []
@@ -65,7 +66,7 @@ export async function getAllPosts ({ notionPageData, from, pageType }) {
}
// 从Block获取封面图;优先取PageCover否则取内容图片
function getPostCover (id, block) {
function getPostCover(id, block) {
const pageCover = block[id].value?.format?.page_cover
if (pageCover) {
if (pageCover.startsWith('/')) return 'https://www.notion.so' + pageCover
@@ -78,7 +79,7 @@ function getPostCover (id, block) {
* @param {*} param0
* @returns
*/
export async function getAllPostCount ({ notionPageData, from }) {
export async function getAllPostCount({ notionPageData, from }) {
if (!notionPageData) {
notionPageData = await getNotionPageData({ from })
}