mirror of
https://github.com/DefectingCat/DefectingCat.github.io
synced 2025-07-15 16:51:37 +00:00
Update length calculate
This commit is contained in:
@ -61,10 +61,12 @@ export const getStaticProps: GetStaticProps<{
|
||||
|
||||
const post = await readSinglePost(slug);
|
||||
const toc = generateToc(post);
|
||||
let tocLength = toc.length;
|
||||
toc.forEach(
|
||||
(item) => item.children.length && (tocLength += item.children.length)
|
||||
);
|
||||
|
||||
const calcLength = (prev: number, cur: SingleToc) => {
|
||||
const childLen = cur.children.length;
|
||||
return childLen ? prev + childLen + 1 : prev + 1;
|
||||
};
|
||||
const tocLength = toc.reduce(calcLength, 0);
|
||||
|
||||
const mdxSource = await serialize(post, {
|
||||
mdxOptions: {
|
||||
@ -87,4 +89,4 @@ export const getStaticProps: GetStaticProps<{
|
||||
};
|
||||
};
|
||||
|
||||
export default Slug;
|
||||
export default Slug;
|
Reference in New Issue
Block a user