-
Notifications
You must be signed in to change notification settings - Fork 143
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
Add "Edit on GitHub" links #3398
base: main
Are you sure you want to change the base?
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- 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/install
does not exist,https://github.com/teemtee/tmt/blob/main/stories/install.fmf
does.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
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