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

52 lines
1.5 KiB
Plaintext
Raw Normal View History

2024-01-17 00:27:48 +08:00
<%
2024-05-13 09:45:38 +08:00
const notebook = theme.notebooks.tree[page.notebook]
2024-01-17 00:27:48 +08:00
if (item.filter == null) {
item.filter = 'auto'
}
2024-01-21 22:49:17 +08:00
if (item.placeholder == null && item.filter == 'auto') {
if (theme.wiki.tree[page.wiki]?.name) {
item.placeholder = __('search.search_in', theme.wiki.tree[page.wiki]?.name)
2024-05-13 09:45:38 +08:00
} else if (notebook) {
item.placeholder = __('search.search_in', notebook.name || __('btn.notebook'))
item.filter = notebook.base_dir
2024-01-21 22:49:17 +08:00
}
}
2024-01-17 00:27:48 +08:00
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() %>