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 ability to embed a readthedocs style version switcher in static sites #596

Open
samuel-emrys opened this issue Jul 27, 2022 · 4 comments
Labels
enhancement New feature or request

Comments

@samuel-emrys
Copy link

samuel-emrys commented Jul 27, 2022

Context

It's often useful to have multiple versions of documentation, and to be able to switch between these easily. The readthedocs theme makes this easy by providing the structure and css to be able to embed a version switcher by providing a versions.html template, which results in the following:

Screenshot_20220727_221734

I'm using sphinx-multiversion which provides the HTML context with which to populate this version switcher, however it seems as though it's not possible to inject this template anywhere into the sphinx-book-theme to get a similar result to what readthedocs provides in their template.

I notice that in your own documentation, you have an equivalent version switcher:
Screenshot_20220727_221058

However, it doesn't seem to be possible to replicate this using the theme's options, currently.

Proposal

In this issue, I'm proposing adding the features necessary for a user to instantiate the version switcher as demonstrated in your documentation, on their own static website, without using readthedocs.

As far as I can tell, this would mean the addition of the following features:

  • Ability to inject a template into the <div id="rtd-footer-container"> node (currently can only inject into the bd-sidebar__top or bd-sidebar__bottom nodes using existing theme options)
  • Addition of the appropriate CSS for the rst-versions, rst-badge, shift-up, rst-current-version, rst-other-versions, rst-current-item CSS classes. What's missing seems to largely be contained within badge_only.css and readthedocs-doc-embed.css (not currently shipped with this theme).
  • Addition of the appropriate javascript to handle interactivity with the version switcher. This seems to largely be contained within readthedocs-doc-embed.js (not currently shipped with this theme)

I've had limited success hacking my way through this by injecting the above template here:

And adding the aforementioned .css and .js files as static resources (in the _static folder). However, it hasn't been perfect and I'm still missing the interactivity so I assume the javascript isn't working correctly. Not being particularly familiar with sphinx templating or theming, I'm hoping that the way to get this to work will be relatively obvious to one of the maintainers.

Tasks and updates

No response

Related issues

#449
pydata/pydata-sphinx-theme#234
pydata/pydata-sphinx-theme#647

@samuel-emrys samuel-emrys added the enhancement New feature or request label Jul 27, 2022
@welcome
Copy link

welcome bot commented Jul 27, 2022

Thanks for opening your first issue here! Engagement like this is essential for open source projects! 🤗

If you haven't done so already, check out EBP's Code of Conduct. Also, please try to follow the issue template as it helps other community members to contribute more effectively.

If your issue is a feature request, others may react to it, to raise its prominence (see Feature Voting).

Welcome to the EBP community! 🎉

@billcxx
Copy link

billcxx commented Dec 14, 2022

I'm also looking for a solution to integrate the sphinx-multiversion with the book theme

@Cynerd
Copy link

Cynerd commented Jul 2, 2024

For anyone looking for the integration with sphinx-multiversion. I put together template based on this theme and sphinx-multiversion version listing.

{% if versions %}
<nav class="bd-links bd-docs-nav">
    <div class="bd-toc-item navbar-nav">
        <ul class="nav bd-sidenav">
      <li class="toctree-l1 has-children">
        <p class="caption" aria-level="2" role="heading">
          <span type="button" class="caption-text">Version:  {{ current_version.name }}</span>
        </p>
        <input class="toctree-checkbox" id="version-checkbox" name="version-checkbox" type="checkbox"/>
        <label class="toctree-toggle" for="version-checkbox"><i class="fa-solid fa-chevron-down"></i></label>
        <ul>
          {%- for item in versions.branches %}
          <li class="toctree-l2 {% if item == current_version %}current{% endif %} "><a class="reference" href="{{item.url}}">{{item.name}}</a></li>
          {%- endfor %}
          {%- for item in versions.tags|reverse %}
          <li class="toctree-l2 {% if item == current_version %}current{% endif %} "><a class="reference" href="{{item.url}}">{{item.name}}</a></li>
          {%- endfor %}
        </ul>
      </li>
    </ul>
    </div>
</nav>
{% endif %}

It is not perfect but it might be a base for someone who might be willing to invest a bit of more time than me.

@samuel-emrys
Copy link
Author

@agoose77 @choldgraf any chance this could get some love?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants