Skip to content

Commit 115c489

Browse files
authored
add nif page (#26)
1 parent 799483c commit 115c489

5 files changed

Lines changed: 628 additions & 71 deletions

File tree

docs/_/js/search-ui.js

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -133,14 +133,9 @@
133133
document.head.appendChild(link);
134134
}
135135

136-
function highlightPageTitle (title, terms) {
137-
const positions = getTermPosition(title, terms);
138-
return buildHighlightedText(title, positions, snippetLength)
139-
}
140-
141136
function highlightSectionTitle (sectionTitle, terms) {
142137
if (sectionTitle) {
143-
const text = sectionTitle.text;
138+
const text = sectionTitle.title ?? sectionTitle.text;
144139
const positions = getTermPosition(text, terms);
145140
return buildHighlightedText(text, positions, snippetLength)
146141
}
@@ -156,8 +151,7 @@
156151
return []
157152
}
158153

159-
function highlightText (doc, terms) {
160-
const text = doc.text;
154+
function highlightText (text, terms) {
161155
const positions = getTermPosition(text, terms);
162156
return buildHighlightedText(text, positions, snippetLength)
163157
}
@@ -183,9 +177,12 @@
183177
}
184178
}
185179
return {
186-
pageTitleNodes: highlightPageTitle(doc.title, terms.title || []),
180+
pageTitleNodes: highlightText(doc.title, terms.title || []),
187181
sectionTitleNodes: highlightSectionTitle(sectionTitle, terms.title || []),
188-
pageContentNodes: highlightText(doc, terms.text || []),
182+
pageContentNodes: highlightText(
183+
sectionTitle?.title && sectionTitle.text ? sectionTitle.text : doc.text,
184+
terms.text || []
185+
),
189186
pageKeywordNodes: highlightKeyword(doc, terms.keyword || []),
190187
}
191188
}
@@ -199,12 +196,12 @@
199196
let sectionTitle;
200197
if (ids.length > 1) {
201198
const titleId = ids[1];
202-
sectionTitle = doc.titles.filter(function (item) {
199+
sectionTitle = doc.titles.find(function (item) {
203200
return String(item.id) === titleId
204-
})[0];
201+
});
205202
}
206203
const metadata = item.matchData.metadata;
207-
const highlightingResult = highlightHit(metadata, sectionTitle, doc);
204+
const highlightingResult = highlightHit(metadata, sectionTitle || doc, doc);
208205
const componentVersion = store.componentVersions[`${doc.component}/${doc.version}`];
209206
if (componentVersion !== undefined && currentComponent !== componentVersion) {
210207
const searchResultComponentHeader = document.createElement('div');

0 commit comments

Comments
 (0)