feat(search): 引入拼音搜索
* add pinyin search * style(highlight): keep theme-aware background - restore theme-aware .highlight with --highlight-bg - add highlight vars for light/dark chore: load pinyin lib before script.js - ensure pinyin-match.js loads before script.js to avoid runtime dependency issues docs: add third-party notice for pinyin-match - add placeholder notice; replace with upstream license after verification --------- Co-authored-by: neo <neo@example.com> Co-authored-by: Maintainer (PR Edit) <maintainer@local>
This commit is contained in:
@@ -665,7 +665,7 @@ document.addEventListener('DOMContentLoaded', () => {
|
||||
|
||||
// 使用更高效的搜索算法
|
||||
const matchedItems = searchIndex.items.filter(item => {
|
||||
return item.searchText.includes(searchTerm);
|
||||
return item.searchText.includes(searchTerm) || PinyinMatch.match(item.searchText, searchTerm);;
|
||||
});
|
||||
|
||||
// 按页面分组结果
|
||||
@@ -800,6 +800,12 @@ document.addEventListener('DOMContentLoaded', () => {
|
||||
title.removeChild(title.firstChild);
|
||||
}
|
||||
title.appendChild(titleFragment);
|
||||
} else if (PinyinMatch.match(title.textContent, searchTerm)) {
|
||||
const arr = PinyinMatch.match(title.textContent, searchTerm);
|
||||
const [start, end] = arr;
|
||||
title.innerHTML = title.textContent.slice(0, start) +
|
||||
`<span class="highlight">${title.textContent.slice(start, end + 1)}</span>` +
|
||||
title.textContent.slice(end + 1);
|
||||
}
|
||||
|
||||
// 安全地高亮描述中的匹配文本
|
||||
@@ -846,6 +852,12 @@ document.addEventListener('DOMContentLoaded', () => {
|
||||
description.removeChild(description.firstChild);
|
||||
}
|
||||
description.appendChild(descFragment);
|
||||
} else if (PinyinMatch.match(description.textContent, searchTerm)) {
|
||||
const arr = PinyinMatch.match(description.textContent, searchTerm);
|
||||
const [start, end] = arr;
|
||||
description.innerHTML = description.textContent.slice(0, start) +
|
||||
`<span class="highlight">${description.textContent.slice(start, end + 1)}</span>` +
|
||||
description.textContent.slice(end + 1);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error highlighting search term');
|
||||
|
||||
Reference in New Issue
Block a user