Fixed invalid outdated version banner URL when using instant loading

This commit is contained in:
squidfunk 2022-03-02 09:26:00 +01:00
parent 1cc250625b
commit bcc2c180cd
12 changed files with 52 additions and 27 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -34,7 +34,7 @@
{% endif %}
{% endblock %}
{% block styles %}
<link rel="stylesheet" href="{{ 'assets/stylesheets/main.e8d9bf0c.min.css' | url }}">
<link rel="stylesheet" href="{{ 'assets/stylesheets/main.2d9f7617.min.css' | url }}">
{% if config.theme.palette %}
{% set palette = config.theme.palette %}
<link rel="stylesheet" href="{{ 'assets/stylesheets/palette.e6a45f82.min.css' | url }}">
@ -214,7 +214,7 @@
</script>
{% endblock %}
{% block scripts %}
<script src="{{ 'assets/javascripts/bundle.b88e97c5.min.js' | url }}"></script>
<script src="{{ 'assets/javascripts/bundle.5413a266.min.js' | url }}"></script>
{% for path in config["extra_javascript"] %}
<script src="{{ path | url }}"></script>
{% endfor %}

View File

@ -122,7 +122,7 @@ if (feature("navigation.instant"))
/* Set up version selector */
if (config.version?.provider === "mike")
setupVersionSelector()
setupVersionSelector({ document$ })
/* Always close drawer and search on navigation */
merge(location$, target$)

View File

@ -237,6 +237,7 @@ export function setupInstantLoading(
"[data-md-component=announce]",
"[data-md-component=container]",
"[data-md-component=header-topic]",
"[data-md-component=outdated]",
"[data-md-component=logo]",
"[data-md-component=skip]",
...feature("navigation.tabs.sticky")

View File

@ -22,12 +22,14 @@
import {
EMPTY,
Subject,
combineLatest,
filter,
fromEvent,
map,
of,
switchMap
switchMap,
switchMapTo
} from "rxjs"
import { configuration } from "~/_"
@ -45,14 +47,29 @@ import {
import { fetchSitemap } from "../sitemap"
/* ----------------------------------------------------------------------------
* Helper types
* ------------------------------------------------------------------------- */
/**
* Setup options
*/
interface SetupOptions {
document$: Subject<Document> /* Document subject */
}
/* ----------------------------------------------------------------------------
* Functions
* ------------------------------------------------------------------------- */
/**
* Set up version selector
*
* @param options - Options
*/
export function setupVersionSelector(): void {
export function setupVersionSelector(
{ document$ }: SetupOptions
): void {
const config = configuration()
const versions$ = requestJSON<Version[]>(
new URL("../versions.json", config.base)
@ -115,17 +132,25 @@ export function setupVersionSelector(): void {
.subscribe(([versions, current]) => {
const topic = getElement(".md-header__topic")
topic.appendChild(renderVersionSelector(versions, current))
})
/* Integrate outdated version banner with instant loading */
document$.pipe(switchMapTo(current$))
.subscribe(current => {
/* Check if version state was already determined */
if (__md_get("__outdated", sessionStorage) === null) {
let outdated = __md_get("__outdated", sessionStorage)
if (outdated === null) {
const latest = config.version?.default || "latest"
const outdated = !current.aliases.includes(latest)
outdated = !current.aliases.includes(latest)
/* Persist version state in session storage */
__md_set("__outdated", outdated, sessionStorage)
if (outdated)
for (const warning of getComponentElements("outdated"))
warning.hidden = false
}
/* Unhide outdated version banner */
if (outdated)
for (const warning of getComponentElements("outdated"))
warning.hidden = false
})
}

View File

@ -50,4 +50,3 @@
<!-- Extra JavaScript (can't be set in mkdocs.yml due to content hash) -->
<script src="{{ 'overrides/assets/javascripts/bundle.js' | url }}"></script>
{% endblock %}