gitbook 主题fix最近阅读

This commit is contained in:
tangly1024.com
2024-05-16 15:29:02 +08:00
parent 71701fa314
commit 59025e8018
6 changed files with 33 additions and 32 deletions

View File

@@ -5,14 +5,14 @@ import getAllPageIds from '@/lib/notion/getAllPageIds'
import { getAllTags } from '@/lib/notion/getAllTags'
import { getConfigMapFromConfigPage } from '@/lib/notion/getNotionConfig'
import getPageProperties, {
adjustPageProperties
adjustPageProperties
} from '@/lib/notion/getPageProperties'
import { fetchInBatches, getPage } from '@/lib/notion/getPostBlocks'
import { compressImage, mapImgUrl } from '@/lib/notion/mapImage'
import { deepClone } from '@/lib/utils'
import { idToUuid } from 'notion-utils'
import { siteConfig } from '../config'
import { extractLangId, extractLangPrefix } from '../utils/pageId'
import { extractLangId, extractLangPrefix, getShortId } from '../utils/pageId'
export { getAllTags } from '../notion/getAllTags'
export { getPost } from '../notion/getNotionPost'
@@ -100,16 +100,14 @@ function compressData(db) {
// 清理多余的块
if (db?.notice) {
db.notice = cleanBlock(db?.notice)
}
if (db?.post) {
db.post = cleanBlock(db?.post)
delete db.notice?.id
}
db.tagOptions = cleanIds(db?.tagOptions)
db.categoryOptions = cleanIds(db?.categoryOptions)
db.customMenu = cleanIds(db?.customMenu)
db.latestPosts = cleanIds(db?.latestPosts)
db.latestPosts = shortenIds(db?.latestPosts)
db.allNavPages = shortenIds(db?.allNavPages)
// db.allPages = cleanBlocks(db?.allPages)
@@ -125,7 +123,7 @@ function shortenIds(items) {
if (items && Array.isArray(items)) {
return deepClone(
items.map(item => {
item.short_id = getFirstPart(item.id)
item.short_id = getShortId(item.id)
delete item.id
return item
})
@@ -134,16 +132,6 @@ function shortenIds(items) {
return items
}
function getFirstPart(uuid) {
if (!uuid || uuid.indexOf('-') < 0) {
return uuid
}
// 找到第一个 '-' 的位置
const index = uuid.indexOf('-')
// 截取从开始到第一个 '-' 之前的部分
return uuid.substring(0, index)
}
/**
* 清理一组数据的id
* @param {*} items
@@ -167,7 +155,7 @@ function cleanIds(items) {
function cleanBlock(item) {
const post = deepClone(item)
const pageBlock = post?.blockMap?.block
delete post?.id
// delete post?.id
// delete post?.blockMap?.collection
if (pageBlock) {

View File

@@ -30,4 +30,18 @@ function extractLangId(str) {
}
}
module.exports = { extractLangPrefix, extractLangId }
/**
* 列表中用过来区分page只需要端的id足够
*/
function getShortId(uuid) {
if (!uuid || uuid.indexOf('-') < 0) {
return uuid
}
// 找到第一个 '-' 的位置
const index = uuid.indexOf('-')
// 截取从开始到第一个 '-' 之前的部分
return uuid.substring(0, index)
}
module.exports = { extractLangPrefix, extractLangId, getShortId }