Comments (7)
I've added my own custom search by overriding dot's search with my own:
global_search_script.hml
:
<!-- 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 head.tml
and all the pages that use the search bar. Putting it into header of the document is a bit nicer as then the whole big list of all the pages gets cached by the browser.
Here's the change we did to our own page to make it work.
from dot-hugo.
Please try this theme
https://gethugothemes.com/products/godocs-hugo-documentation-theme/ .
It has advance search feature
from dot-hugo.
hey @zfk513 ,
This search is also working for markdown file, And it has also a feature called search keyword
, You can set a custom keyword for searching.
from dot-hugo.
hey @zfk513 ,
This search is also working for markdown file, And it has also a feature called
search keyword
, You can set a custom keyword for searching.
is it support Chinese?
and i update the theme,try on my local ,i still find it can only search the title,though the code show it search the content,thx for reply
from dot-hugo.
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.
from dot-hugo.
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.
thanks for reply ,it really works! ,but i have couple questions,
- if we can search the whole content,why should we have keywords?
- it is possible to add another line under the title when we searching ,like using the search engine,and yellow light out the search word in some context ?cause only see the title maybe not help,
from dot-hugo.
Did you solve your problem? I am going to close this issue, if you need more help, don't hesitate to reopen this issue.
from dot-hugo.
Related Issues (20)
- Broken "Home" link when not using multiple languages (regression) HOT 2
- Navigation with many subitems is hard to navigate HOT 7
- Modify column width HOT 2
- H2 being generated instead of H1 HOT 3
- installation problem HOT 15
- Google analytics still cannot be found HOT 5
- Extra space added after line using icon within paragraph HOT 6
- Formspree.io legacy forms is not longer available HOT 1
- Show related articles with shared keywords at the bottom of an article HOT 1
- actionArgumentsにoptionsを追加する
- Setting a custom favicon overrides the theme's head.html, breaking the website HOT 3
- QUESTION: Add PDF export feature to upstream? HOT 3
- Error: module "dot" not found HOT 2
- Bug: Commit d127d5e breaks banner image on index page
- Banner is incorrectly displayed on mobile HOT 2
- Update to Bootstrap 5 HOT 1
- Language switch redirects to wrong URL HOT 1
- New icon from FontAwesome not show
- this template does not seem to be compatible with the latest version of hugo (0.120.4) HOT 2
- config.toml is missning HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from dot-hugo.