Skip to content

Commit d79cbdc

Browse files
author
Mridul
committed
fix(generateSearch): prevent #undefined in search URLs when heading lacks id
1 parent be6a2c8 commit d79cbdc

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

scripts/generateSearch.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,12 @@ function generateContents() {
7171
el = $(el);
7272
const title = el.text();
7373
const html = el.nextUntil('h3').html();
74+
const id = el.prop('id');
75+
const baseUrl = filename.replace('.md', '.html').replace(/^docs/, '');
7476
const content = new Content({
7577
title: `${file.title}: ${title}`,
7678
body: html,
77-
url: `${filename.replace('.md', '.html').replace(/^docs/, '')}#${el.prop('id')}`
79+
url: id ? `${baseUrl}#${id}` : baseUrl
7880
});
7981

8082
content.validateSync();
@@ -102,10 +104,12 @@ function generateContents() {
102104
el = $(el);
103105
const title = el.text();
104106
const html = el.nextUntil('h3').html();
107+
const id = el.prop('id');
108+
const baseUrl = filename.replace('.pug', '.html').replace(/^docs/, '');
105109
const content = new Content({
106110
title: `${file.title}: ${title}`,
107111
body: html,
108-
url: `${filename.replace('.pug', '.html').replace(/^docs/, '')}#${el.prop('id')}`
112+
url: id ? `${baseUrl}#${id}` : baseUrl
109113
});
110114

111115
content.validateSync();

0 commit comments

Comments
 (0)