added i and lvl to toc element

This commit is contained in:
Kim, Jimin 2021-08-17 11:11:58 +09:00
parent 74b523be23
commit ace4fc82a9
2 changed files with 5 additions and 3 deletions

View file

@ -104,11 +104,11 @@ const StyledMetaContainer = styled.div`
})}; })};
` `
function parseToc(json: TocElement[]) { function parseToc(tocData: TocElement[]) {
return ( return (
<ol> <ol>
{json.map((elem) => ( {tocData.map((elem) => (
// elem: content, i, lvl // use elem.lvl
<li key={elem.slug}> <li key={elem.slug}>
<HashLink smooth to={location.pathname + "#" + elem.slug}> <HashLink smooth to={location.pathname + "#" + elem.slug}>
{elem.content} {elem.content}

View file

@ -1,6 +1,8 @@
export interface TocElement { export interface TocElement {
slug: string slug: string
content: string content: string
i: number
lvl: number
} }
export interface Post { export interface Post {