diff --git a/content/about.md b/content/about.md index ce2698aa..ec4d26e7 100644 --- a/content/about.md +++ b/content/about.md @@ -32,78 +32,3 @@ draft: false - -
输入关键词并回车进行搜索
'; + return; + } + + var results = window.searchIndex.filter(function(item) { + return (item.title && item.title.toLowerCase().includes(query)) || + (item.summary && item.summary.toLowerCase().includes(query)); + }); + + if (results.length > 0) { + var html = results.map(function(item) { + return ` + + `; + }).join(''); + searchResults.innerHTML = html; + + // Refresh PJAX to recognize new links + if (window.pjax) { + window.pjax.refresh(searchResults); + } + } else { + searchResults.innerHTML = '未找到相关文章
'; + } + }); + } + } +} + +function initInlineSearch() { + var header = document.getElementById('essay-header'); + var searchContainer = document.getElementById('search-container'); + var input = document.getElementById('inline-search-input'); + var resultsContainer = document.getElementById('inline-search-results'); + + window.toggleSearchMode = function(show) { + if (!header || !searchContainer || !input || !resultsContainer) return; + + if (show) { + header.style.display = 'none'; + searchContainer.style.display = 'block'; + input.focus(); + loadSearchIndex(); + } else { + header.style.display = 'inline-flex'; + searchContainer.style.display = 'none'; + input.value = ''; + resultsContainer.classList.remove('show'); + resultsContainer.innerHTML = ''; + } + }; + + if (!header || !searchContainer || !input || !resultsContainer) return; + + // Input Event + var newInput = input.cloneNode(true); + input.parentNode.replaceChild(newInput, input); + input = newInput; + + input.addEventListener('input', function() { + var query = this.value.trim().toLowerCase(); + + if (query.length === 0) { + resultsContainer.classList.remove('show'); + resultsContainer.innerHTML = ''; + return; + } + + if (!window.searchIndex) return; + + var results = window.searchIndex.filter(function(item) { + return (item.title && item.title.toLowerCase().includes(query)) || + (item.summary && item.summary.toLowerCase().includes(query)); + }); + + if (results.length > 0) { + var html = results.slice(0, 5).map(function(item) { + return ` + + ${item.title} +