forked from tangly1024/NotionNext
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'tangly1024:main' into main
- Loading branch information
Showing
20 changed files
with
131 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
# 环境变量 @see https://www.nextjs.cn/docs/basic-features/environment-variables | ||
NEXT_PUBLIC_VERSION=3.6.5 | ||
NEXT_PUBLIC_VERSION=3.6.6 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
import { getTextContent } from 'notion-utils' | ||
|
||
const indentLevels = { | ||
header: 0, | ||
sub_header: 1, | ||
sub_sub_header: 2 | ||
} | ||
|
||
/** | ||
* @see https://github.com/NotionX/react-notion-x/blob/master/packages/notion-utils/src/get-page-table-of-contents.ts | ||
* Gets the metadata for a table of contents block by parsing the page's | ||
* H1, H2, and H3 elements. | ||
*/ | ||
export const getPageTableOfContents = (page, recordMap) => { | ||
const contents = (page.content ?? []) | ||
const toc = getBlockHeader(contents, recordMap) | ||
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() | ||
} | ||
|
||
// eslint-disable-next-line no-constant-condition | ||
} while (true) | ||
} | ||
|
||
return toc | ||
} | ||
|
||
/** | ||
* 重写获取目录方法 | ||
*/ | ||
function getBlockHeader(contents, recordMap, toc) { | ||
if (!toc) { | ||
toc = [] | ||
} | ||
if (!contents) { | ||
return toc | ||
} | ||
|
||
for (const blockId of contents) { | ||
const block = recordMap.block[blockId]?.value | ||
if (!block) { | ||
continue | ||
} | ||
const { type } = block | ||
if (type.indexOf('header') >= 0) { | ||
const existed = toc.find(e => e.id === blockId) | ||
if (!existed) { | ||
toc.push({ | ||
id: blockId, | ||
type, | ||
text: getTextContent(block.properties?.title), | ||
indentLevel: indentLevels[type] | ||
}) | ||
} | ||
} | ||
|
||
if (block.content?.length > 0) { | ||
getBlockHeader(block.content, recordMap, toc) | ||
} | ||
} | ||
|
||
return toc | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,13 @@ | ||
import { getPageTableOfContents } from 'notion-utils' | ||
import ArticleDetail from './components/ArticleDetail' | ||
import LayoutBase from './LayoutBase' | ||
import { ArticleLock } from './components/ArticleLock' | ||
|
||
export const LayoutSlug = (props) => { | ||
const { post, lock, validPassword } = props | ||
if (!lock && post?.blockMap?.block) { | ||
post.content = Object.keys(post.blockMap.block) | ||
post.toc = getPageTableOfContents(post, post.blockMap) | ||
} | ||
|
||
const { lock, validPassword } = props | ||
return ( | ||
<LayoutBase {...props} > | ||
{!lock && <ArticleDetail {...props} />} | ||
{lock && <ArticleLock password={post.password} validPassword={validPassword} />} | ||
{lock && <ArticleLock validPassword={validPassword} />} | ||
</LayoutBase> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
c7e9fbd
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
notion-next – ./
notion-next-nine-topaz.vercel.app
notion-next-git-main-expoli.vercel.app
www.expoli.tech
notion-next-expoli.vercel.app
expoli.tech