Skip to content

Commit 3000378

Browse files
committed
Fix #undefined named anchors for question permalinks. Resolve #304
Also removed comment from the default config which made it invalid JSON. (The same explanation is already included in README)
1 parent d55f757 commit 3000378

File tree

2 files changed

+3
-11
lines changed

2 files changed

+3
-11
lines changed

config/default.json

-10
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,4 @@
11
{
22
"indexConfig": {
3-
// this config is used during the build to configure Zotero Bib
4-
// component both during development and in production. Values
5-
// listed below can be overriden in local.json and/or using
6-
// env variables. See https://www.npmjs.com/package/config
7-
//
8-
// "apiAuthorityPart": undefined,
9-
// "storeURL": undefined,
10-
// "stylesURL": undefined,
11-
// "translatePrefix": "",
12-
// "translateURL": undefined
133
}
144
}

scripts/build-html.cjs

+3-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@ const addAnchors = html => {
1313
const $ = cheerio.load(html);
1414
const headers = $('h2, h3');
1515
headers.map((_, element) => {
16-
const id = element.attribs.id;
16+
const id = element.attribs.id ?? $(element).text().replace(/[^\w\s]/g, '').trim().replace(/\s/g, '_').toLocaleLowerCase();
17+
element.attribs.id = id;
18+
1719
$('<a>')
1820
.attr('href', '#' + id)
1921
.addClass('anchor-link')

0 commit comments

Comments
 (0)