From 1b32ecff1a23c0bbc2da45f95ac3fd4930f4d7d3 Mon Sep 17 00:00:00 2001 From: Shigma Date: Fri, 5 Jan 2024 02:50:47 +0800 Subject: [PATCH] feat(console): support override title via config.head --- packages/client/client/index.ts | 5 ++++- packages/online/app/index.ts | 1 - plugins/console/src/node/index.ts | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/packages/client/client/index.ts b/packages/client/client/index.ts index 80ead48d..d0855575 100644 --- a/packages/client/client/index.ts +++ b/packages/client/client/index.ts @@ -50,11 +50,14 @@ export const router = createRouter({ routes: [], }) +const initialTitle = document.title + router.afterEach((route) => { const { name, fullPath } = router.currentRoute.value routeCache[name] = fullPath if (route.meta.activity) { - document.title = `${route.meta.activity.name} | ${global.messages?.title || 'Koishi 控制台'}` + document.title = `${route.meta.activity.name}` + if (initialTitle) document.title += ` | ${initialTitle}` } }) diff --git a/packages/online/app/index.ts b/packages/online/app/index.ts index cdf5fbaf..8df25822 100644 --- a/packages/online/app/index.ts +++ b/packages/online/app/index.ts @@ -32,7 +32,6 @@ root.page({ }) global.messages = {} -global.messages.title = 'Koishi Online' global.messages.connecting = '正在初始化 Koishi Online 运行环境……' if (!('chrome' in window)) { diff --git a/plugins/console/src/node/index.ts b/plugins/console/src/node/index.ts index 9bf61a81..73d2847a 100644 --- a/plugins/console/src/node/index.ts +++ b/plugins/console/src/node/index.ts @@ -164,7 +164,7 @@ class NodeConsole extends Console { const attrString = Object.entries(attrs).map(([key, value]) => ` ${key}="${h.escape(value ?? '', true)}"`).join('') headInjection += `<${tag}${attrString}>${content ?? ''}` } - return template.replace('', '' + headInjection) + return template.replace('', headInjection + '<title>') } private async createVite() {