Files
docmd-io--docmd/packages/ui/templates/partials/version-dropdown.ejs
T
wehub-resource-sync 6db8fca185
docmd CI verification / verify (push) Failing after 0s
chore: import upstream snapshot with attribution
2026-07-13 12:31:55 +08:00

59 lines
2.7 KiB
Plaintext

<%# ---------------------------------------------------------------
# docmd : the zero-config documentation engine.
# @website https://docmd.io
# [docmd-source] - Please do not remove this header.
# ---------------------------------------------------------------
%>
<% if (versions && versions.all.length > 0) {
const current = activeVersion || versions.all.find(v => v.id === versions.current);
// If we are in a sub-version (e.g. /v1/), we go up one level (../) to get to root.
const isCurrentSubVersion = current && current.id !== versions.current;
const upOneLevel = isCurrentSubVersion ? '../' : '';
%>
<div class="docmd-version-dropdown">
<button class="version-dropdown-toggle" aria-expanded="false" aria-label="<%= typeof t === 'function' ? t('selectVersion') : 'Select Version' %>">
<%- renderIcon('git-branch', { class: 'version-icon' }) %>
<span class="version-label">
<%= current ? current.label : (typeof t === 'function' ? t('version') : 'Version') %>
</span>
<%- renderIcon('chevron-down', { class: 'version-chevron' }) %>
</button>
<ul class="version-dropdown-menu">
<% versions.all.forEach(v => {
const isCurrentActive = current && v.id === current.id;
const isTargetRootVersion = v.id === versions.current;
// Include locale prefix for non-default locales
const locPrefix = (typeof localePrefix !== 'undefined' && localePrefix) ? localePrefix : '';
// Include locale prefix only if the target version has i18n for this locale
const versionI18nMap = config._versionI18nMap || {};
const targetHasLocale = locPrefix ? versionI18nMap[v.id] !== false : true;
const effectiveLocPrefix = targetHasLocale ? locPrefix : '';
const targetSuffix = isTargetRootVersion ? '' : v.id + '/';
// Use centralised URL builder — single source of truth
const absoluteHref = (typeof buildAbsoluteUrl === 'function')
? buildAbsoluteUrl(config.base || '/', effectiveLocPrefix, targetSuffix, '')
: ((config.base || '/').replace(/\/?$/, '/') + effectiveLocPrefix + targetSuffix);
// Data Root for JS Sticky Logic
const dataRoot = absoluteHref;
%>
<li>
<a href="<%= absoluteHref %>"
class="version-dropdown-item <%= isCurrentActive ? 'active' : '' %>"
data-spa-ignore
data-version-root="<%= dataRoot %>">
<%= v.label %><% if (v.id === versions.current) { %> <span class="version-latest-badge"><%= typeof t === 'function' ? t('latest') : 'Latest' %></span><% } %>
<% if (isCurrentActive) { %>
<%- renderIcon('check', { class: 'version-check' }) %>
<% } %>
</a>
</li>
<% }) %>
</ul>
</div>
<% } %>