Skip to content

Commit 2101a39

Browse files
authored
Merge pull request #1959 from dgageot/improve-docs-search
Improve docs search
2 parents b05779f + ea53369 commit 2101a39

File tree

2 files changed

+30
-9
lines changed

2 files changed

+30
-9
lines changed

docs/css/style.css

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -831,24 +831,38 @@ body {
831831
padding: 8px;
832832
}
833833
.search-result {
834-
padding: 12px 16px;
834+
display: block;
835+
padding: 10px 16px;
835836
border-radius: var(--radius);
836837
cursor: pointer;
837838
transition: background 0.15s;
839+
text-decoration: none;
840+
color: var(--text);
838841
}
839842
.search-result:hover,
840843
.search-result:focus {
841844
background: var(--bg-hover);
842845
outline: none;
846+
text-decoration: none;
843847
}
844848
.search-result-title {
845-
font-weight: 600;
849+
font-weight: 500;
846850
font-size: 0.9rem;
847851
color: var(--text);
848852
}
849-
.search-result-section {
850-
font-size: 0.8rem;
853+
.search-result-group {
854+
padding: 12px 16px 4px;
855+
font-size: 0.7rem;
856+
font-weight: 700;
857+
text-transform: uppercase;
858+
letter-spacing: 0.08em;
851859
color: var(--text-muted);
860+
user-select: none;
861+
}
862+
.search-result-group:not(:first-child) {
863+
margin-top: 4px;
864+
border-top: 1px solid var(--border-light);
865+
padding-top: 12px;
852866
}
853867
.search-result-match {
854868
font-size: 0.78rem;

docs/js/app.js

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -169,12 +169,19 @@ function renderSearchResults(query) {
169169
return;
170170
}
171171

172-
$searchResults.innerHTML = results.map(r => `
173-
<a class="search-result" href="${r.url}" tabindex="0" role="option">
172+
// Group results by section to avoid repeating section names
173+
let html = '';
174+
let lastSection = '';
175+
for (const r of results) {
176+
if (r.section && r.section !== lastSection) {
177+
html += `<div class="search-result-group">${r.section}</div>`;
178+
lastSection = r.section;
179+
}
180+
html += `<a class="search-result" href="${r.url}" tabindex="0" role="option">
174181
<div class="search-result-title">${r.title}</div>
175-
${r.section ? `<div class="search-result-section">${r.section}</div>` : ''}
176-
</a>
177-
`).join('');
182+
</a>`;
183+
}
184+
$searchResults.innerHTML = html;
178185

179186
$searchResults.querySelectorAll('.search-result').forEach(el => {
180187
el.addEventListener('click', () => closeSearch());

0 commit comments

Comments
 (0)