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

Custom content (e.g. front matter) added to Lunr search index #1067

Closed
diablodale opened this issue Dec 19, 2022 · 1 comment · Fixed by #1068
Closed

Custom content (e.g. front matter) added to Lunr search index #1067

diablodale opened this issue Dec 19, 2022 · 1 comment · Fixed by #1068

Comments

@diablodale
Copy link
Contributor

JTD creates search-data.json for Lunr only from the page.content, page.title, and sometimes headers (which are already in the page.content). This misses all the information/content that is in Front Matter, data files, etc.

I use JTD to render highly structured content by a combination of Front Matter custom attributes and a page's content (that text content that is below the Front Matter). Many of my rendered pages have half of their rendered html sourced from my Front Matter attributes. Therefore, the Lunr search index is missing a large amount of my content.

The Ask -- What to build?

  • No change in today's JTD Lunr behavior by default
  • Adding this feature should not break existing JTD users
  • Those that want custom data in Lunr should have a method that uses site config, _include files, or some
    easily "pluggable" method to add their custom data into Lunr's index

Proposal

I've written a working prototype, PR forthcoming.
Three code blocks need to change

  1. JTD needs to write the additional custom data/content into search-data.json for Lunr's index
  2. Lunr itself needs to be configured to receive this new data
  3. Lunr needs the expanded data loaded into its runtime index

This can be achieved by...

  1. Add {% include lunr-data.json page=page %} to assets/js/zzzz-search-data.json so that a user can write
    custom code to gather and insert their custom content/data into the JSON. Update rake also.
  2. Add {% include lunr-index.js %} to assets/js/just-the-docs.js so that a user can write custom code
    to load their custom JSON into the runtime Lunr index. My prototype supports adding custom data into
    already existing indices (e.g. content). Support for new custom Lunr indices seems not valuable given complexity.
    To do so requires a 3rd include file or something in site config.
  3. Add two blank lunr-xxx include files to JTD theme -- the default setup has therefore no change in behavior.

Related discussions

olivernn/lunr.js#100
https://katydecorah.com/code/lunr-and-jekyll/

diablodale added a commit to diablodale/just-the-docs that referenced this issue Dec 19, 2022
- add framework for custom content into
  Lunr indices
@diablodale
Copy link
Contributor Author

More of my content is frontmatter/data driven and NOT below the --- on a page. By default, JTD only indexes that which is below ---. Nothing in a layout, includes within layouts, etc. This leads me down a thought path...

  1. I have to continue to expand the extra data put into the index using my prototype. This can be neverending. 🥱
  2. Change the approach of indexing "content". Core JTD uses lunr.index = page.content. Perhaps change that to page.output. Might have to isolate the ... but that isn't too difficult.

diablodale added a commit to diablodale/just-the-docs that referenced this issue Jan 9, 2023
- add framework for custom content into
  Lunr indices
- update docs for this feature
mattxwang added a commit that referenced this issue Jan 14, 2023
This is a prototype for review and discussion. My use and testing of this PR is on top of 6d9d413. The changes are trival to rebase to `main` and I'm happy to do so if this prototype moves forward.


* Feature request details in linked issue, fixes #1067
* I welcome feedback and all discussion
* A draft doc site of mine using this PR is at https://docs.hidale.com/

To use the prototype, the two include files need to be customized. Here are mine from the draft website diablodale/dp.docs@9c0d836

Co-authored-by: Matt Wang <matt@matthewwang.me>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant