Skip to content

Commit 4266e01

Browse files
committed
Merge branch 'main' into dev
2 parents 11cc562 + 7af03cc commit 4266e01

File tree

3 files changed

+10
-3
lines changed

3 files changed

+10
-3
lines changed

components/Docs/NavGroup.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { PageFrontMatter } from '../../models';
44
import { Link } from '../Link/Link';
55
import { ParentLink } from '../Link/ParentLink';
66
import { useRouter } from 'next/router';
7+
import { getHeadingLink } from '../../utils/getHeadingLink';
78

89
export interface INavGroupProps {
910
items: PageFrontMatter[];
@@ -33,7 +34,7 @@ export const NavGroup: React.FunctionComponent<INavGroupProps> = ({
3334
<li key={index}>
3435
<Link
3536
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)}`}
3738
/>
3839
</li>
3940
);

utils/getHeadingLink.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
export const getHeadingLink = (value: string) => {
2+
return value
3+
.toLowerCase()
4+
.replace(/\s/g, "-")
5+
.replace(/[^a-zA-Z0-9.-]/g, "");
6+
};

utils/markdownToHtml.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { visit } from "unist-util-visit";
88
import * as shiki from "shiki";
99
import fs from "fs";
1010
import path from "path";
11+
import { getHeadingLink } from "./getHeadingLink";
1112

1213
class ShikiFm {
1314
public static highlighter: shiki.Highlighter | undefined = undefined;
@@ -110,8 +111,7 @@ const remarkFm = ({
110111
let lastChild = node.children[node.children.length - 1];
111112
if (lastChild && lastChild.type === "text") {
112113
let string = lastChild.value.replace(/ +$/, "");
113-
let hId = string.toLowerCase().replace(/\s/g, "-");
114-
hId = hId.replace(/[^a-zA-Z0-9.]/g, "");
114+
let hId = getHeadingLink(string);
115115

116116
if (!node.data) {
117117
node.data = {};

0 commit comments

Comments
 (0)