Skip to content

Commit

Permalink
Fix #undefined named anchors for question permalinks. Resolve #304
Browse files Browse the repository at this point in the history
Also removed comment from the default config which made it invalid JSON.
(The same explanation is already included in README)
  • Loading branch information
tnajdek committed Feb 16, 2024
1 parent d55f757 commit 3000378
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 11 deletions.
10 changes: 0 additions & 10 deletions config/default.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,4 @@
{
"indexConfig": {
// this config is used during the build to configure Zotero Bib
// component both during development and in production. Values
// listed below can be overriden in local.json and/or using
// env variables. See https://www.npmjs.com/package/config
//
// "apiAuthorityPart": undefined,
// "storeURL": undefined,
// "stylesURL": undefined,
// "translatePrefix": "",
// "translateURL": undefined
}
}
4 changes: 3 additions & 1 deletion scripts/build-html.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ const addAnchors = html => {
const $ = cheerio.load(html);
const headers = $('h2, h3');
headers.map((_, element) => {
const id = element.attribs.id;
const id = element.attribs.id ?? $(element).text().replace(/[^\w\s]/g, '').trim().replace(/\s/g, '_').toLocaleLowerCase();
element.attribs.id = id;

$('<a>')
.attr('href', '#' + id)
.addClass('anchor-link')
Expand Down

0 comments on commit 3000378

Please sign in to comment.