Error getting Lunr index file - when site is open from disc

Dear sirs,

My inquiry is about lunr search implementation, I googled everywhere (jekyll users have similar questions) - and could not find an advice. The problem is to generate a relative link to the index file.

I’m using doc dock theme for a documentation site which users will open from the file system. and the problem is that search.js can not pick the index.json.

Here’s how the variable is defined for search.js to pick the index.json:
var baseurl = “{{.Site.BaseURL}}”

I’m having relative links on in the config file:
relativeURLs = true

My expected result is that the base url variable will contain relative path from my context to the publish directory. The actual result is that it pastes what I have in the baseURL (in my config it is set to “/”) without computing the relative path:
var baseurl = “/”;

I guess this is because baseurl variable is inside tag?

I posted an example of repository which reproduces this case:

Please advise if there’s a trick I an use to make search work with site running from disk?

Thank you
Anastasia

Untested, but try:

var baseurl = "{{ .Site.BaseURL | relURL }}";

Edit: well, nevermind. According to the docs example:

{{ "http://gohugo.io/" | relURL }} →  "http://gohugo.io/"

yes, I tried this one. I think it just have to be automatically relURL because relativeURL=true in the config…

Is hardcoding the path to /index.json an option? Because judging by this file it looks like index.json is always at the site root.

@zwbetz
Given BaseURL="/" and relativeURL = true, these statements:

        <script type="text/javascript">
              var baseurl = "{{ "/index.json" }}";
        </script>

and

        <script type="text/javascript">
              var baseurl = "{{ "/index.json" | relURL }}";
        </script>

both produce `var baseurl = “/index.json” - not relative links

Help me out here. What does the index file link need to be relative to?

@zwbetz Zachary, i guess relative to each page

Imagine, the site is on disk im folder /user/apo/dir1/di2/documentation/

Index file would be in the same folder.

If I walk to an html page in section ./features/editing/feature1.html I want on this page the var baseurl to be …/…/ - so that it points to the root as a relative link.

Does that make sense?

That makes sense…

But I’m still not understanding your question. My understanding of Lunr JS is that it needs a single index file. And this single file can be referenced by any other page by using /index.json

So are you unable to do this?

/index.json means root. I need not global root, but root of site (where the user unzipped the site - I don’t know the path, hence need the link to be relative to current page, for instance …/…/index.json

I see your issue now. Sorry about that, I missed the part about it being served from local disk vs web server.

So like you mentioned, I’m curious why the relative link for that file isn’t being produced. Because your config file looks fine. And when viewing your publish folder, the other links are definitely relative. Hmm…

Maybe hugo does not understand that in this expression “baseurl = smth” - smth is a link? could there be any workaround?