-
Notifications
You must be signed in to change notification settings - Fork 6.5k
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
doc: samples: Introduce code sample categories #77400
Conversation
a2f876f
to
0f086c0
Compare
1e01b03
to
d5be859
Compare
5815ba1
to
ad39ade
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adopt zephyr:code-sample directive to describe the Dining Philosophers sample and update reference accordingly. Signed-off-by: Benjamin Cabé <[email protected]>
move domain.py to domain/ to make it easier to keep things organized and e.g. add dedicated css/js resources, etc. Signed-off-by: Benjamin Cabé <[email protected]>
This commit adds support for categorizing code samples in the documentation. It introduces two new directives: - `zephyr:code-sample-category::` to create a category and associated brief description, that implicitly acts as a toctree too. - `zephyr:code-sample-listing::` to allow dumping a list of samples corresponding to a category anywhere in the documentation. Fixes zephyrproject-rtos#62453. Signed-off-by: Benjamin Cabé <[email protected]>
This commit uses the new .. zephyr:code-sample-category directive to categorize code samples across the tree. Updates existing legacy references to manually defined targets to now use :zephyr:code-sample-category: role instead. Signed-off-by: Benjamin Cabé <[email protected]>
ad39ade
to
6bbef8e
Compare
@@ -27,4 +27,4 @@ Building and Running | |||
This sample can be found under :zephyr_file:`samples/bluetooth/observer` in the | |||
Zephyr tree. | |||
|
|||
See :ref:`Bluetooth samples section <bluetooth-samples>` for details. | |||
See :zephyr:code-sample-category:`Bluetooth samples section <bluetooth>` for details. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See :zephyr:code-sample-category:`Bluetooth samples section <bluetooth>` for details. | |
See :zephyr:code-sample-category:`bluetooth` samples for details. |
Suggest to make this consistent with the others
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure! As you can probably imagine, I went for the easy "search and replace" without necessarily putting more thought into it :)
@gmarull did you have time to take a look at this PR? I might not be able to come back to it soon but as it will likely be a source of merge conflicts, it would be good to get this in sooner than later in case it is good enough to go. Thanks! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is great stuff! Thanks @kartben
https://builds.zephyrproject.io/zephyr/pr/77400/docs/samples/index.html
This PR enhances the documentation framework by introducing support for categorizing and listing code samples. This also makes better use of the already available metadata that
.. zephyr:code-sample
directive allows to associate to each sample, namely, the short description.New directives:
.. zephyr:code-sample-category::
Defines a category for grouping related code samples, which is similar to what used to be manually done, and usually in an inconsistent way. Also for the sake of consistency and minimizing the risk of people misusing Sphinx's toctree, the directive also acts as an implicit toctree, "mounting" all the samples (or sub-categories) underneath it... zephyr:code-sample-listing::
Generates a listing of all the samples for a category (or more than one, actually), optionally with an input field allowing to do filtering of the samples and get them "MQTT", "PWM", "ESP32", etc. samples to quickly show up.New roles:
:zephyr:code-sample-category::
References a code sample category from anywhere in the documentation, similar to:zephyr:code-sample:
role.This change should also help encourage code sample authors to take better care of the metadata (ex. have a really good short description) for their samples as this makes them much more discoverable.
Limitations:
Sub-categories and code samples are always listed alphabetically. If deemed useful, I can add some kind of "featured-subcategories" and "featured-samples" options to allow "promoting" some items to the top of their respective lists, but I am not certain this is critical to have (in this first implementation, or ever). It's true that we may want the "Basic" category to be listed first, though, so definitely open to discussion especially as I have some working code for this already (just don't feel like making the directive crazy-customizable from day 1 if not strictly needed).
Sorting everything alphabetically is arguably infinitely better and more consistent than what we had anyway, as samples in a given category would typically be listed according to their folder name, which might be very different from their actual name as per the title of the README. Therefore, listing such as https://docs.zephyrproject.org/latest/samples/bluetooth/bluetooth.html or https://docs.zephyrproject.org/latest/samples/net/net.html are effectively very randomly sorted today and not very easy to navigate at a glance.
Incremental build might need some polishing, but it's likely also true for code-samples, as some dependencies might not alway be captured.
Not necessarily a limitation as this forces us to also organize documentation sources cleanly in the first place but atm it's not possible to define categories in just any document and then randomly "attach" a sample to a given category. A category needs to be defined in a folder that contains a sample, and a sample is automatically added to the first category found in its parent folders' hierarchy.
What that means in practice is should e.g. Bluetooth want to create sub-categories for e.g. Mesh, Audio, etc., the first step would be to create
samples/bluetooth/audio/
,samples/bluetooth/mesh
, etc., move the relevant samples there, and then add an .rst file declaring the category in said folders. Again, not necessarily a limitation IMO, just something to be aware of.Includes a commit from #77478 as I wanted to already align the docs for the new directives/roles with the changes implemented there.
The actual Sphinx extension work is in the commit
doc: extensions: samples: Introduce code sample categories
and the changes in the commit that follows, while intimidating, are really about converting existing "legacy" categories and references to them to the new system.