Skip to content

Commit de98ece

Browse files
committed
Skip auto-injection if a manual "See also" section already exists
Pre-render check in the client-side JS: scan the article body for any H2-H4 heading whose text matches "See also" (case-insensitive, optional trailing : or .) and bail out before fetching/rendering the auto recs. This addresses the duplicate-section concern raised by p-amyjiang on the PR -- about 57 wiki articles already ship a manually written See also list, and they should keep authorial curation untouched. The auto-injected `.sa-heading` is excluded from the detector so the guard stays idempotent if the script ever re-runs on the same DOM.
1 parent 86daddd commit de98ece

1 file changed

Lines changed: 14 additions & 0 deletions

File tree

assets/js/see-also.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,20 @@
77
var target = document.querySelector('.page__content');
88
if (!target) return;
99

10+
// Skip auto-injection if the page already has a manually written
11+
// "See also" heading (preserves authorial curation). Matches H2-H4,
12+
// case-insensitive, with an optional trailing ":" or ".". Excludes
13+
// the heading we ourselves inject (`.sa-heading`) so the check stays
14+
// idempotent under any future re-render.
15+
var existingHeadings = target.querySelectorAll(
16+
'h2:not(.sa-heading), h3:not(.sa-heading), h4:not(.sa-heading)'
17+
);
18+
for (var i = 0; i < existingHeadings.length; i++) {
19+
if (/^\s*see\s+also\s*[:.]?\s*$/i.test(existingHeadings[i].textContent)) {
20+
return;
21+
}
22+
}
23+
1024
fetch('/assets/see-also.json', { credentials: 'same-origin' })
1125
.then(function (r) {
1226
if (!r.ok) throw new Error('HTTP ' + r.status);

0 commit comments

Comments
 (0)