-
Notifications
You must be signed in to change notification settings - Fork 25
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 version switcher to the site #575
Conversation
136bb34
to
878d948
Compare
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #575 +/- ##
===========================================
- Coverage 38.55% 20.65% -17.91%
===========================================
Files 10 9 -1
Lines 594 460 -134
===========================================
- Hits 229 95 -134
Misses 365 365 ☔ View full report in Codecov by Sentry. |
I just realized that with this change we should build Thoughts? |
This script provides a function for building a pkgdown site with multiple versions. Versions are defined by: - ref - a git ref to build. In the gist, prefix tags with `refs/tags/` and branches with `refs/remotes/origin/` - href - a URL path where the version will be available at - label - a label to display in a version switcher. Using true will take version from DESCRIPTION and append "(dev)" suffix The script works as follows: 1. Copy repository into a temporary directory 2. Read `pkgdown/navbar_template.html` and populate switcher options with versions 3. For every version*: a. Create a git worktree based on version's ref b. Populate the navbar template with current version's label c. Write the navbar template to `pkgdown/templates/navbar.html` relative to the git worktree d. Copy `pkgdown/extra.css` from the repository we are building out of (this ensures a consistent and up-to-date styling) e. Use pkgdown to build site f. Remove the worktree * Version with "/" href will be built first. This avoids an error from pkgdown regarding building the site to a non-empty directory (that's not managed by pkgdown). The resulting build has the site with "/" href in the destination directory. Respective versions are stored in subdirectories named after labels defining versions. Known issues - Every version has its own `sitemap.xml` - Every version has separate assets (Bootstrap, favicons, ...) - All versions are indexed by search engines - None of the versions has canonical URLs - "Source" link in vignettes and function reference is hardcoded to HEAD (instead of a respective version) - Switching a version redirects to index (instead of staying on the same subpage in target version if it exists)
878d948
to
8e9fd75
Compare
This change pins bslib version to 0.5.1 to keep Bootstrap 5.2.2. Switching to a newer bslib (and Bootstrap) version requires fixing CSS.
ad2d6c4
to
d1ee335
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.
Awesome! 💯 It's all working pretty great. The only must-have changes are: workflow configuration (run on push to main) and styling issue (white box). Treat my remaining comments as suggestions.
It would be possible to inject the version switcher using before_navbar
(see this commit) to get a perhaps cleaner solution. You can use it if you want or I could send you a follow-up PR 😉
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.
LGTM, great work! 🎉 💯
My notes from the review for future reference:
Ideas for improvements:
|
Changes
Closes #530
This script provides a function for building a pkgdown site with multiple versions.
Versions are defined by:
refs/tags/
and branches withrefs/remotes/origin/
The script works as follows:
pkgdown/navbar_template.html
and populate switcher options with versionsa. Create a git worktree based on version's ref
b. Populate the navbar template with current version's label
c. Write the navbar template to
pkgdown/templates/navbar.html
relative to the git worktreed. Copy
pkgdown/extra.css
from the repository we are building out of (this ensures a consistent and up-to-date styling)e. Use pkgdown to build site
f. Remove the worktree
The resulting build has the site with "/" href in the destination directory. Respective versions are stored in subdirectories named after labels defining versions.
Known issues
sitemap.xml
To address 1.-4. it's best to contribute directly to pkgdown. I think the effort of adjusting this script and keeping relevant templates up-to-date would be bigger than implementing a proper version support directly in pkgdown.
Additionally, I pinned bslib version to keep Bootstrap 5.2.2. Using latest bslib that provides Bootstrap 5.3.0 resulted in styling partially breaking on the site. However, the styling altogether should be revisited and improved.
How to test
Footnotes
Version with "/" href will be built first. This avoids an error from pkgdown regarding building the site to a non-empty directory (that's not managed by pkgdown). ↩