alex-shpak / hugo-book

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

Enable the search function to have a summary #585

Open Deng-Xian-Sheng opened 5 months ago

Deng-Xian-Sheng commented 5 months ago

As shown in the figure

image

Deng-Xian-Sheng commented 5 months ago

If the "content = doc.querySelector('#content').querySelector('article').textContent" in the first 100 lines does not work properly, try changing it to "content = doc.querySelector('article').textContent"

Please merge after the main branch test is functioning properly.

Deng-Xian-Sheng commented 1 month ago

I have modified the language of the comments and the images.

Once again, please start the project locally and ensure the search function is working properly before merging into the main branch.

As for why this is necessary, actually, it works fine on my blog, there's no problem with that. However, the theme of my blog is slightly different from your official theme. I made modifications (using Hugo's feature layouts/posts/single.html), so I haven't tested this search function on the official theme (completely unchanged). I believe this is something you should do.

I'm too tired to test this for the official theme.

As mentioned before: If the "content = doc.querySelector('#content').querySelector('article').textContent" in the first 100 lines does not work properly, try changing it to "content = doc.querySelector('article').textContent".

Please merge after the main branch test is functioning properly.

This is also reflected in the code comments.

I hope it works well on the blogs of thousands of people.