alex-shpak / hugo-book

Hugo documentation theme as simple as plain book
https://hugo-book-demo.netlify.app
MIT License
3.4k stars 1.17k forks source link

The Search Spinner Keeps Spinning And No Result Appear #566

Closed Qian-Donglin closed 7 months ago

Qian-Donglin commented 11 months ago

First of all, thank you for making this fantastic theme!

Now I use hugo-book theme, and suddenly I found I cannot use the search. My customization is only add katex for using $$ to represents the numerical formula on hugo-book/layouts/partials/docs/html-head.html. The added code is following.

<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/katex@0.16.8/dist/katex.min.css"
    integrity="sha384-GvrOXuhMATgEsSwCs4smul74iXGOixntILdUW9XmUC6+HX0sLNAK3q71HotJqlAn" crossorigin="anonymous">

<script defer src="https://cdn.jsdelivr.net/npm/katex@0.16.8/dist/katex.min.js"
    integrity="sha384-cpW21h6RZv/phavutF+AuVYrr+dA8xD9zs6FwLpaCct6O9ctzYFfFr4dgmgccOTx"
    crossorigin="anonymous"></script>

<script defer src="https://cdn.jsdelivr.net/npm/katex@0.16.8/dist/contrib/auto-render.min.js"
    integrity="sha384-+VBxd3r6XgURycqtZ117nYw44OOcIax56Z4dCRWbxyPt0Koah1uHoK0o4+/RRE05" crossorigin="anonymous"
    onload="renderMathInElement(document.body);"></script>

<script>
    document.addEventListener("DOMContentLoaded", function () {
        renderMathInElement(
            document.body,
            {
                delimiters: [
                    { left: "$$", right: "$$", display: true },
                    { left: "\\[", right: "\\]", display: true },
                    { left: "$", right: "$", display: false },
                    { left: "\\(", right: "\\)", display: false }
                ]
            });
    });
</script>

And I hit on this problem in both of my local and github pages. Are there someone knowing how to resolve it?

image
alex-shpak commented 10 months ago

Hi! do you see some error in browser console? what is your --baseURL when you build the site?

millionhz commented 9 months ago

I have the same issue. Here are my findings:

My website is hosted on github pages so the baseURL is of form: username.github.io/website

In order to retrieve assets the hugo page makes request to username.github.io/website but for search date the page is making request to username.github.io/en.search-data.json instead of username.github.io/website/en.search-data.json

millionhz commented 9 months ago

See #571 and #505

alex-shpak commented 7 months ago

Closing in favour of https://github.com/alex-shpak/hugo-book/pull/505