mirror of
https://github.com/d0zingcat/NotionNext.git
synced 2026-05-14 07:26:52 +00:00
feature:
适配无标签文章
This commit is contained in:
@@ -2,8 +2,13 @@ import { faTag } from '@fortawesome/free-solid-svg-icons'
|
||||
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'
|
||||
import Link from 'next/link'
|
||||
import React from 'react'
|
||||
import { useGlobal } from '@/lib/global'
|
||||
|
||||
const TagItem = ({ tag, selected }) => {
|
||||
const { locale } = useGlobal()
|
||||
if (!tag) {
|
||||
<>{locale.COMMON.NOTAG}</>
|
||||
}
|
||||
return (
|
||||
<Link href={selected ? '/' : `/tag/${encodeURIComponent(tag.name)}`} passHref>
|
||||
<li
|
||||
|
||||
2
lib/cache/cache_manager.js
vendored
2
lib/cache/cache_manager.js
vendored
@@ -2,7 +2,7 @@ import { getCacheFromFile, setCacheToFile } from '@/lib/cache/local_file_cache'
|
||||
import { getCacheFromMemory, setCacheToMemory } from '@/lib/cache/memory_cache'
|
||||
import BLOG from '@/blog.config'
|
||||
// 关闭本地缓存
|
||||
const enableCache = true
|
||||
const enableCache = false
|
||||
|
||||
/**
|
||||
* 为减少频繁接口请求,notion数据将被缓存
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import BLOG from '@/blog.config'
|
||||
import lang from './lang'
|
||||
import { useContext, createContext, useState, useEffect } from 'react'
|
||||
import cookie from 'react-cookies'
|
||||
|
||||
@@ -11,6 +11,7 @@ export default {
|
||||
MORE: 'More',
|
||||
LATEST_POSTS: 'Latest posts',
|
||||
TAGS: 'Tags',
|
||||
NO_TAG: 'NoTag',
|
||||
CATEGORY: 'Category',
|
||||
SHARE: 'Share',
|
||||
SCAN_QR_CODE: 'Scan QRCode',
|
||||
|
||||
@@ -12,6 +12,7 @@ export default {
|
||||
MORE: '更多',
|
||||
LATEST_POSTS: '最新文章',
|
||||
TAGS: '标签',
|
||||
NO_TAG: 'NoTag',
|
||||
CATEGORY: '分类',
|
||||
SHARE: '分享',
|
||||
SCAN_QR_CODE: '扫一扫二维码',
|
||||
|
||||
@@ -3,8 +3,6 @@ import getAllPageIds from './getAllPageIds'
|
||||
import getPageProperties from './getPageProperties'
|
||||
import { defaultMapImageUrl } from 'react-notion-x'
|
||||
import { getNotionPageData } from '@/lib/notion/getNotionData'
|
||||
import TagItemMini from '@/components/TagItemMini'
|
||||
import React from 'react'
|
||||
|
||||
/**
|
||||
* 获取所有文章列表
|
||||
@@ -26,19 +24,19 @@ export async function getAllPosts ({ notionPageData, from, includePage = false }
|
||||
const tagOptions = notionPageData.tagOptions
|
||||
const collectionQuery = notionPageData.collectionQuery
|
||||
|
||||
// 获取每篇文章信息
|
||||
const data = []
|
||||
const pageIds = getAllPageIds(collectionQuery)
|
||||
for (let i = 0; i < pageIds.length; i++) {
|
||||
const id = pageIds[i]
|
||||
const properties = (await getPageProperties(id, pageBlock, schema)) || null
|
||||
const tagItems = properties?.tags?.map(tag => { return { name: tag, color: tagOptions.find(t => t.value === tag).color } }) || ['默认']
|
||||
properties.createdTime = new Date(pageBlock[id].value?.created_time).toString()
|
||||
properties.lastEditedTime = new Date(pageBlock[id].value?.last_edited_time).toString()
|
||||
properties.fullWidth = pageBlock[id].value?.format?.page_full_width ?? false
|
||||
properties.page_cover = getPostCover(id, pageBlock) ?? BLOG.defaultImgCover
|
||||
properties.content = pageBlock[id].value?.content ?? []
|
||||
properties.tagItems = tagItems
|
||||
properties.tagItems = properties?.tags?.map(tag => {
|
||||
return { name: tag, color: tagOptions.find(t => t.value === tag)?.color || 'gray' }
|
||||
}) || []
|
||||
data.push(properties)
|
||||
}
|
||||
|
||||
|
||||
@@ -26,7 +26,7 @@ export async function getAllTags ({ allPosts, sliceCount = 12, tagOptions }) {
|
||||
|
||||
// 按照标签数量排序
|
||||
const list = Object.keys(tagObj).map((tag) => {
|
||||
const color = tagOptions.find(option => option.value === tag).color
|
||||
const color = tagOptions.find(option => option.value === tag)?.color || 'gray'
|
||||
return { name: tag, count: tagObj[tag], color }
|
||||
})
|
||||
list.sort((a, b) => b.count - a.count)
|
||||
|
||||
Reference in New Issue
Block a user