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:
Yufan You 2021-08-30 23:40:17 +08:00 committed by GitHub
parent 0e0191535d
commit 6cccf66461
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 5 deletions

View File

@ -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)
}
})
}
})

View File

@ -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
})