fix(admin): add favicon and page-aware titles
This commit is contained in:
@@ -1,10 +1,15 @@
|
||||
<script setup lang="ts">
|
||||
import { computed } from 'vue'
|
||||
import { computed, watchEffect } from 'vue'
|
||||
import { RouterView, useRoute } from 'vue-router'
|
||||
import { documentTitleForRoute } from './app/pageTitle'
|
||||
import AppShell from './components/shell/AppShell.vue'
|
||||
|
||||
const route = useRoute()
|
||||
const inShell = computed(() => route.meta.shell === true)
|
||||
|
||||
watchEffect(() => {
|
||||
document.title = documentTitleForRoute(route)
|
||||
})
|
||||
</script>
|
||||
|
||||
<template>
|
||||
|
||||
42
admin/src/app/pageTitle.ts
Normal file
42
admin/src/app/pageTitle.ts
Normal file
@@ -0,0 +1,42 @@
|
||||
import type { RouteLocationNormalizedLoaded } from 'vue-router'
|
||||
import { controllerIdFromPath } from './controllerRoutes'
|
||||
import { t } from './i18n'
|
||||
import { recordCrumb } from '../state/useBreadcrumbs'
|
||||
import { activeEntry } from '../state/useNavigation'
|
||||
import { settingsEntry } from '../state/useSettings'
|
||||
|
||||
const PRODUCT_TITLE = 'SummerCMS'
|
||||
|
||||
/** The visible page indicator used before the SummerCMS product name. */
|
||||
export function pageIndicator(route: RouteLocationNormalizedLoaded): string {
|
||||
if (route.name === 'login') {
|
||||
return t('backend::lang.auth.title')
|
||||
}
|
||||
if (route.name === 'settings') {
|
||||
return t('backend::lang.settings.title')
|
||||
}
|
||||
if (route.name === 'settings-form') {
|
||||
return settingsEntry(String(route.params.code ?? ''))?.label ?? String(route.params.code ?? '')
|
||||
}
|
||||
if (route.name === 'home') {
|
||||
return t('backend::lang.nav.empty')
|
||||
}
|
||||
if (route.name === 'not-found') {
|
||||
return t('backend::lang.page.not_found')
|
||||
}
|
||||
|
||||
const plugin = activeEntry(String(route.params.vendor ?? ''), String(route.params.plugin ?? ''))
|
||||
const controller = controllerIdFromPath(route.path)
|
||||
const section = plugin?.sideMenu.find((item) => item.controller === controller)
|
||||
const controllerLabel = section?.label ?? plugin?.label ?? ''
|
||||
if (route.name === 'create' || route.name === 'record' || route.name === 'preview') {
|
||||
return recordCrumb.value || controllerLabel
|
||||
}
|
||||
return controllerLabel
|
||||
}
|
||||
|
||||
/** Browser title matching WinterCMS's "Current page | Product" pattern. */
|
||||
export function documentTitleForRoute(route: RouteLocationNormalizedLoaded): string {
|
||||
const indicator = pageIndicator(route).trim()
|
||||
return indicator === '' ? PRODUCT_TITLE : `${indicator} | ${PRODUCT_TITLE}`
|
||||
}
|
||||
Reference in New Issue
Block a user