mirror of
https://github.com/tusen-ai/naive-ui.git
synced 2025-03-31 14:20:53 +08:00
docs(site): add distinct title for each documentation page (#1002)
* site: add distinct title for each documentation page * perf: restore the script in HTML to load the first title faster * refactor: remove duplicated codes * fix: set document.title only once to prevent flicking * fix: shorten the title
This commit is contained in:
parent
0e0191535d
commit
6cccf66461
@ -1,5 +1,6 @@
|
||||
import { nextTick } from 'vue'
|
||||
import { createRouter, createWebHistory } from 'vue-router'
|
||||
import { useLocaleName } from '../store'
|
||||
|
||||
export const loadingBarApiRef = {}
|
||||
|
||||
@ -29,6 +30,15 @@ export default function createDemoRouter (app, routes) {
|
||||
if (el) el.scrollIntoView()
|
||||
})
|
||||
}
|
||||
nextTick(() => {
|
||||
const h1s = document.getElementsByTagName('h1')
|
||||
if (to.name !== 'home' && h1s.length !== 0) {
|
||||
document.title = h1s[0].textContent + ' - Naive UI'
|
||||
} else {
|
||||
// defined in index.html
|
||||
window.deriveTitleFromLocale(useLocaleName().value)
|
||||
}
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { computed, ref, watch } from 'vue'
|
||||
import { computed, ref } from 'vue'
|
||||
import { useMemo } from 'vooks'
|
||||
import {
|
||||
NConfigProvider,
|
||||
@ -31,10 +31,6 @@ export function initRouter (_router, _route) {
|
||||
router.push(changeLangInPath(route.fullPath, locale))
|
||||
}
|
||||
})
|
||||
watch(localeNameRef, (value) => {
|
||||
// defined in index.html
|
||||
window.deriveTitleFromLocale(value)
|
||||
})
|
||||
dateLocaleRef = useMemo(() => {
|
||||
return route.path.startsWith('/zh-CN') ? dateZhCN : dateEnUS
|
||||
})
|
||||
|
Loading…
x
Reference in New Issue
Block a user