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 json index #1998

Merged
merged 4 commits into from
Oct 30, 2022
Merged

Search json index #1998

merged 4 commits into from
Oct 30, 2022

Conversation

sgued
Copy link
Contributor

@sgued sgued commented Sep 29, 2022

Based on this discussion

Sanity check:

  • Have you checked to ensure there aren't other open Pull Requests for the same update/change?

Code changes

(Delete or ignore this section for documentation changes)

  • Are you doing the PR on the next branch?

If the change is a new feature or adding to/changing an existing one:

  • Have you created/updated the relevant documentation page(s)?

Description

This PR adds an index_format configuration item.

[search]
index_format = "javascript" | "json"

When set to Javascript, a JSON file is created instead of a js file for the index.

This is:

  • More convenient. Lazy-loading Json is easier than a script
  • More flexible. The JSON file can be loaded with the fetch API and be manipulated more easily than a script that sets a global variable for which you don't control the name. While it's not a use case I encountered, I don't think the current setup makes it easy to load multiple search index at the same time, for example for multiple languages.

The docs are updated to

  • Document the feature
  • Use the feature and lazy-load the index, saving more than 1MB (200KB with compression) from loading when just loading the site.

@Keats
Copy link
Collaborator

Keats commented Oct 11, 2022

This is an interesting feature.
There has been some request to generate in other formats (#1745, #1849).

components/config/src/config/search.rs Outdated Show resolved Hide resolved
components/config/src/config/search.rs Outdated Show resolved Hide resolved
@sgued sgued force-pushed the search-json-index branch from 573d43c to d9acc9e Compare October 11, 2022 20:28
@Jieiku
Copy link
Contributor

Jieiku commented Oct 13, 2022

I really like this idea. It also makes me wonder if this could be leveraged to generate a css file?

Jieiku/abridge#72

At the very least I can take a look at what you have done here to get some ideas.

@sgued
Copy link
Contributor Author

sgued commented Oct 13, 2022

I really like this idea. It also makes me wonder if this could be leveraged to generate a css file?

Jieiku/abridge#72

At the very least I can take a look at what you have done here to get some ideas.

A css file for what?

Edit: I think you mean csp

@Jieiku
Copy link
Contributor

Jieiku commented Oct 13, 2022

My idea was to create a way for shortcodes to be able to write a portion of their output into a css file.

The issue I linked discusses it in more detail, this is unrelated to search functionality, the only connection is being able to write to a file other than html.

Jieiku/abridge#72

The problem is that you don't want style tags in the middle of an html page if you have a strict content security policy, because it would disallow this, so instead you would make the shortcode write the style related stuff directly to a css file.

Writing style tags to a page via a shortcode is probably not a common use for a shortcode, but it is how I facilitate changing the image on mouse hover (useful thing for image comparison, especially in photography and video compression related blogs).

@Keats
Copy link
Collaborator

Keats commented Oct 15, 2022

My idea was to create a way for shortcodes to be able to write a portion of their output into a css file.

That's not going to happen I think but it would be unrelated to that

@sgued sgued force-pushed the search-json-index branch from d9acc9e to c716bfc Compare October 30, 2022 12:59
@sgued sgued requested a review from Keats October 30, 2022 13:24
@Keats Keats merged commit c889cab into getzola:next Oct 30, 2022
Keats pushed a commit that referenced this pull request Feb 16, 2023
* search: Add support for a JSON index

* docs: Document JSON index for search

* docs: Use lazy-loaded JSON index

* Add elasticlunr prefix to search engine format configuration

This will be useful if support for more search libraries are added in the future
@Jieiku
Copy link
Contributor

Jieiku commented Apr 3, 2023

I am in the process of refactoring the Abridge theme, I got this json index search feature working a few moments ago, but noticed one thing... there is no cachebust hash on the json index

so if you add new posts... repeat visitors may not have those posts in their index if their browser still has the old index cached, correct?

Other than that works great!

One very nice thing about fetching json instead of loading the javascript later is that it will not violate a strict csp since its simply json, before I was using this:

https://github.com/Jieiku/abridge/blob/master/static/search_facade.js

(with the above script, I update the hashes using an npm script)

@Keats
Copy link
Collaborator

Keats commented Apr 3, 2023

Can you open a new issue for the missing cachebust?

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.

3 participants