From cab1c2da68332d4eb3aad172470796b0ba09eaea Mon Sep 17 00:00:00 2001 From: tangly1024 Date: Thu, 7 Apr 2022 17:00:10 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9C=80=E6=96=B0=E6=96=87=E7=AB=A0=E7=BB=84?= =?UTF-8?q?=E4=BB=B6=EF=BC=8C=E6=8C=89=E4=BF=AE=E6=94=B9=E6=97=B6=E9=97=B4?= =?UTF-8?q?=E5=80=92=E5=BA=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/notion/getNotionData.js | 34 ++++++++++------------ themes/hexo/LayoutBase.js | 24 +++++++-------- themes/hexo/components/LatestPostsGroup.js | 9 +++--- themes/hexo/components/SideRight.js | 12 ++++---- themes/next/LayoutIndex.js | 4 +-- themes/next/components/LatestPostsGroup.js | 8 ++--- themes/next/config_next.js | 2 +- 7 files changed, 44 insertions(+), 49 deletions(-) diff --git a/lib/notion/getNotionData.js b/lib/notion/getNotionData.js index 1c0c845b..68c10f7e 100644 --- a/lib/notion/getNotionData.js +++ b/lib/notion/getNotionData.js @@ -30,7 +30,7 @@ import { getAllTags } from './getAllTags' } * */ -export async function getGlobalNotionData ({ +export async function getGlobalNotionData({ pageId = BLOG.NOTION_PAGE_ID, from, latestPostCount = 5, @@ -52,25 +52,21 @@ export async function getGlobalNotionData ({ } /** - * 获取最新文章 + * 获取最新文章 根据最后修改时间倒序排列 * @param {*}} param0 * @returns */ -async function getLatestPosts ({ notionPageData, from, latestPostCount }) { +async function getLatestPosts({ notionPageData, from, latestPostCount }) { const allPosts = await getAllPosts({ notionPageData, from, pageType: ['Post'] }) - let latestPosts = Object.create(allPosts) - // 时间排序 - latestPosts.sort((a, b) => { - // const dateA = new Date(a?.lastEditedTime || a.createdTime) - // const dateB = new Date(b?.lastEditedTime || b.createdTime) - const dateA = new Date(a.date?.start_date) - const dateB = new Date(b.date?.start_date) + const latestPosts = Object.create(allPosts).sort((a, b) => { + const dateA = new Date(a?.lastEditedTime || a?.createdTime || a?.date?.start_date) + const dateB = new Date(b?.lastEditedTime || b?.createdTime || b?.date?.start_date) + // const dateA = new Date(a.date?.start_date) + // const dateB = new Date(b.date?.start_date) return dateB - dateA }) - // 只取前五 - latestPosts = latestPosts.slice(0, latestPostCount) - return latestPosts + return latestPosts.slice(0, latestPostCount) } /** @@ -79,7 +75,7 @@ async function getLatestPosts ({ notionPageData, from, latestPostCount }) { * @param from 请求来源 * @returns {Promise} */ -export async function getNotionPageData ({ pageId, from }) { +export async function getNotionPageData({ pageId, from }) { // 尝试从缓存获取 const cacheKey = 'page_block_' + pageId const data = await getDataFromCache(cacheKey) @@ -100,7 +96,7 @@ export async function getNotionPageData ({ pageId, from }) { * @param notionPageData * @returns {Promise<[]|*[]>} */ -async function getCustomNav ({ notionPageData }) { +async function getCustomNav({ notionPageData }) { if (!notionPageData) { notionPageData = await getNotionPageData({ from: 'custom-nav' }) } @@ -126,7 +122,7 @@ async function getCustomNav ({ notionPageData }) { * @param schema * @returns {undefined} */ -function getTagOptions (schema) { +function getTagOptions(schema) { if (!schema) return {} const tagSchema = Object.values(schema).find(e => e.name === 'tags') return tagSchema?.options || [] @@ -137,7 +133,7 @@ function getTagOptions (schema) { * @param schema * @returns {{}|*|*[]} */ -function getCategoryOptions (schema) { +function getCategoryOptions(schema) { if (!schema) return {} const categorySchema = Object.values(schema).find(e => e.name === 'category') return categorySchema?.options || [] @@ -149,7 +145,7 @@ function getCategoryOptions (schema) { * @param from * @returns {Promise<{title,description,pageCover}>} */ -async function getBlogInfo ({ notionPageData, from }) { +async function getBlogInfo({ notionPageData, from }) { if (!notionPageData) { notionPageData = await getNotionPageData({ from }) } @@ -182,7 +178,7 @@ const mapCoverUrl = (pageCover, block) => { * 调用NotionAPI获取Page数据 * @returns {Promise} */ -async function getPageRecordMapByNotionAPI ({ pageId, from }) { +async function getPageRecordMapByNotionAPI({ pageId, from }) { const pageRecordMap = await getPostBlocks(pageId, from) if (!pageRecordMap) { return [] diff --git a/themes/hexo/LayoutBase.js b/themes/hexo/LayoutBase.js index 98e13827..7b12a3f4 100644 --- a/themes/hexo/LayoutBase.js +++ b/themes/hexo/LayoutBase.js @@ -22,7 +22,7 @@ const LayoutBase = (props) => { const { children, headerSlot, floatSlot, meta, siteInfo } = props const [show, switchShow] = useState(false) // const [percent, changePercent] = useState(0) // 页面阅读百分比 - const rightAreaSlot = + const rightAreaSlot = const { onLoading } = useGlobal() const scrollListener = () => { @@ -48,7 +48,7 @@ const LayoutBase = (props) => { return (
- + {headerSlot} @@ -56,24 +56,24 @@ const LayoutBase = (props) => {
- {onLoading ? : children} + {onLoading ? : children}
- +
- {/* 右下角悬浮 */} -
-
- - {floatSlot} - -
+ {/* 右下角悬浮 */} +
+
+ + {floatSlot} +
+
-
+
) } diff --git a/themes/hexo/components/LatestPostsGroup.js b/themes/hexo/components/LatestPostsGroup.js index 6b82afd5..ac97f855 100644 --- a/themes/hexo/components/LatestPostsGroup.js +++ b/themes/hexo/components/LatestPostsGroup.js @@ -9,14 +9,13 @@ import { useRouter } from 'next/router' * @param sliceCount 截取展示的数量 默认6 * @constructor */ -const LatestPostsGroup = ({ posts, siteInfo }) => { - if (!posts) { +const LatestPostsGroup = ({ latestPosts, siteInfo }) => { + if (!latestPosts) { return <> } // 获取当前路径 const currentPath = useRouter().asPath const { locale } = useGlobal() - return ( <>
@@ -25,7 +24,7 @@ const LatestPostsGroup = ({ posts, siteInfo }) => { {locale.COMMON.LATEST_POSTS}
- {posts.map(post => { + {latestPosts.map(post => { const selected = currentPath === `${BLOG.SUB_PATH}/article/${post.slug}` const headerImage = post?.page_cover ? `url("${post.page_cover}")` @@ -52,7 +51,7 @@ const LatestPostsGroup = ({ posts, siteInfo }) => { >
{post.title}
-
{post.date?.start_date}
+
{post.lastEditedTime}
diff --git a/themes/hexo/components/SideRight.js b/themes/hexo/components/SideRight.js index f8283e4d..7d690632 100644 --- a/themes/hexo/components/SideRight.js +++ b/themes/hexo/components/SideRight.js @@ -6,7 +6,7 @@ import Catalog from './Catalog' import { InfoCard } from './InfoCard' import { AnalyticsCard } from './AnalyticsCard' import CONFIG_HEXO from '../config_hexo' -export default function SideRight (props) { +export default function SideRight(props) { const { post, currentCategory, categories, latestPosts, tags, currentTag, showCategory, showTag, slot @@ -14,13 +14,13 @@ export default function SideRight (props) { return (
- - { CONFIG_HEXO.WIDGET_ANALYTICS && } + + {CONFIG_HEXO.WIDGET_ANALYTICS && } {showCategory && (
- 分类 + 分类
)} {CONFIG_HEXO.WIDGET_LATEST_POSTS && latestPosts && latestPosts.length > 0 && - + }
- {post && post.toc && + {post && post.toc && } {slot} diff --git a/themes/next/LayoutIndex.js b/themes/next/LayoutIndex.js index 12d77aa0..970cb18a 100644 --- a/themes/next/LayoutIndex.js +++ b/themes/next/LayoutIndex.js @@ -8,7 +8,7 @@ import CONFIG_NEXT from './config_next' export const LayoutIndex = (props) => { const { latestPosts } = props - const rightAreaSlot = CONFIG_NEXT.RIGHT_LATEST_POSTS && + const rightAreaSlot = CONFIG_NEXT.RIGHT_LATEST_POSTS && return } sideBarSlot={} @@ -18,6 +18,6 @@ export const LayoutIndex = (props) => { {CONFIG_NEXT.POST_LIST_TYPE !== 'page' ? : - } + } } diff --git a/themes/next/components/LatestPostsGroup.js b/themes/next/components/LatestPostsGroup.js index 54374834..b4627117 100644 --- a/themes/next/components/LatestPostsGroup.js +++ b/themes/next/components/LatestPostsGroup.js @@ -9,8 +9,8 @@ import { useRouter } from 'next/router' * @param sliceCount 截取展示的数量 默认6 * @constructor */ -const LatestPostsGroup = ({ posts }) => { - if (!posts) { +const LatestPostsGroup = ({ latestPosts }) => { + if (!latestPosts) { return <> } // 获取当前路径 @@ -21,11 +21,11 @@ const LatestPostsGroup = ({ posts }) => { <>
- + {locale.COMMON.LATEST_POSTS}
- {posts.map(post => { + {latestPosts.map(post => { const selected = currentPath === `${BLOG.SUB_PATH}/article/${post.slug}` return (