diff --git a/lib/lang/en-US.js b/lib/lang/en-US.js index 00414875..d51c0a5a 100644 --- a/lib/lang/en-US.js +++ b/lib/lang/en-US.js @@ -32,7 +32,9 @@ export default { ARTICLE_DETAIL: 'Article Details', PASSWORD_ERROR: 'Password Error!', ARTICLE_LOCK_TIPS: 'Please Enter the password:', - SUBMIT: 'Submit' + SUBMIT: 'Submit', + POST_TIME: 'Post on', + LAST_EDITED_TIME: 'Last edited time' }, PAGINATION: { PREV: 'Prev', diff --git a/lib/lang/zh-CN.js b/lib/lang/zh-CN.js index 4417a270..435aeb96 100644 --- a/lib/lang/zh-CN.js +++ b/lib/lang/zh-CN.js @@ -34,7 +34,9 @@ export default { ARTICLE_DETAIL: '文章详情', PASSWORD_ERROR: '密码错误!', ARTICLE_LOCK_TIPS: '文章已上锁,请输入访问密码', - SUBMIT: '提交' + SUBMIT: '提交', + POST_TIME: '发布于', + LAST_EDITED_TIME: '最后更新' }, PAGINATION: { PREV: '上一页', diff --git a/lib/lang/zh-TW.js b/lib/lang/zh-TW.js index a7f648f4..4901fc37 100644 --- a/lib/lang/zh-TW.js +++ b/lib/lang/zh-TW.js @@ -34,7 +34,9 @@ export default { ARTICLE_DETAIL: '完整文章', PASSWORD_ERROR: '密碼錯誤!', ARTICLE_LOCK_TIPS: '文章已上鎖,請輸入訪問密碼', - SUBMIT: '提交' + SUBMIT: '提交', + POST_TIME: '发布于', + LAST_EDITED_TIME: '最后更新日期' }, PAGINATION: { PREV: '上一頁', diff --git a/lib/notion/getAllPosts.js b/lib/notion/getAllPosts.js index cfbbafa8..fbe588da 100644 --- a/lib/notion/getAllPosts.js +++ b/lib/notion/getAllPosts.js @@ -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 }) } diff --git a/lib/notion/getPageProperties.js b/lib/notion/getPageProperties.js index 56ded539..3dcc7735 100644 --- a/lib/notion/getPageProperties.js +++ b/lib/notion/getPageProperties.js @@ -1,7 +1,7 @@ import { getTextContent, getDateValue } from 'notion-utils' import { NotionAPI } from 'notion-client' -async function getPageProperties (id, block, schema, authToken) { +async function getPageProperties(id, block, schema, authToken) { const rawProperties = Object.entries(block?.[id]?.value?.properties || []) const excludeProperties = ['date', 'select', 'multi_select', 'person'] const properties = {} diff --git a/lib/notion/getPostBlocks.js b/lib/notion/getPostBlocks.js index 0db5a582..52cbdf32 100644 --- a/lib/notion/getPostBlocks.js +++ b/lib/notion/getPostBlocks.js @@ -2,7 +2,7 @@ import BLOG from '@/blog.config' import { NotionAPI } from 'notion-client' import { getDataFromCache, setDataToCache } from '@/lib/cache/cache_manager' -export async function getPostBlocks (id, from, slice, retryCount = 3) { +export async function getPostBlocks(id, from, slice, retryCount = 3) { const cacheKey = 'page_block_' + id let pageBlock = await getDataFromCache(cacheKey) if (pageBlock) { @@ -32,13 +32,13 @@ export async function getPostBlocks (id, from, slice, retryCount = 3) { } /** - * + * 获取到的blockMap删除不需要的字段 * @param {*} id 页面ID * @param {*} pageBlock 页面元素 * @param {*} slice 截取数量 * @returns */ -function filterPostBlocks (id, pageBlock, slice) { +function filterPostBlocks(id, pageBlock, slice) { const clonePageBlock = deepClone(pageBlock) let count = 0 @@ -51,8 +51,6 @@ function filterPostBlocks (id, pageBlock, slice) { count++ delete b?.role delete b?.value?.version - delete b?.value?.created_time - delete b?.value?.last_edited_time delete b?.value?.created_by_table delete b?.value?.created_by_id delete b?.value?.last_edited_by_table @@ -67,7 +65,7 @@ function filterPostBlocks (id, pageBlock, slice) { return clonePageBlock } -function deepClone (obj) { +function deepClone(obj) { const newObj = Array.isArray(obj) ? [] : {} if (obj && typeof obj === 'object') { for (const key in obj) { diff --git a/themes/example/LayoutSlug.js b/themes/example/LayoutSlug.js index 0372d507..70482b5d 100644 --- a/themes/example/LayoutSlug.js +++ b/themes/example/LayoutSlug.js @@ -2,6 +2,9 @@ import { getPageTableOfContents } from 'notion-utils' import LayoutBase from './LayoutBase' import { ArticleLock } from './components/ArticleLock' import NotionPage from '@/components/NotionPage' +import Link from 'next/link' +import { useGlobal } from '@/lib/global' +import formatDate from '@/lib/formatDate' export const LayoutSlug = props => { const { post, lock, validPassword } = props @@ -10,6 +13,9 @@ export const LayoutSlug = props => { post.toc = getPageTableOfContents(post, post.blockMap) } + const { locale } = useGlobal() + const date = formatDate(post?.date?.start_date || post.createdTime, locale.LOCALE) + return (
@@ -18,6 +24,42 @@ export const LayoutSlug = props => { {lock && } {!lock &&
+
+
+ + + + {post.category} + + + | + + {post.type[0] !== 'Page' && (<> + + + {date} + + + | + + {locale.COMMON.LAST_EDITED_TIME}: {post.lastEditedTime} + + | + + )} + + + +   + + +
+ +
+ {post.blockMap && }
} diff --git a/themes/fukasawa/components/ArticleDetail.js b/themes/fukasawa/components/ArticleDetail.js index 20d06fbd..cbdfa0b7 100644 --- a/themes/fukasawa/components/ArticleDetail.js +++ b/themes/fukasawa/components/ArticleDetail.js @@ -51,13 +51,15 @@ export default function ArticleDetail({ post, recommendPosts, prev, next }) { | + + {locale.COMMON.LAST_EDITED_TIME}: {post.lastEditedTime} + )} -
+
  - |
diff --git a/themes/hexo/components/HeaderArticle.js b/themes/hexo/components/HeaderArticle.js index 23ebdaf0..ce9b3484 100644 --- a/themes/hexo/components/HeaderArticle.js +++ b/themes/hexo/components/HeaderArticle.js @@ -3,7 +3,7 @@ import { useGlobal } from '@/lib/global' import formatDate from '@/lib/formatDate' import { useEffect } from 'react' -export default function HeaderArticle ({ post, siteInfo }) { +export default function HeaderArticle({ post, siteInfo }) { const headerImage = post?.page_cover ? `url("${post.page_cover}")` : `url("${siteInfo?.pageCover}")` const { isDarkMode } = useGlobal() @@ -47,52 +47,53 @@ export default function HeaderArticle ({ post, siteInfo }) { } return ( - + +
) } diff --git a/themes/medium/components/ArticleDetail.js b/themes/medium/components/ArticleDetail.js index fec2baa7..a0ed321e 100644 --- a/themes/medium/components/ArticleDetail.js +++ b/themes/medium/components/ArticleDetail.js @@ -37,6 +37,9 @@ export const ArticleDetail = props => {
{date}
+
+ {locale.COMMON.LAST_EDITED_TIME}: {post.lastEditedTime} +
  diff --git a/themes/next/components/ArticleDetail.js b/themes/next/components/ArticleDetail.js index bccc778f..ba49b0a6 100644 --- a/themes/next/components/ArticleDetail.js +++ b/themes/next/components/ArticleDetail.js @@ -42,7 +42,7 @@ export default function ArticleDetail(props) {
-
+
{post.category && <> @@ -61,19 +61,23 @@ export default function ArticleDetail(props) { | +
+ +   + +
+ )} -
- -   - - | -
+ +
+ {locale.COMMON.LAST_EDITED_TIME} {post.lastEditedTime} +
+
-
}