From c111330baf078198f6fec2f09e89c4ad95fcb861 Mon Sep 17 00:00:00 2001 From: wangxueliang Date: Mon, 4 Jun 2018 14:58:02 +0800 Subject: [PATCH] fix: add document title --- .../upload/__tests__/uploadlist.test.js | 1 - site/components/layout.vue | 39 ++++++++++++++----- 2 files changed, 29 insertions(+), 11 deletions(-) diff --git a/components/upload/__tests__/uploadlist.test.js b/components/upload/__tests__/uploadlist.test.js index cb87cdc03..493db48c0 100644 --- a/components/upload/__tests__/uploadlist.test.js +++ b/components/upload/__tests__/uploadlist.test.js @@ -1,7 +1,6 @@ import { mount } from '@vue/test-utils' import Vue from 'vue' import Upload from '..' -import Form from '../../form' import { errorRequest, successRequest } from './requests' import PropsTypes from '../../_util/vue-types' import { UploadListProps } from '../interface' diff --git a/site/components/layout.vue b/site/components/layout.vue index edae777eb..ee635298f 100644 --- a/site/components/layout.vue +++ b/site/components/layout.vue @@ -7,6 +7,15 @@ import _ from 'lodash' import { isZhCN } from '../util' import { Provider, create } from '../../components/_util/store' +const docsList = [ + { key: 'introduce', enTitle: 'Ant Design of Vue', title: 'Ant Design of Vue' }, + { key: 'getting-started', enTitle: 'Getting Started', title: '快速上手' }, + { key: 'use-with-vue-cli', enTitle: 'Use in vue-cli', title: '在 vue-cli 中使用' }, + { key: 'customize-theme', enTitle: 'Customize Theme', title: '定制主题' }, + { key: 'changelog', enTitle: 'Change Log', title: '更新日志' }, + { key: 'i18n', enTitle: 'Internationalization', title: '国际化' }, +] + export default { props: { name: String, @@ -82,16 +91,8 @@ export default { ) }, getDocsMenu (isCN) { - const docs = [ - { key: 'introduce', enTitle: 'Ant Design of Vue', title: 'Ant Design of Vue' }, - { key: 'getting-started', enTitle: 'Getting Started', title: '快速上手' }, - { key: 'use-with-vue-cli', enTitle: 'Use in vue-cli', title: '在 vue-cli 中使用' }, - { key: 'customize-theme', enTitle: 'Customize Theme', title: '定制主题' }, - { key: 'changelog', enTitle: 'Change Log', title: '更新日志' }, - { key: 'i18n', enTitle: 'Internationalization', title: '国际化' }, - ] const docsMenu = [] - docs.forEach(({ key, enTitle, title }) => { + docsList.forEach(({ key, enTitle, title }) => { const k = isCN ? `${key}-cn` : key docsMenu.push( {isCN ? title : enTitle } @@ -99,6 +100,22 @@ export default { }) return docsMenu }, + resetDocumentTitle (component, name, isCN) { + let titleStr = 'Vue Antd' + if (component) { + const { subtitle, title } = component + const componentName = isCN ? subtitle + ' ' + title : title + titleStr = componentName + ' - ' + titleStr + } else { + const currentKey = docsList.filter((item) => { + return item.key === name + }) + if (currentKey.length) { + titleStr = (isCN ? currentKey[0]['title'] : currentKey[0]['enTitle']) + ' - ' + titleStr + } + } + document.title = titleStr + }, }, render () { const name = this.name @@ -122,7 +139,8 @@ export default { menuConfig[type] = menuConfig[type] || [] menuConfig[type].push(d) } - const Demo = AllDemo[titleMap[name.replace(/-cn\/?$/, '')]] + const reName = name.replace(/-cn\/?$/, '') + const Demo = AllDemo[titleMap[reName]] const MenuGroup = [] for (const [type, menus] of Object.entries(menuConfig)) { const MenuItems = [] @@ -149,6 +167,7 @@ export default { if (!isCN) { locale = enUS } + this.resetDocumentTitle(Demo, reName, isCN) return (