Merge branch 'theme-Next' of https://github.com/tangly1024/NotionNext into theme-Next

This commit is contained in:
tangly1024
2022-01-08 22:26:58 +08:00
68 changed files with 966 additions and 613 deletions

View File

@@ -45,7 +45,7 @@ bszCaller = {
try {
e(t), scriptTag && scriptTag.parentElement && scriptTag.parentElement.removeChild && scriptTag.parentElement.removeChild(scriptTag)
} catch (t) {
console.log(t), bszTag.hides()
// console.log(t), bszTag.hides()
}
})
}

View File

@@ -1,7 +1,7 @@
import cache from 'memory-cache'
import BLOG from 'blog.config'
const cacheTime = BLOG.isProd ? 60 : 60 * 60
const cacheTime = BLOG.isProd ? 10 * 60 : 120 * 60 // 120 minutes for dev,10 minutes for prod
export async function getCacheFromMemory (key, options) {
return cache.get(key)

View File

@@ -26,7 +26,9 @@ export default {
POSTS: 'Posts',
VISITORS: 'Visitors',
VIEWS: 'Views',
COPYRIGHT_NOTICE: 'All articles in this blog, except for special statements, adopt BY-NC-SA agreement. Please indicate the source!'
COPYRIGHT_NOTICE: 'All articles in this blog, except for special statements, adopt BY-NC-SA agreement. Please indicate the source!',
RESULT_OF_SEARCH: 'Results Found',
ARTICLE_DETAIL: 'Article Details'
},
PAGINATION: {
PREV: 'Prev',

View File

@@ -21,14 +21,16 @@ export default {
URL_COPIED: '链接已复制!',
TABLE_OF_CONTENTS: '目录',
RELATE_POSTS: '相关文章',
COPYRIGHT: '版权声明',
COPYRIGHT: '声明',
AUTHOR: '作者',
URL: '链接',
ANALYTICS: '统计',
POSTS: '篇文章',
VISITORS: '位访客',
VIEWS: '次查看',
COPYRIGHT_NOTICE: '本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议转载请注明出处'
COPYRIGHT_NOTICE: '本文采用 CC BY-NC-SA 4.0 许可协议转载请注明出处。',
RESULT_OF_SEARCH: '篇搜索到的结果',
ARTICLE_DETAIL: '文章详情'
},
PAGINATION: {
PREV: '上一页',

View File

@@ -29,6 +29,7 @@ export async function getAllPosts ({ notionPageData, from, includePage = false }
for (let i = 0; i < pageIds.length; i++) {
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.fullWidth = pageBlock[id].value?.format?.page_full_width ?? false

View File

@@ -1,7 +1,52 @@
import BLOG from '@/blog.config'
import { idToUuid } from 'notion-utils'
import { getDataFromCache, setDataToCache } from '@/lib/cache/cache_manager'
import { getPostBlocks } from '@/lib/notion/getPostBlocks'
import { idToUuid } from 'notion-utils'
import { getAllCategories } from './getAllCategories'
import { getAllPosts } from './getAllPosts'
import { getAllTags } from './getAllTags'
/**
* 获取博客数据
* @param {*} pageId
* @param {*} from
* @returns
* allPosts 所有博客
* categories 所有分类
* tags 所有标签
*/
export async function getGlobalNotionData ({
pageId = BLOG.notionPageId,
from,
latestPostCount = 5,
tagsCount = 16,
includePage
}) {
const notionPageData = await getNotionPageData({ pageId, from })
const tagOptions = notionPageData.tagOptions
const allPosts = await getAllPosts({ notionPageData, from, includePage })
const postCount = allPosts?.length
const categories = await getAllCategories(allPosts)
const tags = await getAllTags({ allPosts, tagOptions, sliceCount: tagsCount })
// 深拷贝
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)
return dateB - dateA
})
// 只取前五
latestPosts = latestPosts.slice(0, latestPostCount)
return {
allPosts,
latestPosts,
categories,
postCount,
tags
}
}
/**
* 获取指定notion的collection数据
@@ -9,7 +54,7 @@ import { getPostBlocks } from '@/lib/notion/getPostBlocks'
* @param from 请求来源
* @returns {Promise<JSX.Element|*|*[]>}
*/
export async function getNotionPageData ({ pageId = BLOG.notionPageId, from }) {
export async function getNotionPageData ({ pageId, from }) {
// 尝试从缓存获取
const cacheKey = 'page_record_map_' + pageId
const data = await getDataFromCache(cacheKey)
@@ -54,7 +99,10 @@ async function getPageRecordMapByNotionAPI ({ pageId, from }) {
const tagOptions = getTagOptions(schema)
// Check Type Page-Database和Inline-Database
if (rawMetadata?.type !== 'collection_view_page' && rawMetadata?.type !== 'collection_view') {
if (
rawMetadata?.type !== 'collection_view_page' &&
rawMetadata?.type !== 'collection_view'
) {
console.warn(`pageId "${pageId}" is not a database`)
return null
}

View File

@@ -20,6 +20,22 @@ export async function getPostBlocks (id, from) {
return null
}
// 去掉不用的字段
for (const j in pageBlock?.block) {
const b = pageBlock?.block[j]
if (b) {
delete b.role
delete b.value?.version
delete b.value?.created_time
delete b.value?.last_edited_time
delete b.value?.created_by_table
delete b.value?.created_by_id
delete b.value?.last_edited_by_table
delete b.value?.last_edited_by_id
delete b.value?.space_id
}
}
if (pageBlock) {
await setDataToCache(cacheKey, pageBlock)
}

View File

@@ -20,8 +20,8 @@ export function generateRss (posts) {
posts.forEach(post => {
feed.addItem({
title: post.title,
id: `${BLOG.link}/${post.slug}`,
link: `${BLOG.link}/${post.slug}`,
id: `${BLOG.link}/article/${post.slug}`,
link: `${BLOG.link}/article/${post.slug}`,
description: post.summary,
date: new Date(post?.date?.start_date || post.createdTime)
})