mirror of
https://github.com/d0zingcat/NotionNext.git
synced 2026-05-14 07:26:52 +00:00
feature: 调整Hexo 页面
This commit is contained in:
@@ -18,7 +18,7 @@ export default {
|
||||
SHARE: 'Share',
|
||||
SCAN_QR_CODE: 'Scan QRCode',
|
||||
URL_COPIED: 'URL has copied!',
|
||||
TABLE_OF_CONTENTS: 'Table of Contents',
|
||||
TABLE_OF_CONTENTS: 'Catalog',
|
||||
RELATE_POSTS: 'Relate Posts',
|
||||
COPYRIGHT: 'Copyright',
|
||||
AUTHOR: 'Author',
|
||||
|
||||
@@ -25,9 +25,6 @@ export async function getAllPosts ({ notionPageData, from, includePage = false }
|
||||
const collectionQuery = notionPageData.collectionQuery
|
||||
|
||||
const data = []
|
||||
if (!collectionQuery || collectionQuery.toString === '{}') {
|
||||
console.warn('列表查询条件为空', notionPageData)
|
||||
}
|
||||
const pageIds = getAllPageIds(collectionQuery)
|
||||
if (!pageIds || pageIds.length === 0) {
|
||||
console.warn('页面ID列表为空')
|
||||
|
||||
@@ -1,68 +0,0 @@
|
||||
|
||||
const indentLevels = {
|
||||
header: 0,
|
||||
sub_header: 1,
|
||||
sub_sub_header: 2
|
||||
}
|
||||
|
||||
export const getPageTableOfContents = (page, recordMap) => {
|
||||
// 获取 header sub_header sub_sub_header
|
||||
const toc = (page.content ?? [])
|
||||
.map((blockId) => {
|
||||
const block = recordMap.block[blockId]?.value
|
||||
|
||||
if (block) {
|
||||
const { type } = block
|
||||
|
||||
if (
|
||||
type === 'header' ||
|
||||
type === 'sub_header' ||
|
||||
type === 'sub_sub_header'
|
||||
) {
|
||||
return {
|
||||
id: blockId,
|
||||
type,
|
||||
indentLevel: indentLevels[type]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return null
|
||||
})
|
||||
.filter(Boolean)
|
||||
|
||||
const indentLevelStack = [
|
||||
{
|
||||
actual: -1,
|
||||
effective: -1
|
||||
}
|
||||
]
|
||||
|
||||
// Adjust indent levels to always change smoothly.
|
||||
// This is a little tricky, but the key is that when increasing indent levels,
|
||||
// they should never jump more than one at a time.
|
||||
for (const tocItem of toc) {
|
||||
const { indentLevel } = tocItem
|
||||
const actual = indentLevel
|
||||
|
||||
do {
|
||||
const prevIndent = indentLevelStack[indentLevelStack.length - 1]
|
||||
const { actual: prevActual, effective: prevEffective } = prevIndent
|
||||
|
||||
if (actual > prevActual) {
|
||||
tocItem.indentLevel = prevEffective + 1
|
||||
indentLevelStack.push({
|
||||
actual,
|
||||
effective: tocItem.indentLevel
|
||||
})
|
||||
} else if (actual === prevActual) {
|
||||
tocItem.indentLevel = prevEffective
|
||||
break
|
||||
} else {
|
||||
indentLevelStack.pop()
|
||||
}
|
||||
} while (true)
|
||||
}
|
||||
|
||||
return toc
|
||||
}
|
||||
Reference in New Issue
Block a user