web/updates: update hash on navigation, navigate if present on load

This commit is contained in:
dumbmoron 2024-07-16 17:21:53 +00:00
parent a22b0e5136
commit 3305bba28a
No known key found for this signature in database

View file

@ -1,7 +1,8 @@
<script lang="ts"> <script lang="ts">
import { SvelteComponent, onMount } from 'svelte'; import { onMount } from 'svelte';
import type { ChangelogImport, ChangelogMetadata } from '$lib/types/changelogs'; import type { ChangelogImport } from '$lib/types/changelogs';
import { t } from '$lib/i18n/translations'; import { t } from '$lib/i18n/translations';
import { page } from '$app/stores';
import { getAllChangelogs } from '$lib/changelogs'; import { getAllChangelogs } from '$lib/changelogs';
const changelogs = getAllChangelogs(); const changelogs = getAllChangelogs();
@ -9,6 +10,13 @@
let changelog: ChangelogImport & { version: string } | undefined; let changelog: ChangelogImport & { version: string } | undefined;
let currentIndex = -1; let currentIndex = -1;
{
const hash = $page.url.hash.replace("#", "");
const versionIndex = versions.indexOf(hash);
if (versionIndex !== -1 && currentIndex !== versionIndex) {
currentIndex = versionIndex;
}
}
const loadChangelog = async () => { const loadChangelog = async () => {
const version = versions[currentIndex]; const version = versions[currentIndex];
@ -21,6 +29,8 @@
...log, ...log,
version version
}; };
window.location.hash = version;
} }
const nextChangelog = async () => { const nextChangelog = async () => {