fix: ensure both href theme updates result in the same url
All checks were successful
ci/woodpecker/push/build-and-publish Pipeline was successful
ci/woodpecker/pr/build-and-publish Pipeline was successful

This commit is contained in:
Twig 2025-07-16 05:37:44 +02:00
parent 73606b6bc3
commit 2ce09e7c7a
No known key found for this signature in database

View file

@ -1,23 +1,28 @@
let themeLinkElement: HTMLLinkElement | null;
export default function loadPreferredTheme() {
const runtimeConfig = useRuntimeConfig()
const baseURL = runtimeConfig.app.baseURL;
const currentTheme = settingsLoad().selectedThemeId ?? "dark"
if (themeLinkElement) {
themeLinkElement.href = `${baseURL}themes/${currentTheme}.css`;
themeLinkElement.href = getThemeUrl(currentTheme);
} else {
// create the theme link if one doesn't already exist
useHead({
link: [{
id: "main-theme",
rel: "stylesheet",
// this should preferrably use version hash, but that's not implemented yet
href: `${baseURL}themes/${currentTheme}.css?v=${runtimeConfig.public.buildTimeString}`
href: getThemeUrl(currentTheme)
}]
})
themeLinkElement = document.getElementById('main-theme') as HTMLLinkElement;
}
}
function getThemeUrl(id: string): string {
const runtimeConfig = useRuntimeConfig()
const baseURL = runtimeConfig.app.baseURL;
// this should preferrably use version hash, but that's not implemented yet
return `${baseURL}themes/${id}.css?v=${runtimeConfig.public.buildTimeString}`
}