Merge branch 'main' of https://github.com/rbetree/menav
This commit is contained in:
1
assets/pinyin-match.js
Normal file
1
assets/pinyin-match.js
Normal file
File diff suppressed because one or more lines are too long
@@ -157,6 +157,7 @@ html {
|
||||
color: var(--text-color);
|
||||
}
|
||||
|
||||
|
||||
body {
|
||||
font-family: var(--font-body);
|
||||
font-weight: var(--font-weight-body);
|
||||
|
||||
7
licenses/pinyin-match.NOTICE.md
Normal file
7
licenses/pinyin-match.NOTICE.md
Normal file
@@ -0,0 +1,7 @@
|
||||
Third-party notice: pinyin-match
|
||||
|
||||
- File: assets/pinyin-match.js (minified vendor script)
|
||||
- Source: To be confirmed; replace with upstream repo URL and exact license.
|
||||
- License: To be added (likely MIT). Include the full license text once verified.
|
||||
|
||||
Vendored to enable offline builds. This notice will be replaced with the exact license details once confirmed.
|
||||
@@ -897,6 +897,12 @@ function copyStaticFiles(config) {
|
||||
console.error('Error copying style.css:', e);
|
||||
}
|
||||
|
||||
try {
|
||||
fs.copyFileSync('assets/pinyin-match.js', 'dist/pinyin-match.js');
|
||||
} catch (e) {
|
||||
console.error('Error copying pinyin-match.js:', e);
|
||||
}
|
||||
|
||||
// 复制JavaScript文件
|
||||
try {
|
||||
fs.copyFileSync('src/script.js', 'dist/script.js');
|
||||
|
||||
@@ -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');
|
||||
|
||||
@@ -140,6 +140,7 @@
|
||||
<script id="menav-config-data" type="application/json" style="display: none;">
|
||||
{{{configJSON}}}
|
||||
</script>
|
||||
<script src="pinyin-match.js"></script>
|
||||
<script src="script.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user