Conversation
ab47c7d to
c92b81c
Compare
|
Good idea, but it's not going to be that simple. It will work for pages that exist as ReST files in the repo, and that's just a subset of pages Sphinx consumes and renders. Specification, stories, plugins, plus a couple more, all these are generated either from Python sources or, in the case of large content in specification and stories, from fmf files. So, a simple link to https://tmt--3398.org.readthedocs.build/en/3398/spec/core.html -> 404. Edit: on top of that, one page generated by Sphinx is often constructed from multiple fmf stories, multiple fmf files. "Edit on Github" should then most likely point to a directory rather than a single file. https://tmt.readthedocs.io/en/stable/spec/core.html -> https://github.com/teemtee/tmt/tree/main/spec/core |
|
Template uses Sphinx hasdoc function to check if the page has source. Possible solution is to let Sphinx generate the docs with extension, like https://www.sphinx-doc.org/en/master/tutorial/automatic-doc-generation.html Or save a copy of generated sources in the repo. |
|
All right. The feature can be turned on and off on page by page basis. Setting |
|
https://tmt--3398.org.readthedocs.build/en/3398/spec/core.html is generated from https://github.com/teemtee/tmt/tree/main/spec/core but I don't see what generates it https://github.com/teemtee/tmt/blob/main/docs/Makefile EDIT: Okay, it is generated by https://github.com/teemtee/tmt/blob/main/docs/scripts/generate-stories.py |
https://github.com/teemtee/tmt/blob/main/docs/Makefile#L133: |
|
It would be cool to have it as part of #3088 |
|
@martinhoyer it would be nice to get proper standard for "Edit on GitHub" links in Spinx, but folks on @readthedocs probably have different priorities. I would be happy to take this as a freelance job, just to focus. |
3226c26 to
7f14663
Compare
|
@happz spec link works https://tmt--3398.org.readthedocs.build/en/3398/spec/core.html |
34c95dc to
097e152
Compare
| # Metadata - | ||
| # https://www.sphinx-doc.org/en/master/usage/restructuredtext/field-lists.html | ||
| doc.write( | ||
| f':github_url: https://github.com/teemtee/tmt/blob/main{area}' |
There was a problem hiding this comment.
- The URL is invalid for forks and every branch beyond
main - Some areas are directories, some are fmf files. It's not important to fmf, which can handle both correctly, but here we would need to make a distinction.
https://github.com/teemtee/tmt/blob/main/stories/installdoes not exist,https://github.com/teemtee/tmt/blob/main/stories/install.fmfdoes.
Every story object should have web_link() method, which returns a link to the corresponding fmf file, that would be perfect, but that's for "edit on github" per section rather than per page. My initial idea would be to collect all web links for the area stories, and find their common, shared prefix and use that one. I don't like it, but right now I don't have a better one.
There was a problem hiding this comment.
The URL points to main, but it should be valid as long as file path in repo doesn't change. Does it makes sense to propose edits to branches?
For .fmf vs directory, the generate script knows which template to invoke, and it can set the URL correctly. What is needed, is the list of this generated entries to check, and generators that produce them. To make sure nothing falls apart.
| doc.write( | ||
| f':github_url: https://github.com/teemtee/tmt/blob/main{area}' | ||
| ) |
There was a problem hiding this comment.
The :github_url: metadata field is missing a newline character at the end. Consider modifying the string to include \n at the end:
doc.write(
f':github_url: https://github.com/teemtee/tmt/blob/main{area}\n'
)This ensures proper separation between the metadata field and subsequent content in the generated RST file, preventing potential formatting issues in the documentation.
| doc.write( | |
| f':github_url: https://github.com/teemtee/tmt/blob/main{area}' | |
| ) | |
| doc.write( | |
| f':github_url: https://github.com/teemtee/tmt/blob/main{area}\n' | |
| ) |
Spotted by Diamond
Is this helpful? React 👍 or 👎 to let us know.
|
What is the state of this? I am working on refactoring the sphinx implementation which automatically adds the reference to the original docstrings as best as it can. Isn't there a sphinx extension that can hook into those and add the element to the individual items? I can help with this feature if you can help me figure out how to create that edit element. |
|
@LecrisUT the problem is missing |
On the tmt side? Don't worry about it, I am gradually introducing explicit source links to the files for individual sections in #4288. The things I don't know are if having links to the local git repo is enough and how can we customize it and tweak it to our intricacies. E.g. we would want to make the edit button point differently for each section or object because the sources are quite scattered, similar to autodoc. |
Ideally, it should be on Sphinx side, and then incorporated into theme. If the page is composed of multiple sources, I would list them all. |
I mean the missing |
|
@LecrisUT the |
|
Again sorry for the long silence here. The sphinx integration is still being worked on, and maybe with the introduction of the new way of handling stories, I hope things can work more easily out-of-the-box. Regarding this change, I think we are actually good to go to have it in the current form. Eventually all generated files should go away, and it should work fine. If you can rebase this to keep only the For the long-term vision, I have an idea on how to fix the linkage issue from the tinkering done over this. We already add some html objects like in tmt/docs/ext/tmt_domain/story.py Line 65 in 887a8ac We can add one of them to be the edit button and point it to the correct source, because we can extract it (or rather a good enough approximation of it) when building these. If you know some references to check for a similar design, or if there are some extensions to work on top of, that would help. This has some strong overlap with how sphinx.ext.autodoc works, so I do wonder if there is no work being done in that area.
|
Allow to easily jump to documentation page contents in repository.
The explanation is here https://stackoverflow.com/a/62904217
Related readthedocs/sphinx_rtd_theme#1635
Pull Request Checklist