feat(cli): support switch site version

This commit is contained in:
陈嘉涵 2019-12-11 11:50:07 +08:00
parent a78fc55079
commit 0a45afad42
4 changed files with 25 additions and 4 deletions

View File

@ -3,6 +3,7 @@
<van-doc <van-doc
:lang="lang" :lang="lang"
:config="config" :config="config"
:versions="versions"
:simulator="simulator" :simulator="simulator"
:lang-configs="langConfigs" :lang-configs="langConfigs"
> >
@ -13,7 +14,7 @@
<script> <script>
import VanDoc from './components'; import VanDoc from './components';
import { config } from 'site-desktop-shared'; import { config, packageVersion } from 'site-desktop-shared';
import { setLang } from '../common/locales'; import { setLang } from '../common/locales';
function getPublicPath() { function getPublicPath() {
@ -33,6 +34,7 @@ export default {
data() { data() {
return { return {
packageVersion,
simulator: `${getPublicPath()}mobile.html${location.hash}` simulator: `${getPublicPath()}mobile.html${location.hash}`
}; };
}, },
@ -59,6 +61,14 @@ export default {
} }
return config.site; return config.site;
},
versions() {
if (config.site.versions) {
return [{ label: packageVersion }, ...config.site.versions];
}
return null;
} }
}, },

View File

@ -18,14 +18,16 @@
<li ref="version" v-if="versions" class="van-doc-header__top-nav-item"> <li ref="version" v-if="versions" class="van-doc-header__top-nav-item">
<span class="van-doc-header__cube van-doc-header__version" @click="toggleVersionPop"> <span class="van-doc-header__cube van-doc-header__version" @click="toggleVersionPop">
{{ versions[0] }} {{ versions[0].label }}
<transition name="van-doc-dropdown"> <transition name="van-doc-dropdown">
<div v-if="showVersionPop" class="van-doc-header__version-pop"> <div v-if="showVersionPop" class="van-doc-header__version-pop">
<div <div
v-for="item in versions" v-for="item in versions"
class="van-doc-header__version-pop-item" class="van-doc-header__version-pop-item"
@click="onSwitchVersion(item)" @click="onSwitchVersion(item)"
>{{ item }}</div> >
{{ item.label }}
</div>
</div> </div>
</transition> </transition>
</span> </span>
@ -107,7 +109,7 @@ export default {
}, },
onSwitchVersion(version) { onSwitchVersion(version) {
this.$emit('switch-version', version); location.href = version.link;
} }
} }
}; };

View File

@ -10,6 +10,7 @@ import {
import { import {
SRC_DIR, SRC_DIR,
DOCS_DIR, DOCS_DIR,
PACKAGE_JSON,
VANT_CONFIG_FILE, VANT_CONFIG_FILE,
SITE_DESKTOP_SHARED_FILE SITE_DESKTOP_SHARED_FILE
} from '../common/constant'; } from '../common/constant';
@ -94,6 +95,10 @@ function genExportConfig() {
return 'export { config };'; return 'export { config };';
} }
function genExportVersion() {
return `export const packageVersion = '${PACKAGE_JSON.version}';`;
}
export function genSiteDesktopShared() { export function genSiteDesktopShared() {
const dirs = readdirSync(SRC_DIR); const dirs = readdirSync(SRC_DIR);
const documents = resolveDocuments(dirs); const documents = resolveDocuments(dirs);
@ -103,6 +108,7 @@ ${genImportDocuments(documents)}
${genExportConfig()} ${genExportConfig()}
${genExportDocuments(documents)} ${genExportDocuments(documents)}
${genExportVersion()}
`; `;
smartOutputFile(SITE_DESKTOP_SHARED_FILE, code); smartOutputFile(SITE_DESKTOP_SHARED_FILE, code);

View File

@ -7,6 +7,9 @@ module.exports = {
}, },
site: { site: {
defaultLang: 'en-US', defaultLang: 'en-US',
versions: [
{ label: '1.x', link: 'https://youzan.github.io/vant/1.x/' }
],
locales: { locales: {
'zh-CN': { 'zh-CN': {
title: 'Vant', title: 'Vant',