-
Notifications
You must be signed in to change notification settings - Fork 148
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Could the search be more powerful? #134
Comments
Please try this theme |
hey @zfk513 , This search is also working for markdown file, And it has also a feature called |
is it support Chinese? |
It supports multilingual. you just need to add the Chinese language. And search can search for everything, but it just shows the title for going to this inner page. |
I've added my own custom search by overriding dot's search with my own: <!-- JavaScript -->
<!--
This file overrides the default search of the dot theme.
Also gets imported in the head.html for more optimal performance.
-->
<script>
$(function() {
const projects = [
{{ range $.Site.Pages }}
{
value: "{{ .Title }}",
label: "{{ .Plain }}",
url:"{{ .Permalink }}",
description: "{{ .Description }}",
keywords: "{{ .Keywords }}"
},
{{ end }}
];
$( "#search" ).autocomplete({
minLength: 3,
// overrides the default search with our own
source: (request, response) => {
// the user input is in the term property. also remove special chars so that regex doesn't cry
const sanitizedInput = request.term.replace(/[^\w\s]/gi, '');
if (!sanitizedInput) {
return response();
}
const substrRegex = new RegExp(sanitizedInput, 'i');
return response(
projects.filter(page => {
// filter out contentless pages like _index.md's
if (page.label) {
// match with either the pages title or keywords.
// Note that the keywords include "[]" at the start and end of them
return substrRegex.test(page.value) || substrRegex.test(page.keywords);
}
}));
},
select: function(event, ui) {
// takes you to the url when you select it, also works with enter
window.location.href = ui.item.url;
},
})
.data( "ui-autocomplete" )._renderItem = function( ul, item ) {
return $( "<li>" )
.append(`<a href="${item.url}">${item.value}</a>`)
.append(`<a href="${item.url}" style="font-size: 80%">${item.description}</a>`)
.appendTo( ul );
};
});
</script> You have to add it as a partial to the project so that you can override the dots search with it in Here's the change we did to our own page to make it work. |
thanks for reply ,it really works! ,but i have couple questions,
|
Did you solve your problem? I am going to close this issue, if you need more help, don't hesitate to reopen this issue. |
now it only search for the title, could it also search on Markdown file?
The text was updated successfully, but these errors were encountered: