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

Add version switcher to the site #575

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open

Conversation

TymekDev
Copy link
Contributor

@TymekDev TymekDev commented Apr 17, 2024

Changes

Closes #530

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 version1:
    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

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

  1. Every version has its own sitemap.xml
  2. Every version has separate assets (Bootstrap, favicons, ...)
  3. All versions are indexed by search engines
  4. None of the versions has canonical URLs
  5. "Source" link in vignettes and function reference is hardcoded to HEAD (instead of a respective version)
  6. Switching a version redirects to index (instead of staying on the same subpage in target version if it exists)
  7. Rhinoverse button resembling a back button makes is even more confusing. Pressing it neither puts you back to the default version nor to a root of the current version you are viewing. It sends you to an entirely new website.

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

  1. Visit https://tymekdev.github.io/rhino
  2. Use the switcher in the navbar
  3. Observe how content and URL changes after selecting a new version

Footnotes

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

@codecov-commenter
Copy link

codecov-commenter commented Apr 17, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 38.55%. Comparing base (82476b5) to head (da3c82d).

❗ Current head da3c82d differs from pull request most recent head 6d9ac99. Consider uploading reports for the commit 6d9ac99 to get more accurate results

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #575   +/-   ##
=======================================
  Coverage   38.55%   38.55%           
=======================================
  Files          10       10           
  Lines         594      594           
=======================================
  Hits          229      229           
  Misses        365      365           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@TymekDev
Copy link
Contributor Author

TymekDev commented Apr 22, 2024

I just realized that with this change we should build pkgdown on push to main. This way documentation of the development version stays up to date.

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)
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.
@TymekDev TymekDev force-pushed the 530-versioned-pkgdown branch 2 times, most recently from ad2d6c4 to d1ee335 Compare May 8, 2024 08:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Show old versions of documentation
2 participants