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
Restore "Edit on GitHub" button #3624
Conversation
2021.6.18b35 was a pre-release, and I want to make theme customizations without chasing old code too much.
https://raw.githubusercontent.com/twbs/icons/main/icons/github.svg is
unclear how these interact. also this icon is nice but it's 16x16 while the icons that come with furo are 24x24 -- though that /shouldn't/ matter since they're all vector graphics anyway. |
Given what they have written on that page:
Obligatory IANAL, but I feel like the GitHub logo exists as a concept beyond the literal file |
06e7cbb
to
5cc801c
Compare
I copied and modified two of furo's templates, out of https://github.com/pradyunsg/furo/tree/2021.11.23/src/furo/theme/furo/, combined them with code from a work-in-progress base theme, https://github.com/pradyunsg/sphinx-basic-ng/, being written by the same author. Hopefully this future-proofs us for when furo gets this feature directly. Awkwardly, we represent the edit link with the GitHub icon. This is appropriate for us, but the code for determine_page_edit_link() supports BitBucket and GitLab (but only GitLab.com; and not Gogs/Gitea). I would consider submitting these updates to furo itself. I would want to make sure to have all the service-specific icons imported first, though. If accepted, we could `git rm page.html partials/icons.html`.
5cc801c
to
d04d459
Compare
This is ready to go in. Here's the default view: Here's dark mode in mobile view: Clicking the icon takes you to the proper page to edit on GitHub: I resurrected this part of our conf file spinalcordtoolbox/documentation/source/conf.py Lines 134 to 139 in d04d459
but as mentioned there, those values should be up in |
very cool @kousu ! thanks for the contribution |
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.
Lovely work! ❤️
The bulk of the work LGTM, but I had a few questions/comments about the nitty-gritty details.
<symbol id="svg-github" viewbox="0 0 16 16"> | ||
<!-- by @mdo from https://raw.githubusercontent.com/twbs/icons/main/icons/github.svg --> | ||
<svg xmlns="http://www.w3.org/2000/svg" id="svg-github" width="16" height="16" fill="currentColor" class="bi bi-github" viewBox="0 0 16 16"> | ||
<path d="M8 0C3.58 0 0 3.58 0 8c0 3.54 2.29 6.53 5.47 7.59.4.07.55-.17.55-.38 0-.19-.01-.82-.01-1.49-2.01.37-2.53-.49-2.69-.94-.09-.23-.48-.94-.82-1.13-.28-.15-.68-.52-.01-.53.63-.01 1.08.58 1.23.82.72 1.21 1.87.87 2.33.66.07-.52.28-.87.51-1.07-1.78-.2-3.64-.89-3.64-3.95 0-.87.31-1.59.82-2.15-.08-.2-.36-1.02.08-2.12 0 0 .67-.21 2.2.82.64-.18 1.32-.27 2-.27.68 0 1.36.09 2 .27 1.53-1.04 2.2-.82 2.2-.82.44 1.1.16 1.92.08 2.12.51.56.82 1.27.82 2.15 0 3.07-1.87 3.75-3.65 3.95.29.25.54.73.54 1.48 0 1.07-.01 1.93-.01 2.2 0 .21.15.46.55.38A8.012 8.012 0 0 0 16 8c0-4.42-3.58-8-8-8z"/> | ||
</svg> | ||
</symbol> |
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.
Ahhh! Now I understand why you wanted to include the license for this! I thought we were just linking a image of the GitHub logo... I didn't realize the SVG image you were planning on adding was made by programmatically generating the shape of the GitHub logo.
(TIL about SVG in html... sorry about the misunderstanding earlier.)
<div class="edit-button-container"> | ||
<a class="edit-button" href="{{ determine_page_edit_link() }}"> | ||
<button type="button" class="btn-github" title="{{ _('Edit this page') }}"> | ||
<svg><use href="#svg-github"></use></svg> | ||
</button> | ||
</a> | ||
</div> |
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.
I looked over the changes you made and the core idea here seems fine!
Just to make sure I'm understand correctly, though:
- Internally the furo theme has its own
_templates
directory containing the original copies of all of these files, right? - And, by having our own
_templates
directory, we're overriding the default templates (to include the "Edit on GitHub" changes you made)?
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.
One suggestion: To make these changes easier to understand in the future, maybe one thing we could do is add HTML comments before/after to make it apparent which blocks are ours, and which blocks come from Furo:
<div class="edit-button-container"> | |
<a class="edit-button" href="{{ determine_page_edit_link() }}"> | |
<button type="button" class="btn-github" title="{{ _('Edit this page') }}"> | |
<svg><use href="#svg-github"></use></svg> | |
</button> | |
</a> | |
</div> | |
<!-- start of changes added by @kousu in https://github.com/spinalcordtoolbox/spinalcordtoolbox/pull/3624 --> | |
<div class="edit-button-container"> | |
<a class="edit-button" href="{{ determine_page_edit_link() }}"> | |
<button type="button" class="btn-github" title="{{ _('Edit this page') }}"> | |
<svg><use href="#svg-github"></use></svg> | |
</button> | |
</a> | |
</div> | |
<!-- end of changes added by @kousu in https://github.com/spinalcordtoolbox/spinalcordtoolbox/pull/3624 --> |
That way, a dev looking back on this work doesn't have to diff with the original Furo file to see what the changes were.
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.
I started out by pasting in furo's page.html, then adding a commit that replaced the buttons with {{ include 'partials/buttons.html' }}
, then a third commit that added in the patch I wanted to see. So, in that case, you could easily tell what had happened. But I was defeated having to redo the same for the mobile header icons -- they're not quite able to share the same partial because of how the CSS is set up. So I just backed everything out and did it again.
As an aside: in this case, sphinx-book-theme
scores a few points over furo
: it makes heavier use of partials and makes customizations a lot easier, and easier to track. I wish furo
did too; I think it will eventually because furo's author is hard at work on componentizing all themes in https://github.com/pradyunsg/sphinx-basic-ng/tree/main/src/sphinx_basic_ng/theme/basic-ng/components it's just not been backported there yet.
I could redo the current version to have a 'import from furo' commit followed by a 'patch in the github button' commit. Would that be satisfying?
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.
I could redo the current version to have a 'import from furo' commit followed by a 'patch in the github button' commit. Would that be satisfying?
I think that would work! But, up to you, really. It's a bit of a nitpick... and it's possible that the next time we return to this will be to just remove it anyway (i.e. once it becomes native in furo).
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.
Ah we have squashes forced on this repo so I couldn't do it that way afterall
Co-authored-by: Joshua Newton <joshuacwnewton@gmail.com>
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.
My comments have been more or less addressed! I think you can probably take it from here. :)
* Upgrade furo sphinx theme to a real release. 2021.6.18b35 was a pre-release, and I want to make theme customizations without chasing old code too much. * Display edit link on all docs pages. I copied and modified two of furo's templates, out of https://github.com/pradyunsg/furo/tree/2021.11.23/src/furo/theme/furo/, combined them with code from a work-in-progress base theme, https://github.com/pradyunsg/sphinx-basic-ng/, being written by the same author. Hopefully this future-proofs us for when furo gets this feature directly. Awkwardly, we represent the edit link with the GitHub icon. This is appropriate for us, but the code for determine_page_edit_link() supports BitBucket and GitLab (but only GitLab.com; and not Gogs/Gitea). I would consider submitting these updates to furo itself. I would want to make sure to have all the service-specific icons imported first, though. If accepted, we could `git rm page.html partials/icons.html`. Co-authored-by: Joshua Newton <joshuacwnewton@gmail.com>
Checklist
GitHub
PR contents
Description
Linked issues
Fixes #3490