Added support for displaying version aliases

This commit is contained in:
squidfunk 2024-05-15 17:24:40 +02:00
parent 485fa76fbc
commit cc398ddc33
No known key found for this signature in database
GPG Key ID: 5ED40BC4F9C436DF
12 changed files with 37 additions and 13 deletions

View File

@ -317,6 +317,12 @@
}
],
"default": "stable"
},
"alias": {
"title": "Show alias next to version number",
"markdownDescription": "https://squidfunk.github.io/mkdocs-material/setup/setting-up-the-versioning/#version-alias",
"type": "boolean",
"default": true
}
}
},

View File

@ -23,5 +23,5 @@
{% endblock %}
{% block scripts %}
{{ super() }}
<script src="{{ 'assets/javascripts/custom.63a6dff3.min.js' | url }}"></script>
<script src="{{ 'assets/javascripts/custom.b457887c.min.js' | url }}"></script>
{% endblock %}

View File

@ -44,7 +44,7 @@
{% endif %}
{% endblock %}
{% block styles %}
<link rel="stylesheet" href="{{ 'assets/stylesheets/main.732c4fb1.min.css' | url }}">
<link rel="stylesheet" href="{{ 'assets/stylesheets/main.6543a935.min.css' | url }}">
{% if config.theme.palette %}
{% set palette = config.theme.palette %}
<link rel="stylesheet" href="{{ 'assets/stylesheets/palette.06af60db.min.css' | url }}">
@ -249,7 +249,7 @@
</script>
{% endblock %}
{% block scripts %}
<script src="{{ 'assets/javascripts/bundle.7c1205d0.min.js' | url }}"></script>
<script src="{{ 'assets/javascripts/bundle.ebd0bdb7.min.js' | url }}"></script>
{% for script in config.extra_javascript %}
{{ script | script_tag }}
{% endfor %}

View File

@ -83,6 +83,7 @@ export type Translations =
export interface Versioning {
provider: "mike" /* Version provider */
default?: string | string[] /* Default version */
alias?: boolean /* Show alias */
}
/**

View File

@ -64,6 +64,11 @@ function renderVersion(version: Version): HTMLElement {
<li class="md-version__item">
<a href={`${url}`} class="md-version__link">
{version.title}
{config.version?.alias && version.aliases.length && (
<span class="md-version__alias">
{version.aliases[0]}
</span>
)}
</a>
</li>
)
@ -84,6 +89,7 @@ function renderVersion(version: Version): HTMLElement {
export function renderVersionSelector(
versions: Version[], active: Version
): HTMLElement {
const config = configuration()
versions = versions.filter(version => !version.properties?.hidden)
return (
<div class="md-version">
@ -92,6 +98,11 @@ export function renderVersionSelector(
aria-label={translation("select.version")}
>
{active.title}
{config.version?.alias && active.aliases.length && (
<span class="md-version__alias">
{active.aliases[0]}
</span>
)}
</button>
<ul class="md-version__list">
{versions.map(renderVersion)}

View File

@ -76,6 +76,12 @@
}
}
// Version alias
&__alias {
margin-left: px2rem(6px);
opacity: 0.7;
}
// Version selection list
&__list {
position: absolute;