Skip to content

Commit cfd76df

Browse files
committed
fix(cn): fix heading id
1 parent d872c7b commit cfd76df

File tree

5 files changed

+132
-124
lines changed

5 files changed

+132
-124
lines changed

src/components/Site/Site.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ function Site(props) {
269269
),
270270
},
271271
{ content: '参与贡献', url: '/contribute/' },
272-
{ content: '投票', url: '/vote/' },
272+
{ content: '投票', url: 'https://webpack.js.org/vote/' },
273273
{ content: '博客', url: '/blog/' },
274274
{ content: '印记中文', url: 'https://docschina.org' },
275275
]}

src/remark-plugins/docschina-remark-slugger/index.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use strict';
22

3-
import toString from 'mdast-util-to-string';
3+
import { toString } from 'mdast-util-to-string';
44
import { visit } from 'unist-util-visit';
55
import slugs from 'github-slugger';
66

src/remark-plugins/remark-slug/index.mjs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,15 @@ export default function remarkSlug() {
2727
);
2828
let id = props.id;
2929

30-
id = id ? slugs.slug(String(id), true) : slugs.slug(toString(node));
30+
const rawHeader = id ? id : toString(node);
31+
const match = /^.+(\s*\$#([a-z0-9\-_]+?)\$\s*)$/.exec(rawHeader);
32+
id = match ? match[2] : slugs.slug(rawHeader, true);
33+
34+
if (match) {
35+
// Remove the custom ID part from the text node.
36+
const lastNode = node.children[node.children.length - 1];
37+
lastNode.value = lastNode.value.replace(match[1], '');
38+
}
3139

3240
data.id = id;
3341
props.id = id;

webpack.common.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import webpack from 'webpack';
44
import h from 'hastscript';
55
import remarkResponsiveTable from './src/remark-plugins/remark-responsive-table/remark-responsive-table.mjs';
66
import gfm from 'remark-gfm';
7-
import slug from './src/remark-plugins/docschina-remark-slugger/index.mjs';
7+
import slug from './src/remark-plugins/remark-slug/index.mjs';
88
import cleanup from './src/remark-plugins/remark-cleanup-readme/index.mjs';
99
import aside from './src/remark-plugins/remark-custom-asides/index.mjs';
1010
import autolink from 'remark-autolink-headings';

0 commit comments

Comments
 (0)