hexo-theme-stellar/layout/_partial/sidebar/search.ejs

43 lines
1.1 KiB
Plaintext
Raw Normal View History

2024-01-17 00:27:48 +08:00
<%
if (item.filter == null) {
item.filter = 'auto'
}
function layoutDiv() {
var el = ''
el += `<div class="search-wrapper" id="search-wrapper">`
el += `<form class="search-form">`
var filter = ''
if (item.filter == 'auto') {
2024-01-19 01:05:44 +08:00
if (page.wiki) {
2024-01-17 00:27:48 +08:00
let matches = page.path.match(/(.*?)\/(.*?)\//i)
if (matches?.length > 0) {
filter = matches[0]
}
}
} else {
if (item.filter?.length > 0) {
filter = item.filter
}
}
el += `<a class="search-button" onclick="document.getElementById(&quot;search-input&quot;).focus();">`
2024-01-19 13:51:55 +08:00
el += icon('default:search')
2024-01-17 00:27:48 +08:00
el += `</a>`
el += `<input type="text" class="search-input" id="search-input"`
if (filter.length > 0) {
if (!filter.startsWith('/')) {
filter = '/' + filter
}
el += ` data-filter="${filter}"`
el += ` placeholder="${item.placeholder || __('search.search_in', filter)}">`
} else {
el += ` placeholder="${item.placeholder || __('search.search')}">`
}
el += `</form>`
el += `<div id="search-result"></div>`
el += `<div class="search-no-result">${__('search.no_results')}</div>`
el += `</div>`
return el
}
%>
<%- layoutDiv() %>