File tree Expand file tree Collapse file tree 3 files changed +10
-3
lines changed Expand file tree Collapse file tree 3 files changed +10
-3
lines changed Original file line number Diff line number Diff line change @@ -4,6 +4,7 @@ import { PageFrontMatter } from '../../models';
4
4
import { Link } from '../Link/Link' ;
5
5
import { ParentLink } from '../Link/ParentLink' ;
6
6
import { useRouter } from 'next/router' ;
7
+ import { getHeadingLink } from '../../utils/getHeadingLink' ;
7
8
8
9
export interface INavGroupProps {
9
10
items : PageFrontMatter [ ] ;
@@ -33,7 +34,7 @@ export const NavGroup: React.FunctionComponent<INavGroupProps> = ({
33
34
< li key = { index } >
34
35
< Link
35
36
title = { link }
36
- link = { `/docs/${ item . slug !== "index" ? item . slug : '' } #${ link . toLowerCase ( ) . replace ( / \s / g , '-' ) } ` }
37
+ link = { `/docs/${ item . slug !== "index" ? item . slug : '' } #${ getHeadingLink ( link ) } ` }
37
38
/>
38
39
</ li >
39
40
) ;
Original file line number Diff line number Diff line change
1
+ export const getHeadingLink = ( value : string ) => {
2
+ return value
3
+ . toLowerCase ( )
4
+ . replace ( / \s / g, "-" )
5
+ . replace ( / [ ^ a - z A - Z 0 - 9 . - ] / g, "" ) ;
6
+ } ;
Original file line number Diff line number Diff line change @@ -8,6 +8,7 @@ import { visit } from "unist-util-visit";
8
8
import * as shiki from "shiki" ;
9
9
import fs from "fs" ;
10
10
import path from "path" ;
11
+ import { getHeadingLink } from "./getHeadingLink" ;
11
12
12
13
class ShikiFm {
13
14
public static highlighter : shiki . Highlighter | undefined = undefined ;
@@ -110,8 +111,7 @@ const remarkFm = ({
110
111
let lastChild = node . children [ node . children . length - 1 ] ;
111
112
if ( lastChild && lastChild . type === "text" ) {
112
113
let string = lastChild . value . replace ( / + $ / , "" ) ;
113
- let hId = string . toLowerCase ( ) . replace ( / \s / g, "-" ) ;
114
- hId = hId . replace ( / [ ^ a - z A - Z 0 - 9 . ] / g, "" ) ;
114
+ let hId = getHeadingLink ( string ) ;
115
115
116
116
if ( ! node . data ) {
117
117
node . data = { } ;
You can’t perform that action at this time.
0 commit comments