Skip to content
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

Search #18

Merged
merged 5 commits into from
Oct 25, 2016
Merged

Search #18

merged 5 commits into from
Oct 25, 2016

Conversation

gwleclerc
Copy link
Contributor

Add search feature and close issue #12

// Initialize lunrjs using our generated index file
function initLunr() {
// First retrieve the index file
$.getJSON("/json/search.json")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems does not work if baseurl = "https://foo/bar"
GET https://foo/json/search.json instead of https://foo/bar/json/search.json

<input id="search-by" type="text" placeholder="Search Documentation" data-search-input="/lunr.json/query">
<span data-search-clear=""><i class="fa fa-close"></i></span>
</div>
{{ partial "search.html" . }}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be more flexible if {{ partial "search.html" . }} is not in header class, like :

<nav id="sidebar">
  <div id="header-wrapper">
    <div id="header">
      {{ partial "logo.html" . }}
    </div>
    {{ if .Site.Params.search }}
      {{ partial "search.html" . }}
    {{ end }}
</div>


And set `search = true` in your config.toml

To generate your lunr index, you can see this project https://github.com/gwleclerc/lunr-hugo which parse your markdown files and extract toml and yaml headers to create index with corresponding format.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you put a full example step by step to use this lib here ?

@yesnault
Copy link

And for :

---
title: "bar"
weight: 5
toc: true
---

--> Title is not included in search.json after running lunr-hugo.

meta.data.title is empty here https://github.com/gwleclerc/lunr-hugo/blob/master/lib/index.js#L123

@gwleclerc
Copy link
Contributor Author

very strange because it does work with

---
title: Get started
icon: '<i class="fa fa-road"></i>'
chapter: true
aliases:
- /start
next: "/start/introduction"
weight: 0
---

@gwleclerc
Copy link
Contributor Author

I launch lunr-hugo using this command:
lunr-hugo -i "docs/**/*.md" -o static/json/search.json -l yaml

… + add a step to explain how to use lunr-hugo + update perfect-scrollbar
@matcornic
Copy link
Owner

Thanks @gwleclerc for your new commit.

Could you :

  1. Move the search documentation into the real one : https://github.com/matcornic/hugo-learn-doc ? I would prefer to not have 2 locations of documentation.
  2. Add search to list of functionalities with a link to the right section in documentation ?

@matcornic matcornic merged commit a74c02d into master Oct 25, 2016
@ilyasustun
Copy link

Although I have installed npm and lunr-hugo I get the bash: lunr-hugo: command not found using bash and similar from command prompt. I use Win 10. Can anyone help me?

@matcornic
Copy link
Owner

@ilyasustun you don't need lunr anymore to use search feature in v2 version. But your problem is probably because npm binary folder is not in your PATH environment variables (or you opened a cmd before installing npm)

@ilyasustun
Copy link

Thanks for the prompt answer. Is v2 the version of hugo or learn-theme?

@ilyasustun
Copy link

Hey I got it fixed. I used npm install -g lunr-hugo and that fixed the PATH issue.

Another important question: If I have both .md and .Rmd files in my content folder, how can I get them both indexed into the search file?

@matcornic
Copy link
Owner

v2 is for learn theme. Both should work as search (at least in v2) is working from hugo Pages API : https://github.com/matcornic/hugo-theme-learn/blob/1e715f4aff563ed2c2aea2bb7de7e54ab2962669/layouts/index.json

There is still an open issue about R Markdown though

@ilyasustun
Copy link

I have managed to create the search.json file by using .Rmd extension instead of .md extension. It looks the same as it should be with title, tags and everything. However, when I run my website the search only acts like ctrl+f, no matter what I did I could not get it to function properly :(

patrick-othmer pushed a commit to patrick-othmer/hugo-theme-learn that referenced this pull request Oct 7, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants