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

Restore "Edit on GitHub" button #3624

Merged
merged 3 commits into from Dec 17, 2021
Merged

Restore "Edit on GitHub" button #3624

merged 3 commits into from Dec 17, 2021

Conversation

kousu
Copy link
Contributor

@kousu kousu commented Dec 13, 2021

Checklist

GitHub

PR contents

Description

Linked issues

Fixes #3490

2021.6.18b35 was a pre-release, and I want to make theme customizations
without chasing old code too much.
@kousu kousu changed the title Restoer "Edit on GitHub" button Restore "Edit on GitHub" button Dec 13, 2021
@kousu
Copy link
Contributor Author

kousu commented Dec 13, 2021

https://github.com/logos

GITHUB®, the GITHUB® logo design, OCTOCAT® and the OCTOCAT® logo design are exclusive trademarks registered in the United States by GitHub, Inc.

The OCTOCAT design is the exclusive property of GitHub, Inc and has been federally registered with the United States Copyright Office. All rights reserved.

No adaptation or use of any kind of any of our registered trademarks or copyrights, or any other contents of this website, is allowed without the express written permission of GitHub, Inc.

For more information regarding the authorized uses of these items please contact us.

https://raw.githubusercontent.com/twbs/icons/main/icons/github.svg is

The MIT License (MIT)

Copyright (c) 2019-2021 The Bootstrap Authors

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

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.

@joshuacwnewton
Copy link
Member

joshuacwnewton commented Dec 13, 2021

https://github.com/logos

Given what they have written on that page:

Do these awesome things

  • Use the Octocat or GitHub logo to link to GitHub
  • Use the Mark in social buttons to link to your GitHub profile or project
  • Use the Octocat or GitHub logo to advertise that your product has built-in GitHub integration
  • Use the Octocat or GitHub logo in a blog post or news article about GitHub

Obligatory IANAL, but I feel like the GitHub logo exists as a concept beyond the literal file github.svg, so I would think that GitHub's recommendations take precedent over the license for that one file. (i.e. I think we're fine to use the GitHub logo in this context.)

@kousu kousu force-pushed the ng/docs-furo-edit-on-github branch 3 times, most recently from 06e7cbb to 5cc801c Compare December 17, 2021 02:21
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`.
@kousu kousu force-pushed the ng/docs-furo-edit-on-github branch from 5cc801c to d04d459 Compare December 17, 2021 02:23
@kousu
Copy link
Contributor Author

kousu commented Dec 17, 2021

This is ready to go in. Here's the default view:

lightfull

Here's dark mode in mobile view:

Screenshot from 2021-12-16 21-11-39

Clicking the icon takes you to the proper page to edit on GitHub:

Screenshot from 2021-12-16 21-12-24

I resurrected this part of our conf file

html_context = {
# TODO: when the Github icon is supported natively by furo (https://github.com/pradyunsg/furo/discussions/114)
# then this should be moved into html_theme_options and the theme_ prefix should be dropped
"theme_source_repository": "https://github.com/spinalcordtoolbox/spinalcordtoolbox",
"theme_source_branch": "master", # or subprocess.check_output(["git", "rev-parse", "--abbrev-ref", "HEAD"]) ?
"theme_source_directory": "documentation/source/",

but as mentioned there, those values should be up in html_theme_options -- I just wasn't able to get that that to work. They're not allowed there until furo declares knowing them as options.

@jcohenadad
Copy link
Member

very cool @kousu ! thanks for the contribution

@kousu kousu marked this pull request as ready for review December 17, 2021 16:19
Copy link
Member

@joshuacwnewton joshuacwnewton left a 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.

documentation/source/conf.py Show resolved Hide resolved
setup.py Show resolved Hide resolved
documentation/source/_templates/partials/icons.html Outdated Show resolved Hide resolved
Comment on lines +68 to +73
<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>
Copy link
Member

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.)

documentation/source/conf.py Show resolved Hide resolved
documentation/source/conf.py Show resolved Hide resolved
Comment on lines +75 to +81
<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>
Copy link
Member

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)?

Copy link
Member

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:

Suggested change
<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.

Copy link
Contributor Author

@kousu kousu Dec 17, 2021

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?

Copy link
Member

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).

Copy link
Contributor Author

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>
Copy link
Member

@joshuacwnewton joshuacwnewton left a 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. :)

@kousu kousu merged commit 64de35d into master Dec 17, 2021
joshuacwnewton added a commit that referenced this pull request Jan 18, 2022
* 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>
@joshuacwnewton joshuacwnewton added this to the 5.5 milestone Jan 26, 2022
@joshuacwnewton joshuacwnewton added the documentation category: readthedocs, sourceforge, or SCT courses label Jan 26, 2022
@joshuacwnewton joshuacwnewton deleted the ng/docs-furo-edit-on-github branch May 2, 2023 13:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation category: readthedocs, sourceforge, or SCT courses
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Edit on GH button
3 participants