|
| 1 | +{%- comment -%} |
| 2 | + Per-product documentation version selector, rendered at the top of the sidebar. |
| 3 | + |
| 4 | + Lists the current product's versions (newest first, per _data/products.yml), |
| 5 | + marks the one being viewed, and badges the version that `latest` aliases. Links |
| 6 | + point at each version's root (e.g. /openvox/9.x/); switching versions is a |
| 7 | + deliberate, infrequent jump, and root links stay correct in the theme's |
| 8 | + persistent (Turbo-navigated) sidebar without per-page rewriting. Keeping the |
| 9 | + reader on the same page across a switch is a possible later enhancement. |
| 10 | + |
| 11 | + Each qualifying product gets a block so the selector survives Turbo navigation |
| 12 | + between products; the layout-end script shows the block matching the current |
| 13 | + collection and marks the active version. A product is skipped when it is flagged |
| 14 | + single_version (no numbered collections, e.g. OpenVox Containers) or has fewer |
| 15 | + than two versions — there is nothing to switch between, so no picker is shown. |
| 16 | + The wrapper is only emitted when at least one product qualifies, to avoid a |
| 17 | + stray empty bordered box. |
| 18 | +{%- endcomment -%} |
| 19 | +{%- capture version_picker_groups -%} |
| 20 | + {%- for product_entry in site.data.products -%} |
| 21 | + {%- assign product_id = product_entry[0] -%} |
| 22 | + {%- assign product = product_entry[1] -%} |
| 23 | + {%- if product.single_version == true -%}{%- continue -%}{%- endif -%} |
| 24 | + {%- if product.versions.size < 2 -%}{%- continue -%}{%- endif -%} |
| 25 | + |
| 26 | + {%- comment -%} Collections this product owns: each numbered version, plus the _latest alias. {%- endcomment -%} |
| 27 | + {%- assign latest_alias = product_id | append: '_latest' -%} |
| 28 | + {%- assign collections = '' -%} |
| 29 | + {%- assign latest_collection = '' -%} |
| 30 | + {%- for version in product.versions -%} |
| 31 | + {%- assign version_collection = version.collection | remove_first: '_' -%} |
| 32 | + {%- assign collections = collections | append: version_collection | append: '|' -%} |
| 33 | + {%- if version.id == product.latest -%}{%- assign latest_collection = version_collection -%}{%- endif -%} |
| 34 | + {%- endfor -%} |
| 35 | + {%- assign collections = collections | append: latest_alias -%} |
| 36 | + {%- assign collection_list = collections | split: '|' -%} |
| 37 | + |
| 38 | + {%- assign is_current_product = false -%} |
| 39 | + {%- if collection_list contains page.collection -%}{%- assign is_current_product = true -%}{%- endif -%} |
| 40 | + |
| 41 | + <div class="VPVersionPickerGroup" data-product="{{ product_id }}" data-collections="{{ collections }}" data-latest-collection="{{ latest_collection }}"{% unless is_current_product %} hidden{% endunless %}> |
| 42 | + <span class="VPVersionPickerLabel">{{ product.label }} version</span> |
| 43 | + <ul class="VPVersionPickerList"> |
| 44 | + {%- for version in product.versions -%} |
| 45 | + {%- assign version_collection = version.collection | remove_first: '_' -%} |
| 46 | + {%- assign is_active = false -%} |
| 47 | + {%- if version_collection == page.collection -%} |
| 48 | + {%- assign is_active = true -%} |
| 49 | + {%- elsif page.collection == latest_alias and version.id == product.latest -%} |
| 50 | + {%- assign is_active = true -%} |
| 51 | + {%- endif -%} |
| 52 | + <li> |
| 53 | + <a class="VPVersionPickerItem{% if is_active %} is-active{% endif %}" href="{{ version.base }}" data-collection="{{ version_collection }}"{% if is_active %} aria-current="true"{% endif %}> |
| 54 | + <span class="VPVersionPickerVersion">{{ version.label }}</span> |
| 55 | + {%- if version.id == product.latest -%}<span class="VPVersionPickerBadge">latest</span>{%- endif -%} |
| 56 | + </a> |
| 57 | + </li> |
| 58 | + {%- endfor -%} |
| 59 | + </ul> |
| 60 | + </div> |
| 61 | + {%- endfor -%} |
| 62 | +{%- endcapture -%} |
| 63 | +{%- assign version_picker_groups = version_picker_groups | strip -%} |
| 64 | +{%- if version_picker_groups != '' -%} |
| 65 | +<div class="VPVersionPicker" id="vp-version-picker">{{ version_picker_groups }}</div> |
| 66 | +{%- endif -%} |
0 commit comments