Refactor style handling and add head management for overview route

This commit is contained in:
2026-01-05 01:15:01 +07:00
parent 22af8c4f2b
commit 2297cb3b69
2 changed files with 12 additions and 1 deletions

View File

@@ -39,7 +39,7 @@ app.get("*", async (c) => {
await auth.init(); await auth.init();
await router.push(url.pathname); await router.push(url.pathname);
await router.isReady(); await router.isReady();
let usedStyles = new Set(defaultNames); let usedStyles = new Set<String>();
Base.setLoadedStyleName = async (name: string) => usedStyles.add(name) Base.setLoadedStyleName = async (name: string) => usedStyles.add(name)
return streamText(c, async (stream) => { return streamText(c, async (stream) => {
c.header("Content-Type", "text/html; charset=utf-8"); c.header("Content-Type", "text/html; charset=utf-8");
@@ -53,6 +53,9 @@ app.get("*", async (c) => {
await stream.write(`<link href="https://fonts.googleapis.com/css2?family=Be+Vietnam+Pro:ital,wght@0,100;0,200;0,300;0,400;0,500;0,600;0,700;0,800;0,900;1,100;1,200;1,300;1,400;1,500;1,600;1,700;1,800;1,900&display=swap"rel="stylesheet"></link>`); await stream.write(`<link href="https://fonts.googleapis.com/css2?family=Be+Vietnam+Pro:ital,wght@0,100;0,200;0,300;0,400;0,500;0,600;0,700;0,800;0,900;1,100;1,200;1,300;1,400;1,500;1,600;1,700;1,800;1,900&display=swap"rel="stylesheet"></link>`);
await stream.write('<link rel="icon" href="/favicon.ico" />'); await stream.write('<link rel="icon" href="/favicon.ico" />');
await stream.write(buildBootstrapScript()); await stream.write(buildBootstrapScript());
if (usedStyles.size > 0) {
defaultNames.forEach(name => usedStyles.add(name));
}
await Promise.all(styleTags.filter(tag => usedStyles.has(tag.name.replace(/-(variables|style)$/, ""))).map(tag => stream.write(`<style type="text/css" data-primevue-style-id="${tag.name}">${tag.value}</style>`))); await Promise.all(styleTags.filter(tag => usedStyles.has(tag.name.replace(/-(variables|style)$/, ""))).map(tag => stream.write(`<style type="text/css" data-primevue-style-id="${tag.name}">${tag.value}</style>`)));
await stream.write(`</head><body class='${bodyClass}'>`); await stream.write(`</head><body class='${bodyClass}'>`);
await stream.pipe(appStream); await stream.pipe(appStream);

View File

@@ -1,4 +1,5 @@
import { type ReactiveHead, type ResolvableValue } from "@unhead/vue"; import { type ReactiveHead, type ResolvableValue } from "@unhead/vue";
import { headSymbol } from '@unhead/vue'
import { import {
createMemoryHistory, createMemoryHistory,
createRouter, createRouter,
@@ -58,6 +59,13 @@ const routes: RouteData[] = [
path: "", path: "",
name: "overview", name: "overview",
component: () => import("./add/Add.vue"), component: () => import("./add/Add.vue"),
beforeEnter: (to, from, next) => {
const head = inject(headSymbol);
(head as any).push({
title: 'Overview - Holistream',
});
next();
}
}, },
{ {
path: "video", path: "video",