mirror of
https://github.com/d0zingcat/NotionNext.git
synced 2026-05-19 15:09:36 +00:00
最新文章组件,按修改时间倒序
This commit is contained in:
@@ -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<JSX.Element|*|*[]>}
|
||||
*/
|
||||
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<JSX.Element|null|*>}
|
||||
*/
|
||||
async function getPageRecordMapByNotionAPI ({ pageId, from }) {
|
||||
async function getPageRecordMapByNotionAPI({ pageId, from }) {
|
||||
const pageRecordMap = await getPostBlocks(pageId, from)
|
||||
if (!pageRecordMap) {
|
||||
return []
|
||||
|
||||
Reference in New Issue
Block a user