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

feat: customize search_data for an extra #2017

Merged
merged 3 commits into from
Jan 14, 2025

Conversation

zachdaniel
Copy link
Contributor

This allows configuring the "search data" for any given extra. When you do this, you take over the way that the extra appears both in autocomplete and in search_data. The current system assumes that you give this information in markdown, which I think is a safe assumption, but we could do something like allow for an html_body or markdown_body to be given, etc.

This is likely not going to be useful for 99% of people, and as such I think its okay that its not super ergonomic. Specifically, you have to completely manage the search content etc. The way this will be used, however, is in Spark where we generate markdown files for DSL documentation. With this change, we can add a function called Spark.Dsl.search_data_for(Your.Dsl) which will improve the autocomplete experience and the search experience in various ways (by adding more things to autocomplete than just headers, and by customizing the type of the search data nodes

@josevalim I know we had discussed a sort of "unification" of search-data and sidebar-items, but I think this does let me kick the can down the road a little bit.

With this PR ex_doc provides a way to customize the search data for extras (which I need) that encompasses all of the information that currently drives both search-data and sidebar-items. This means that we are free to refactor those two files internally, and my code that customizes searchable content for extras won't be affected. Additionally, since you configure the search_data for an extra completely (it replaces the autogenerated search data), we don't double index the same material but differently.

If this approach is amenable then I can work up some documentation and add some additional tests for how it modifies search data. Only didn't do that because I think there will be some discussion/back and forth on naming, implementation, etc. (or even if this is something that ex_doc will accept 😄 )

Copy link

github-actions bot commented Jan 11, 2025

@zachdaniel
Copy link
Contributor Author

{"test/fixtures/README.md",
search_data: [
%{
anchor: "heading-without-content",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is one particular annoyance here. The top item of the search data is the "module body" of the page, and it doesn't have an anchor. So we need to allow anchor to be an empty string and add a test that we emit the proper code (i.e. no trailing #).

@zachdaniel zachdaniel force-pushed the customize-extra-search-data branch from 11fbc6e to ba72416 Compare January 12, 2025 18:40
@zachdaniel
Copy link
Contributor Author

@josevalim I believe I've addressed your comments. Instead of using custom I've used the key searchData since it aligns more with how it is configured and will be used in general.

Also added a test in the js spec.

@zachdaniel zachdaniel force-pushed the customize-extra-search-data branch from ba72416 to c367a89 Compare January 12, 2025 18:43
@zachdaniel zachdaniel marked this pull request as ready for review January 12, 2025 18:43
@zachdaniel zachdaniel force-pushed the customize-extra-search-data branch from c367a89 to e84b754 Compare January 12, 2025 18:45
@zachdaniel zachdaniel force-pushed the customize-extra-search-data branch from e84b754 to b1ee88b Compare January 12, 2025 20:55
@zachdaniel
Copy link
Contributor Author

Okay @josevalim I think it should align better with what you are looking for now (which is better than what I had). There is still some conditional logic changes required in the autocomplete code, but I've explained each in a comment.

lib/mix/tasks/docs.ex Outdated Show resolved Hide resolved
lib/mix/tasks/docs.ex Outdated Show resolved Hide resolved
Copy link
Member

@josevalim josevalim left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are almost there! I have only dropped nitpicks now. :)

@zachdaniel
Copy link
Contributor Author

@josevalim ready for another round 🙇

lib/mix/tasks/docs.ex Outdated Show resolved Hide resolved
@zachdaniel
Copy link
Contributor Author

@josevalim done.

@zachdaniel
Copy link
Contributor Author

zachdaniel commented Jan 13, 2025

lemme squash all these commits actually.

Okay, now its good to go.

This allows configuring the "search data" for any given extra. When you
do this, you take over the way that the extra appears both in
autocomplete and in search_data. The current system assumes that you
give this information in markdown, which I think is a safe assumption,
but we could do something like allow for an html_body or markdown_body
to be given, etc.

This is likely not going to be useful for 99% of people, and as such I
think its okay that its not super ergonomic. Specifically, you have to
completely manage the search content etc. The way this will be used,
however, is in Spark where we generate markdown files for DSL
documentation. With this change, we can add a function called
Spark.Dsl.search_data_for(Your.Dsl) which will improve the autocomplete
experience and the search experience in various ways (by adding more
things to autocomplete than just headers, and by customizing the type of
the search data nodes
@zachdaniel zachdaniel force-pushed the customize-extra-search-data branch from 10cbe36 to effbc74 Compare January 13, 2025 16:40
@zachdaniel
Copy link
Contributor Author

@josevalim done

@josevalim josevalim merged commit 2381e3c into elixir-lang:main Jan 14, 2025
4 checks passed
@josevalim
Copy link
Member

💚 💙 💜 💛 ❤️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants