Skip to content

Commit

Permalink
First version of a version picker for Bevy Book
Browse files Browse the repository at this point in the history
Added to the bottom of the Book section list on the left.

- Reads versions from `content/learn/book/versions.toml` so we can start
  working on the book for a new version and have the content in `main`
  without neccessarly publishing it on the website
  • Loading branch information
Captain-Of-Coit committed Apr 20, 2023
1 parent b81dc3c commit af2dac4
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 0 deletions.
7 changes: 7 additions & 0 deletions content/learn/book/versions.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# [[versions]]
# title = "v0.12.0"
# path = "/learn/book/v0.12.0"

[[versions]]
title = "v0.11.0"
path = "/learn/book/v0.11.0"
1 change: 1 addition & 0 deletions templates/book-section.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

{% block page_menu %}
{{book_macros::book_menu(prefix="page-menu", root=get_section(path="learn/book/_index.md"))}}
{{book_macros::version_menu()}}
{% endblock %}

{% block page_content %}
Expand Down
36 changes: 36 additions & 0 deletions templates/macros/book.html
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,39 @@
{% endfor %}
</ul>
{% endmacro %}

{% macro version_menu() %}
{% set book_versions = load_data(path="content/learn/book/versions.toml") %}
{% set prefix = 'versions-menu' %}
<ul class="tree-menu">
{% set id = prefix ~ '-' ~ 'root-version' | slugify %}
{% set class = "tree-menu__item" %}
{% set label_class = "tree-menu__label" %}

{% set label_class = label_class ~ " tree-menu__label--with-chevron" %}
<input id="{{id}}" class="tree-menu__state" type="checkbox" {% if is_in_branch %}checked{% endif %}>

<li class="{{class}}">
<div class="{{label_class}}">
<a class="tree-menu__link" href="#">Versions</a>
{% if section.subsections %}
<label class="tree-menu__toggle" for="{{id}}">
<img class="tree-menu__chevron" src="/assets/icon-chevron-down.svg">
</label>
{% endif %}
</div>
<ul class="tree-menu">
{% for version in book_versions.versions %}
{% set version_id = prefix ~ '-' ~ version.path | slugify %}
{% set version_class = "tree-menu__item" %}
{% set version_label_class = "tree-menu__label" %}
<li class="{{version_class}}">
<div class="{{version_label_class}}">
<a class="tree-menu__link" href="{{version.path}}">{{ version.title }}</a>
</div>
</li>
{% endfor %}
</ul>
</li>
</ul>
{% endmacro %}

0 comments on commit af2dac4

Please sign in to comment.