NEXT主题-fontawesome改成引用CDN

This commit is contained in:
tangly1024
2022-02-26 21:23:59 +08:00
parent bebde04f15
commit 20cb91c577
42 changed files with 215 additions and 274 deletions

View File

@@ -9,10 +9,10 @@ import { delCacheData } from '@/lib/cache/cache_manager'
* 获取所有文章列表
* @param notionPageData
* @param from
* @param includePage 是否包含Page类型
* @param pageType 页面类型数组 ['Post','Page']
* @returns {Promise<*[]>}
*/
export async function getAllPosts ({ notionPageData, from, includePage = false }) {
export async function getAllPosts ({ notionPageData, from, pageType }) {
if (!notionPageData) {
notionPageData = await getNotionPageData({ from })
}
@@ -31,11 +31,12 @@ export async function getAllPosts ({ notionPageData, from, includePage = false }
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()
properties.lastEditedTime = new Date(pageBlock[id].value?.last_edited_time).toString()
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.fullWidth = pageBlock[id].value?.format?.page_full_width ?? false
properties.page_cover = getPostCover(id, pageBlock) ?? null
properties.content = pageBlock[id].value?.content ?? []
properties.icon = pageBlock[id].value?.icon ?? null
properties.tagItems = properties?.tags?.map(tag => {
return { name: tag, color: tagOptions.find(t => t.value === tag)?.color || 'gray' }
}) || []
@@ -45,19 +46,7 @@ export async function getAllPosts ({ notionPageData, from, includePage = false }
// remove all the the items doesn't meet requirements
const posts = data.filter(post => {
if (includePage) {
return (
post.title && post.slug &&
post?.status?.[0] === 'Published' &&
(post?.type?.[0] === 'Post' || post?.type?.[0] === 'Page')
)
} else {
return (
post.title && post.slug &&
post?.status?.[0] === 'Published' &&
(post?.type?.[0] === 'Post')
)
}
return post.title && post?.status?.[0] === 'Published' && pageType.indexOf(post?.type?.[0]) > -1
})
if (!posts || posts.length === 0) {
@@ -65,6 +54,7 @@ export async function getAllPosts ({ notionPageData, from, includePage = false }
const cacheKey = 'page_block_' + BLOG.NOTION_PAGE_ID
await delCacheData(cacheKey)
}
// Sort by date
if (BLOG.POSTS_SORT_BY === 'date') {
posts.sort((a, b) => {

View File

@@ -12,27 +12,30 @@ import { getAllTags } from './getAllTags'
* @param {*} from
* @param latestPostCount 截取最新文章数量
* @param tagsCount 截取标签数量
* @param includePage 是否包含PAGE类型
* @returns {}
* allPosts 所有博客
* categories 所有分类
* tags 所有标签
* @param pageType 过滤的文章类型,数组格式 ['Page','Post']
* @returns {
allPosts, 所有博客
latestPosts,
categories, 所有分类
postCount,
customNav, 自定义导航菜单
tags 所有标签
}
*
*/
export async function getGlobalNotionData ({
pageId = BLOG.NOTION_PAGE_ID,
from,
latestPostCount = 5,
tagsCount = 16,
includePage
pageType = ['Post']
}) {
const notionPageData = await getNotionPageData({ pageId, from })
const tagOptions = notionPageData.tagOptions
const allPosts = await getAllPosts({ notionPageData, from, includePage })
const postCount = allPosts?.filter(post =>
post.title && post.slug &&
post?.status?.[0] === 'Published' &&
(post?.type?.[0] === 'Post')
const allPosts = await getAllPosts({ notionPageData, from, pageType })
const postCount = allPosts?.filter(post => post?.status?.[0] === 'Published' && (post?.type?.[0] === 'Post')
)?.length
const customNav = await getCustomNav({ notionPageData })
const categories = await getAllCategories(allPosts)
const tags = await getAllTags({ allPosts, tagOptions, sliceCount: tagsCount })
// 深拷贝
@@ -51,6 +54,7 @@ export async function getGlobalNotionData ({
latestPosts,
categories,
postCount,
customNav,
tags
}
}
@@ -77,6 +81,18 @@ export async function getNotionPageData ({ pageId, from }) {
return pageRecordMap
}
async function getCustomNav ({ notionPageData }) {
if (!notionPageData) {
notionPageData = await getNotionPageData({ from: 'custom-nav' })
}
if (!notionPageData) {
return []
}
const allPage = await getAllPosts({ notionPageData, from: 'custom-nav', pageType: ['Page'] })
console.log(allPage)
return [{ icon: 'fas fa-file-alt', name: '简历', to: '/' + 'resume', show: true }]
}
/**
* 获取标签选项
* @param schema