fix: ensure both href theme updates result in the same url
This commit is contained in:
parent
73606b6bc3
commit
2ce09e7c7a
1 changed files with 10 additions and 5 deletions
|
@ -1,23 +1,28 @@
|
||||||
let themeLinkElement: HTMLLinkElement | null;
|
let themeLinkElement: HTMLLinkElement | null;
|
||||||
|
|
||||||
export default function loadPreferredTheme() {
|
export default function loadPreferredTheme() {
|
||||||
const runtimeConfig = useRuntimeConfig()
|
|
||||||
const baseURL = runtimeConfig.app.baseURL;
|
|
||||||
const currentTheme = settingsLoad().selectedThemeId ?? "dark"
|
const currentTheme = settingsLoad().selectedThemeId ?? "dark"
|
||||||
|
|
||||||
if (themeLinkElement) {
|
if (themeLinkElement) {
|
||||||
themeLinkElement.href = `${baseURL}themes/${currentTheme}.css`;
|
themeLinkElement.href = getThemeUrl(currentTheme);
|
||||||
} else {
|
} else {
|
||||||
// create the theme link if one doesn't already exist
|
// create the theme link if one doesn't already exist
|
||||||
useHead({
|
useHead({
|
||||||
link: [{
|
link: [{
|
||||||
id: "main-theme",
|
id: "main-theme",
|
||||||
rel: "stylesheet",
|
rel: "stylesheet",
|
||||||
// this should preferrably use version hash, but that's not implemented yet
|
href: getThemeUrl(currentTheme)
|
||||||
href: `${baseURL}themes/${currentTheme}.css?v=${runtimeConfig.public.buildTimeString}`
|
|
||||||
}]
|
}]
|
||||||
})
|
})
|
||||||
|
|
||||||
themeLinkElement = document.getElementById('main-theme') as HTMLLinkElement;
|
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}`
|
||||||
}
|
}
|
Loading…
Add table
Add a link
Reference in a new issue