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

40 lines
1.1 KiB
Plaintext

<%
function layoutDiv() {
var el = '<widget class="widget-wrapper search">'
el += '<div class="widget-body">'
el += '<div class="search-wrapper" id="search">'
el += '<form class="search-form">'
var filter = ''
if (item.filter == 'auto') {
if (page.layout == 'wiki') {
let matches = page.path.match(/(.*?)\/(.*?)\//i)
if (matches?.length > 0) {
filter = matches[0]
}
}
} else {
if (item.filter?.length > 0) {
filter = item.filter
}
}
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>'
el += '</div>'
el += '</widget>'
return el
}
%>
<%- layoutDiv() %>