mirror of
https://github.com/d0zingcat/NotionNext.git
synced 2026-05-14 07:26:52 +00:00
推荐文章,支持时间倒序
This commit is contained in:
@@ -184,7 +184,7 @@ export function getNavPages({ allPages }) {
|
||||
return post && post?.slug && (!post?.slug?.startsWith('http')) && post?.type === 'Post' && post?.status === 'Published'
|
||||
})
|
||||
|
||||
return allNavPages.map(item => ({ id: item.id, title: item.title || '', pageCoverThumbnail: item.pageCoverThumbnail || '', category: item.category || null, tags: item.tags || null, summary: item.summary || null, slug: item.slug }))
|
||||
return allNavPages.map(item => ({ id: item.id, title: item.title || '', pageCoverThumbnail: item.pageCoverThumbnail || '', category: item.category || null, tags: item.tags || null, summary: item.summary || null, slug: item.slug, lastEditedDate: item.lastEditedDate }))
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -160,22 +160,9 @@ function TopGroup(props) {
|
||||
todayCardRef.current.coverUp()
|
||||
}
|
||||
|
||||
let topPosts = []
|
||||
// 默认展示最近更新
|
||||
if (!CONFIG.HERO_RECOMMEND_POST_TAG || CONFIG.HERO_RECOMMEND_POST_TAG === '') {
|
||||
topPosts = latestPosts
|
||||
} else {
|
||||
// 展示特定标签文章
|
||||
for (const post of allNavPages) {
|
||||
if (topPosts.length === 6) {
|
||||
break
|
||||
}
|
||||
// 查找标签
|
||||
if (post?.tags?.indexOf(CONFIG.HERO_RECOMMEND_POST_TAG) >= 0) {
|
||||
topPosts.push(post)
|
||||
}
|
||||
}
|
||||
}
|
||||
// 获取置顶推荐文章
|
||||
const topPosts = getTopPosts({ latestPosts, allNavPages })
|
||||
|
||||
return (
|
||||
<div id='hero-right-wrapper' onMouseLeave={handleMouseLeave} className='flex-1 relative w-full'>
|
||||
{/* 置顶推荐文章 */}
|
||||
@@ -198,6 +185,42 @@ function TopGroup(props) {
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取推荐置顶文章
|
||||
*/
|
||||
function getTopPosts({ latestPosts, allNavPages }) {
|
||||
// 默认展示最近更新
|
||||
if (!CONFIG.HERO_RECOMMEND_POST_TAG || CONFIG.HERO_RECOMMEND_POST_TAG === '') {
|
||||
return latestPosts
|
||||
}
|
||||
|
||||
// 显示包含‘推荐’标签的文章
|
||||
let sortPosts = []
|
||||
|
||||
// 排序方式
|
||||
if (JSON.parse(CONFIG.HERO_RECOMMEND_POST_SORT_BY_UPDATE_TIME)) {
|
||||
sortPosts = Object.create(allNavPages).sort((a, b) => {
|
||||
const dateA = new Date(a?.lastEditedDate)
|
||||
const dateB = new Date(b?.lastEditedDate)
|
||||
return dateB - dateA
|
||||
})
|
||||
} else {
|
||||
sortPosts = Object.create(allNavPages)
|
||||
}
|
||||
|
||||
const topPosts = []
|
||||
for (const post of sortPosts) {
|
||||
if (topPosts.length === 6) {
|
||||
break
|
||||
}
|
||||
// 查找标签
|
||||
if (post?.tags?.indexOf(CONFIG.HERO_RECOMMEND_POST_TAG) >= 0) {
|
||||
topPosts.push(post)
|
||||
}
|
||||
}
|
||||
return topPosts
|
||||
}
|
||||
|
||||
/**
|
||||
* 英雄区右侧,今日卡牌
|
||||
* @returns
|
||||
|
||||
@@ -24,6 +24,7 @@ const CONFIG = {
|
||||
|
||||
// 英雄区右侧推荐文章标签, 例如 [推荐] , 最多六篇文章; 若留空白'',则推荐最近更新文章
|
||||
HERO_RECOMMEND_POST_TAG: '推荐',
|
||||
HERO_RECOMMEND_POST_SORT_BY_UPDATE_TIME: false, // 推荐文章排序,为`true`时将强制按最后修改时间倒序
|
||||
|
||||
// 右侧个人资料卡牌欢迎语,点击可自动切换
|
||||
INFOCARD_GREETINGS: [
|
||||
|
||||
Reference in New Issue
Block a user