Skip to content

Commit 8c59b22

Browse files
committed
Integrate review feedback
1 parent a0d2121 commit 8c59b22

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

src/browserlib/map-ids-to-headings.mjs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -86,21 +86,21 @@ export default function () {
8686
let href = nodeid;
8787

8888
if (parentSection) {
89-
let alternateIds = [];
89+
const ids = [];
9090
let id;
9191

9292
const heading = parentSection.heading;
9393
if (heading.id) {
9494
id = heading.id;
9595
href = getAbsoluteUrl(heading, { singlePage });
96-
alternateIds.push(id);
96+
ids.push(id);
9797
}
9898
else {
9999
const anchor = heading.querySelector('a[name]');
100100
if (anchor) {
101101
id = anchor.getAttribute('name');
102102
href = getAbsoluteUrl(anchor, { singlePage, attribute: 'name' });
103-
alternateIds.push(id);
103+
ids.push(id);
104104
}
105105
}
106106

@@ -115,13 +115,16 @@ export default function () {
115115

116116
const mapping = {};
117117
if (id) {
118-
mapping.id = id;
118+
ids.push(id);
119+
120+
}
121+
if (ids.length) {
122+
mapping.id = ids.pop();
119123
}
120-
alternateIds = alternateIds.filter(id => id !== mapping.id);
121124
mapping.href = href;
122125
mapping.title = trimmedText.replace(reNumber, '');
123-
if (alternateIds.length) {
124-
mapping.alternateIds = alternateIds;
126+
if (ids.length) {
127+
mapping.alternateIds = ids;
125128
}
126129
mappingTable[nodeid] = mapping;
127130

0 commit comments

Comments
 (0)