From 64ec6ce5ac8e7809a32fa69faee0b520ab564bd5 Mon Sep 17 00:00:00 2001 From: Yao Date: Fri, 6 Oct 2017 12:33:28 +0800 Subject: [PATCH] Docs: add English language support (#170) * feat: support lang entry build * feat: vant support lang switch * move lang iframe-router to utils & fix router link bug * add en-US config && add some translation * chang async. to async_ (support superman cdn) * add layout translation * change nav style * upgrade zan-doc * fix: doc config * upgrade zan-doc && remove useless code * fix changelog generate path --- build/build-changelog.sh | 2 +- build/webpack.config.dev.js | 4 +- build/webpack.config.prod.js | 2 +- docs/examples-docs/en-US/changelog.md | 28 ++++ docs/examples-docs/en-US/layout.md | 90 +++++++++++ docs/examples-docs/en-US/quickstart.md | 49 ++++++ docs/examples-docs/{ => zh-CN}/actionsheet.md | 0 .../examples-docs/{ => zh-CN}/address-edit.md | 2 +- .../examples-docs/{ => zh-CN}/address-list.md | 0 docs/examples-docs/{ => zh-CN}/area.md | 4 +- docs/examples-docs/{ => zh-CN}/badge.md | 0 docs/examples-docs/{ => zh-CN}/button.md | 0 docs/examples-docs/{ => zh-CN}/card.md | 0 docs/examples-docs/{ => zh-CN}/cell-swipe.md | 0 docs/examples-docs/{ => zh-CN}/cell.md | 0 .../{ => zh-CN}/changelog-generated.md | 0 docs/examples-docs/{ => zh-CN}/changelog.md | 0 docs/examples-docs/{ => zh-CN}/checkbox.md | 0 docs/examples-docs/{ => zh-CN}/contact.md | 0 docs/examples-docs/{ => zh-CN}/coupon.md | 0 .../{ => zh-CN}/datetime-picker.md | 0 docs/examples-docs/{ => zh-CN}/dialog.md | 0 docs/examples-docs/{ => zh-CN}/field.md | 0 .../examples-docs/{ => zh-CN}/goods-action.md | 0 docs/examples-docs/{ => zh-CN}/icon.md | 0 .../{ => zh-CN}/image-preview.md | 0 docs/examples-docs/{ => zh-CN}/layout.md | 0 docs/examples-docs/{ => zh-CN}/lazyload.md | 0 docs/examples-docs/{ => zh-CN}/loading.md | 0 docs/examples-docs/{ => zh-CN}/nav-bar.md | 0 docs/examples-docs/{ => zh-CN}/notice-bar.md | 0 .../{ => zh-CN}/number-keyboard.md | 0 docs/examples-docs/{ => zh-CN}/panel.md | 0 .../{ => zh-CN}/password-input.md | 0 docs/examples-docs/{ => zh-CN}/picker.md | 0 docs/examples-docs/{ => zh-CN}/popup.md | 0 docs/examples-docs/{ => zh-CN}/progress.md | 0 .../examples-docs/{ => zh-CN}/pull-refresh.md | 0 docs/examples-docs/{ => zh-CN}/quickstart.md | 0 docs/examples-docs/{ => zh-CN}/radio.md | 0 docs/examples-docs/{ => zh-CN}/search.md | 0 docs/examples-docs/{ => zh-CN}/sku.md | 2 +- docs/examples-docs/{ => zh-CN}/stepper.md | 0 docs/examples-docs/{ => zh-CN}/steps.md | 0 docs/examples-docs/{ => zh-CN}/submit-bar.md | 0 docs/examples-docs/{ => zh-CN}/swipe.md | 0 docs/examples-docs/{ => zh-CN}/switch-cell.md | 0 docs/examples-docs/{ => zh-CN}/switch.md | 0 docs/examples-docs/{ => zh-CN}/tab.md | 0 docs/examples-docs/{ => zh-CN}/tag.md | 0 docs/examples-docs/{ => zh-CN}/toast.md | 0 docs/examples-docs/{ => zh-CN}/tree-select.md | 0 docs/examples-docs/{ => zh-CN}/uploader.md | 0 docs/examples-docs/{ => zh-CN}/waterfall.md | 0 docs/src/ExamplesApp.vue | 2 +- docs/src/ExamplesDocsApp.vue | 32 ++-- docs/src/components/demo-list.vue | 25 ++- docs/src/components/mobile-nav.vue | 2 +- docs/src/doc.config.js | 147 ++++++++++++------ docs/src/examples.js | 10 +- docs/src/index.js | 8 +- docs/src/router.config.js | 76 +++++---- docs/src/{ => utils}/iframe-router.js | 30 ++-- docs/src/utils/iframe.js | 18 +++ docs/src/{ => utils}/is-mobile.js | 0 docs/src/utils/lang.js | 16 ++ package.json | 4 +- yarn.lock | 21 ++- 68 files changed, 439 insertions(+), 135 deletions(-) create mode 100644 docs/examples-docs/en-US/changelog.md create mode 100644 docs/examples-docs/en-US/layout.md create mode 100644 docs/examples-docs/en-US/quickstart.md rename docs/examples-docs/{ => zh-CN}/actionsheet.md (100%) rename docs/examples-docs/{ => zh-CN}/address-edit.md (98%) rename docs/examples-docs/{ => zh-CN}/address-list.md (100%) rename docs/examples-docs/{ => zh-CN}/area.md (97%) rename docs/examples-docs/{ => zh-CN}/badge.md (100%) rename docs/examples-docs/{ => zh-CN}/button.md (100%) rename docs/examples-docs/{ => zh-CN}/card.md (100%) rename docs/examples-docs/{ => zh-CN}/cell-swipe.md (100%) rename docs/examples-docs/{ => zh-CN}/cell.md (100%) rename docs/examples-docs/{ => zh-CN}/changelog-generated.md (100%) rename docs/examples-docs/{ => zh-CN}/changelog.md (100%) rename docs/examples-docs/{ => zh-CN}/checkbox.md (100%) rename docs/examples-docs/{ => zh-CN}/contact.md (100%) rename docs/examples-docs/{ => zh-CN}/coupon.md (100%) rename docs/examples-docs/{ => zh-CN}/datetime-picker.md (100%) rename docs/examples-docs/{ => zh-CN}/dialog.md (100%) rename docs/examples-docs/{ => zh-CN}/field.md (100%) rename docs/examples-docs/{ => zh-CN}/goods-action.md (100%) rename docs/examples-docs/{ => zh-CN}/icon.md (100%) rename docs/examples-docs/{ => zh-CN}/image-preview.md (100%) rename docs/examples-docs/{ => zh-CN}/layout.md (100%) rename docs/examples-docs/{ => zh-CN}/lazyload.md (100%) rename docs/examples-docs/{ => zh-CN}/loading.md (100%) rename docs/examples-docs/{ => zh-CN}/nav-bar.md (100%) rename docs/examples-docs/{ => zh-CN}/notice-bar.md (100%) rename docs/examples-docs/{ => zh-CN}/number-keyboard.md (100%) rename docs/examples-docs/{ => zh-CN}/panel.md (100%) rename docs/examples-docs/{ => zh-CN}/password-input.md (100%) rename docs/examples-docs/{ => zh-CN}/picker.md (100%) rename docs/examples-docs/{ => zh-CN}/popup.md (100%) rename docs/examples-docs/{ => zh-CN}/progress.md (100%) rename docs/examples-docs/{ => zh-CN}/pull-refresh.md (100%) rename docs/examples-docs/{ => zh-CN}/quickstart.md (100%) rename docs/examples-docs/{ => zh-CN}/radio.md (100%) rename docs/examples-docs/{ => zh-CN}/search.md (100%) rename docs/examples-docs/{ => zh-CN}/sku.md (99%) rename docs/examples-docs/{ => zh-CN}/stepper.md (100%) rename docs/examples-docs/{ => zh-CN}/steps.md (100%) rename docs/examples-docs/{ => zh-CN}/submit-bar.md (100%) rename docs/examples-docs/{ => zh-CN}/swipe.md (100%) rename docs/examples-docs/{ => zh-CN}/switch-cell.md (100%) rename docs/examples-docs/{ => zh-CN}/switch.md (100%) rename docs/examples-docs/{ => zh-CN}/tab.md (100%) rename docs/examples-docs/{ => zh-CN}/tag.md (100%) rename docs/examples-docs/{ => zh-CN}/toast.md (100%) rename docs/examples-docs/{ => zh-CN}/tree-select.md (100%) rename docs/examples-docs/{ => zh-CN}/uploader.md (100%) rename docs/examples-docs/{ => zh-CN}/waterfall.md (100%) rename docs/src/{ => utils}/iframe-router.js (54%) create mode 100644 docs/src/utils/iframe.js rename docs/src/{ => utils}/is-mobile.js (100%) create mode 100644 docs/src/utils/lang.js diff --git a/build/build-changelog.sh b/build/build-changelog.sh index 57b57c9df..0edf423b6 100644 --- a/build/build-changelog.sh +++ b/build/build-changelog.sh @@ -17,4 +17,4 @@ github_changelog_generator \ --issues-label "**处理的 Issue:**" \ --pr-label "**合并的 Pull Request (可能有不兼容改动):**" \ --no-unreleased \ - -o $basepath/../docs/examples-docs/changelog-generated.md + -o $basepath/../docs/examples-docs/zh-CN/changelog-generated.md diff --git a/build/webpack.config.dev.js b/build/webpack.config.dev.js index 2a1b95031..71d194e41 100644 --- a/build/webpack.config.dev.js +++ b/build/webpack.config.dev.js @@ -16,7 +16,7 @@ const styleLoaders = [ extractExample({ src: path.resolve(__dirname, '../docs/examples-docs'), dist: path.resolve(__dirname, '../docs/examples-dist'), - nav: docConfig['zh-CN'].nav, + nav: docConfig, watch: !isProduction }); @@ -31,7 +31,7 @@ module.exports = { publicPath: '/', filename: '[name].js', umdNamedDefine: true, - chunkFilename: 'async.[name].js' + chunkFilename: 'async_[name].js' }, devServer: { host: '0.0.0.0', diff --git a/build/webpack.config.prod.js b/build/webpack.config.prod.js index e7ca527d9..669f10f37 100644 --- a/build/webpack.config.prod.js +++ b/build/webpack.config.prod.js @@ -9,7 +9,7 @@ module.exports = merge(devConfig, { publicPath: 'https://b.yzcdn.cn/zanui/vue/', filename: '[name].[hash:8].js', umdNamedDefine: true, - chunkFilename: 'async.[name].[chunkhash:8].js' + chunkFilename: 'async_[name].[chunkhash:8].js' }, devtool: false, plugins: [ diff --git a/docs/examples-docs/en-US/changelog.md b/docs/examples-docs/en-US/changelog.md new file mode 100644 index 000000000..7f5873963 --- /dev/null +++ b/docs/examples-docs/en-US/changelog.md @@ -0,0 +1,28 @@ +## Changelog + +### [0.9.9](https://github.com/youzan/vant/tree/v0.9.9) +`2017-09-26` + +**Improvements** +- Sku:support Stepper [\#146](https://github.com/youzan/vant/pull/146) [@w91](https://github.com/w91) + +**Bug Fixes** +- fix license error in packages.json [\#144](https://github.com/youzan/vant/pull/144) [@airyland](https://github.com/airyland) +- fix Waterfall scroll bug [\#145](https://github.com/youzan/vant/pull/145) [@pangxie1991](https://github.com/pangxie1991) + + +### [0.9.8](https://github.com/youzan/vant/tree/v0.9.8) +`2017-09-24` + +**Improvements** +- add AddressList component [\#138](https://github.com/youzan/vant/pull/138) [@chenjiahan](https://github.com/chenjiahan) +- modify changelog [\#140](https://github.com/youzan/vant/pull/140) [@chenjiahan](https://github.com/chenjiahan) + +**Bug Fixes** +- fix Sku message render bug [\#142](https://github.com/youzan/vant/pull/142) [@w91](https://github.com/w91) + +### [0.9.7](https://github.com/youzan/vant/tree/v0.9.7) +`2017-09-21` + +**Improvements** +- Checkbox: support shape prop [\#137](https://github.com/youzan/vant/pull/137) [@chenjiahan](https://github.com/chenjiahan) diff --git a/docs/examples-docs/en-US/layout.md b/docs/examples-docs/en-US/layout.md new file mode 100644 index 000000000..a73beec62 --- /dev/null +++ b/docs/examples-docs/en-US/layout.md @@ -0,0 +1,90 @@ + + +## Layout + +Quickly and easily create layouts with `van-row` and `van-col` + +### Install +``` javascript +import { Row, Col } from 'vant'; + +Vue.component(Row.name, Row); +Vue.component(Col.name, Col); +``` + +### Usage + +#### Basic + +Layout are based on 24-column. The attribute `span` in `Col` means the number of column the grid spans. Of course, You can use `offset` attribute to set number of spacing on the left side of the grid. + +:::demo Basic Usage +```html + + span: 8 + span: 8 + span: 8 + + + + span: 4 + offset: 4, span: 10 + span: 6 + + + + offset: 12, span: 12 + +``` +::: + +#### Column Spacing + +Set grid spacing using `gutter` attribute. The default value is 0 + +:::demo Column Spacing +```html + + span: 8 + span: 8 + span: 8 + +``` +::: + +### API + +#### Row +| Attribute | Description | Type | Default | Accepted Values | +|-----------|-----------|-----------|-------------|-------------| +| gutter | grid spacing(px) | `String | Number` | - | - | +| prefix | className prefix | `String` | `van` | - | + +#### Column +| Attribute | Description | Type | Default | Accepted Values | +|-----------|-----------|-----------|-------------|-------------| +| span | number of column the grid spans | `String | Number` | - | - | +| offset | number of spacing on the left side of the grid | `String | Number` | - | - | +| prefix | className prefix | `String` | `van` | - | diff --git a/docs/examples-docs/en-US/quickstart.md b/docs/examples-docs/en-US/quickstart.md new file mode 100644 index 000000000..682478802 --- /dev/null +++ b/docs/examples-docs/en-US/quickstart.md @@ -0,0 +1,49 @@ +## Vant + +Mobile UI Component based on `Vue 2.0` + +### Install + +```shell +npm i vant -S +``` + +### Usage + +#### 1. Use [babel-plugin-import](https://github.com/ant-design/babel-plugin-import) (推荐) +```bash +# Install babel-plugin-import +npm i babel-plugin-import -D +``` + +```js +// set babel config in .babelrc or babel-loader +{ + "plugins": [ + ["import", { "libraryName": "vant", "style": true }] + ] +} +``` + +Then you can import components from vant, equivalent to import manually below. + +```js +import { Button } from 'vant'; +``` + +#### 2. Manually import + +```js +import { Button } from 'vant/lib/button'; +import 'vant/lib/vant-css/button.css'; +``` + +#### 3. Import all components + +```js +import Vue from 'vue'; +import Vant from 'vant'; +import 'vant/lib/vant-css/index.css'; + +Vue.use(Vant); +``` diff --git a/docs/examples-docs/actionsheet.md b/docs/examples-docs/zh-CN/actionsheet.md similarity index 100% rename from docs/examples-docs/actionsheet.md rename to docs/examples-docs/zh-CN/actionsheet.md diff --git a/docs/examples-docs/address-edit.md b/docs/examples-docs/zh-CN/address-edit.md similarity index 98% rename from docs/examples-docs/address-edit.md rename to docs/examples-docs/zh-CN/address-edit.md index 9e0ebf529..f039bec49 100644 --- a/docs/examples-docs/address-edit.md +++ b/docs/examples-docs/zh-CN/address-edit.md @@ -1,6 +1,6 @@ diff --git a/docs/src/components/mobile-nav.vue b/docs/src/components/mobile-nav.vue index c9b6e7de6..0df077fa1 100644 --- a/docs/src/components/mobile-nav.vue +++ b/docs/src/components/mobile-nav.vue @@ -17,7 +17,7 @@ v-if="!navItem.disabled"> + :to="'/' + base + navItem.path">

{{ navItem.title }}

diff --git a/docs/src/doc.config.js b/docs/src/doc.config.js index bce7e4213..27af62051 100644 --- a/docs/src/doc.config.js +++ b/docs/src/doc.config.js @@ -5,7 +5,8 @@ module.exports = { '首页': 'https://www.youzanyun.com/zanui', 'PC端': 'https://www.youzanyun.com/zanui/react', '移动端': 'https://www.youzanyun.com/zanui/vue', - '微信小程序': 'https://github.com/youzan/zanui-weapp' + '微信小程序': 'https://github.com/youzan/zanui-weapp', + 'English': '#/en-US/' }, footer: { github: 'https://github.com/youzan/vant', @@ -48,87 +49,87 @@ module.exports = { "list": [ { "path": "/layout", - "title": "Layout 布局" + "title": "Layout - 布局" }, { "path": "/badge", - "title": "Badge 徽章" + "title": "Badge - 徽章" }, { "path": "/button", - "title": "Button 按钮" + "title": "Button - 按钮" }, { "path": "/card", - "title": "Card 卡片" + "title": "Card - 卡片" }, { "path": "/cell", - "title": "Cell 单元格" + "title": "Cell - 单元格" }, { "path": "/icon", - "title": "Icon 图标" + "title": "Icon - 图标" }, { "path": "/image-preview", - "title": "ImagePreview 图片预览" + "title": "ImagePreview - 图片预览" }, { "path": "/lazyload", - "title": "Lazyload 图片懒加载" + "title": "Lazyload - 图片懒加载" }, { "path": "/loading", - "title": "Loading 加载" + "title": "Loading - 加载" }, { "path": "/nav-bar", - "title": "NavBar 导航栏" + "title": "NavBar - 导航栏" }, { "path": "/notice-bar", - "title": "NoticeBar 通告栏" + "title": "NoticeBar - 通告栏" }, { "path": "/panel", - "title": "Panel 面板" + "title": "Panel - 面板" }, { "path": "/popup", - "title": "Popup 弹出层" + "title": "Popup - 弹出层" }, { "path": "/progress", - "title": "Progress 进度条" + "title": "Progress - 进度条" }, { "path": "/search", - "title": "Search 搜索" + "title": "Search - 搜索" }, { "path": "/stepper", - "title": "Stepper 步进器" + "title": "Stepper - 步进器" }, { "path": "/steps", - "title": "Steps 步骤条" + "title": "Steps - 步骤条" }, { "path": "/swipe", - "title": "Swipe 轮播" + "title": "Swipe - 轮播" }, { "path": "/tab", - "title": "Tab 标签" + "title": "Tab - 标签" }, { "path": "/tag", - "title": "Tag 标记" + "title": "Tag - 标记" }, { "path": "/waterfall", - "title": "Waterfall 瀑布流" + "title": "Waterfall - 瀑布流" } ] }, @@ -137,31 +138,31 @@ module.exports = { "list": [ { "path": "/checkbox", - "title": "Checkbox 复选框" + "title": "Checkbox - 复选框" }, { "path": "/field", - "title": "Field 输入框" + "title": "Field - 输入框" }, { "path": "/number-keyboard", - "title": "NumberKeyboard 数字键盘" + "title": "NumberKeyboard - 数字键盘" }, { "path": "/password-input", - "title": "PasswordInput 密码输入框" + "title": "PasswordInput - 密码输入框" }, { "path": "/radio", - "title": "Radio 单选框" + "title": "Radio - 单选框" }, { "path": "/switch", - "title": "Switch 开关" + "title": "Switch - 开关" }, { "path": "/uploader", - "title": "Uploader 图片上传" + "title": "Uploader - 图片上传" } ] }, @@ -170,27 +171,27 @@ module.exports = { "list": [ { "path": "/actionsheet", - "title": "Actionsheet 行动按钮" + "title": "Actionsheet - 行动按钮" }, { "path": "/datetime-picker", - "title": "DatetimePicker 时间选择" + "title": "DatetimePicker - 时间选择" }, { "path": "/dialog", - "title": "Dialog 弹出框" + "title": "Dialog - 弹出框" }, { "path": "/picker", - "title": "Picker 选择器" + "title": "Picker - 选择器" }, { "path": "/pull-refresh", - "title": "PullRefresh 下拉刷新" + "title": "PullRefresh - 下拉刷新" }, { "path": "/toast", - "title": "Toast 轻提示" + "title": "Toast - 轻提示" } ] }, @@ -199,15 +200,15 @@ module.exports = { "list": [ { "path": "/cell-swipe", - "title": "CellSwipe 滑动单元格" + "title": "CellSwipe - 滑动单元格" }, { "path": "/switch-cell", - "title": "SwitchCell 开关单元格" + "title": "SwitchCell - 开关单元格" }, { "path": "/tree-select", - "title": "TreeSelect 分类选择" + "title": "TreeSelect - 分类选择" }, ] }, @@ -216,40 +217,94 @@ module.exports = { "list": [ { "path": "/address-edit", - "title": "AddressEdit 地址编辑" + "title": "AddressEdit - 地址编辑" }, { "path": "/address-list", - "title": "AddressList 地址列表" + "title": "AddressList - 地址列表" }, { "path": "/area", - "title": "Area 省市区选择" + "title": "Area - 省市区选择" }, { "path": "/contact", - "title": "Contact 联系人" + "title": "Contact - 联系人" }, { "path": "/coupon", - "title": "Coupon 优惠券选择器" + "title": "Coupon - 优惠券选择器" }, { "path": "/goods-action", - "title": "GoodsAction 商品页行动点" + "title": "GoodsAction - 商品页行动点" }, { "path": "/submit-bar", - "title": "SubmitBar 提交订单栏" + "title": "SubmitBar - 提交订单栏" }, { "path": "/sku", - "title": "Sku 商品规格弹层" + "title": "Sku - 商品规格弹层" } ] } ] } ] + }, + "en-US": { + header: { + 'Homepage': 'https://www.youzanyun.com/zanui', + 'PC': 'https://www.youzanyun.com/zanui/react', + 'Mobile': 'https://www.youzanyun.com/zanui/vue', + 'Weapp': 'https://github.com/youzan/zanui-weapp', + '中文': '#/zh-CN' + }, + footer: { + github: 'https://github.com/youzan/vant', + nav: { + 'Youzan': 'https://www.youzan.com/', + 'Join us': 'https://job.youzan.com/', + 'Feedback': 'https://github.com/youzan/vant/issues' + } + }, + nav: [ + { + "name": "Essentials", + "groups": [ + { + "list": [ + { + "path": "/quickstart", + "title": "Getting Started", + noExample: true + }, + { + "path": "/changelog", + "title": "Changelog", + noExample: true + } + ] + } + ] + }, + // translation needed + { + "name": "Components", + "showInMobile": true, + "groups": [ + { + "groupName": "Base Components", + "list": [ + { + "path": "/layout", + "title": "Layout" + } + ] + }, + ] + } + ] } } diff --git a/docs/src/examples.js b/docs/src/examples.js index e4c2337a9..3d8eef83b 100644 --- a/docs/src/examples.js +++ b/docs/src/examples.js @@ -2,9 +2,9 @@ import Vue from 'vue'; import VueRouter from 'vue-router'; import App from './ExamplesApp'; import routes from './router.config'; +import { setLang } from './utils/lang'; import Vant, { Lazyload } from 'packages'; import ZanDoc from 'zan-doc'; -import DemoList from './components/demo-list'; import 'packages/vant-css/src/index.css'; import 'zan-doc/src/helper/touch-simulator'; @@ -16,22 +16,18 @@ Vue.use(Lazyload, { Vue.use(VueRouter); const routesConfig = routes(true); -routesConfig.push({ - path: '/', - component: DemoList -}); const router = new VueRouter({ mode: 'hash', base: '/zanui/vue/examples', routes: routesConfig }); -router.afterEach(() => { +router.afterEach((route) => { const container = document.querySelector('.examples-container'); if (container) { document.querySelector('.examples-container').scrollTop = 0; } - window.syncPath(); + setLang(route.meta.lang); }); window.vueRouter = router; diff --git a/docs/src/index.js b/docs/src/index.js index 2313b2a20..0d2946522 100644 --- a/docs/src/index.js +++ b/docs/src/index.js @@ -3,16 +3,12 @@ import VueRouter from 'vue-router'; import App from './ExamplesDocsApp'; import routes from './router.config'; import ZanDoc from 'zan-doc'; -import isMobile from './is-mobile'; +import isMobile from './utils/is-mobile'; Vue.use(VueRouter); Vue.use(ZanDoc); const routesConfig = routes(); -routesConfig.push({ - path: '/', - redirect: '/component/quickstart' -}); const router = new VueRouter({ mode: 'hash', @@ -30,7 +26,7 @@ router.beforeEach((route, redirect, next) => { router.afterEach(() => { window.scrollTo(0, 0); - window.syncPath(); + Vue.nextTick(() => window.syncPath()); }); window.vueRouter = router; diff --git a/docs/src/router.config.js b/docs/src/router.config.js index 1b952f8a9..257231f08 100644 --- a/docs/src/router.config.js +++ b/docs/src/router.config.js @@ -1,43 +1,67 @@ import docConfig from './doc.config'; +import { getLang } from './utils/lang'; +import DemoList from './components/demo-list'; import componentDocs from '../examples-dist/entry-docs'; import componentDemos from '../examples-dist/entry-demos'; -import './iframe-router'; - -const navs = docConfig['zh-CN'].nav; +import './utils/iframe-router'; const registerRoute = (isExample) => { const route = [{ + path: '/', + redirect: to => { + return `/${getLang()}/`; + } + }, { path: '*', - redirect: '/' + redirect: to => { + return `/${getLang()}/`; + } }]; - navs.forEach(nav => { - if (isExample && !nav.showInMobile) { - return; + Object.keys(docConfig).forEach((lang, index) => { + if (isExample) { + route.push({ + path: `/${lang}`, + component: DemoList, + meta: { lang } + }); + } else { + route.push({ + path: `/${lang}`, + redirect: `/${lang}/component/quickstart` + }); } - if (nav.groups) { - nav.groups.forEach(group => { - group.list.forEach(addRoute); - }); - } else if (nav.children) { - nav.children.forEach(addRoute); - } else { - addRoute(nav); + const navs = docConfig[lang].nav || []; + navs.forEach(nav => { + if (isExample && !nav.showInMobile) { + return; + } + + if (nav.groups) { + nav.groups.forEach(group => { + group.list.forEach(page => addRoute(page, lang)); + }); + } else if (nav.children) { + nav.children.forEach(page => addRoute(page, lang)); + } else { + addRoute(nav, lang); + } + }); + + function addRoute(page, lang) { + const { path } = page; + if (path) { + const name = lang + '/' + path.replace('/', ''); + route.push({ + path: `/${lang}/component${path}`, + component: isExample ? componentDemos[name] : componentDocs[name], + meta: { lang } + }); + } } }); - function addRoute(page) { - const { path } = page; - if (path) { - const name = path.replace('/', ''); - route.push({ - path: '/component' + path, - component: isExample ? componentDemos[name] : componentDocs[name] - }); - } - } - return route; }; diff --git a/docs/src/iframe-router.js b/docs/src/utils/iframe-router.js similarity index 54% rename from docs/src/iframe-router.js rename to docs/src/utils/iframe-router.js index f02baddaa..f23769b73 100644 --- a/docs/src/iframe-router.js +++ b/docs/src/utils/iframe-router.js @@ -3,6 +3,8 @@ */ import isMobile from './is-mobile'; +import { setLang } from './lang'; +import { iframeReady } from './iframe'; window.syncPath = function(dir) { const router = window.vueRouter; @@ -17,25 +19,13 @@ window.syncPath = function(dir) { } }; -window.changePath = function(path) { +window.changePath = function(path = '') { + const pathParts = path.split('/'); + let lang = pathParts[0]; + if (path[0] === '/') { + lang = pathParts[1]; + } + + setLang(lang); window.vueRouter.replace(path); }; - -function iframeReady(iframe, callback) { - const doc = iframe.contentDocument || iframe.contentWindow.document; - const interval = () => { - if (iframe.contentWindow.changePath) { - callback(); - } else { - setTimeout(() => { - interval(); - }, 50); - } - }; - - if (doc.readyState === 'complete') { - interval(); - } else { - iframe.onload = interval; - } -} diff --git a/docs/src/utils/iframe.js b/docs/src/utils/iframe.js new file mode 100644 index 000000000..e9b5db8f8 --- /dev/null +++ b/docs/src/utils/iframe.js @@ -0,0 +1,18 @@ +export function iframeReady(iframe, callback) { + const doc = iframe.contentDocument || iframe.contentWindow.document; + const interval = () => { + if (iframe.contentWindow.changePath) { + callback(); + } else { + setTimeout(() => { + interval(); + }, 50); + } + }; + + if (doc.readyState === 'complete') { + interval(); + } else { + iframe.onload = interval; + } +} diff --git a/docs/src/is-mobile.js b/docs/src/utils/is-mobile.js similarity index 100% rename from docs/src/is-mobile.js rename to docs/src/utils/is-mobile.js diff --git a/docs/src/utils/lang.js b/docs/src/utils/lang.js new file mode 100644 index 000000000..1a291fd84 --- /dev/null +++ b/docs/src/utils/lang.js @@ -0,0 +1,16 @@ +const userLang = window.localStorage.getItem('VANT_LANGUAGE') || window.navigator.language || 'en-US'; +let defaultLang = 'en-US'; +if (userLang.indexOf('zh-') !== -1) { + defaultLang = 'zh-CN'; +} + +let currentLang = defaultLang; + +export function getLang() { + return currentLang; +} + +export function setLang(lang) { + window.localStorage.setItem('VANT_LANGUAGE', lang); + currentLang = lang; +} diff --git a/package.json b/package.json index 8aea6a680..62dd6196b 100644 --- a/package.json +++ b/package.json @@ -20,7 +20,7 @@ "build:style-entry": "VUE_ENV=server node build/bin/build-style-entry.js", "build:changelog": "sh build/build-changelog.sh", "deploy": "npm run deploy:docs && npm run deploy:cdn && gh-pages -d docs/dist --remote youzan && rimraf docs/dist", - "deploy:cdn": "superman cdn /zanui/vue docs/dist/*.js docs/dist/*.css", + "deploy:cdn": "superman cdn /zanui/vue docs/dist/*.js docs/dist/*.css && superman cdn /zanui/vue/async_en-US docs/dist/async_en-US/*.js && superman cdn /zanui/vue/async_zh-CN docs/dist/async_zh-CN/*.js", "deploy:docs": "rimraf docs/dist && cross-env NODE_ENV=production webpack --progress --hide-modules --config build/webpack.config.prod.js", "dist": "node build/bin/build-lib.js", "clean": "rimraf lib && rimraf packages/*/lib", @@ -119,6 +119,6 @@ "webpack-bundle-analyzer": "^2.9.0", "webpack-dev-server": "^2.7.1", "webpack-merge": "^4.1.0", - "zan-doc": "0.2.17" + "zan-doc": "0.3.1" } } diff --git a/yarn.lock b/yarn.lock index 23e2c9af6..fef85a922 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2973,6 +2973,14 @@ fs-extra@^3.0.1: jsonfile "^3.0.0" universalify "^0.1.0" +fs-extra@^4.0.2: + version "4.0.2" + resolved "https://registry.yarnpkg.com/fs-extra/-/fs-extra-4.0.2.tgz#f91704c53d1b461f893452b0c307d9997647ab6b" + dependencies: + graceful-fs "^4.1.2" + jsonfile "^4.0.0" + universalify "^0.1.0" + fs-extra@~1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/fs-extra/-/fs-extra-1.0.0.tgz#cd3ce5f7e7cb6145883fcae3191e9877f8587950" @@ -4144,6 +4152,12 @@ jsonfile@^3.0.0: optionalDependencies: graceful-fs "^4.1.6" +jsonfile@^4.0.0: + version "4.0.0" + resolved "https://registry.yarnpkg.com/jsonfile/-/jsonfile-4.0.0.tgz#8771aae0799b64076b76640fca058f9c10e33ecb" + optionalDependencies: + graceful-fs "^4.1.6" + jsonify@~0.0.0: version "0.0.0" resolved "https://registry.yarnpkg.com/jsonify/-/jsonify-0.0.0.tgz#2c74b6ee41d93ca51b7b5aaee8f503631d252a73" @@ -7899,12 +7913,13 @@ yeast@0.1.2: version "0.1.2" resolved "https://registry.yarnpkg.com/yeast/-/yeast-0.1.2.tgz#008e06d8094320c372dbc2f8ed76a0ca6c8ac419" -zan-doc@0.2.17: - version "0.2.17" - resolved "https://registry.yarnpkg.com/zan-doc/-/zan-doc-0.2.17.tgz#bea711d254d89121b52b47792aec5127fe66fedf" +zan-doc@0.3.1: + version "0.3.1" + resolved "https://registry.yarnpkg.com/zan-doc/-/zan-doc-0.3.1.tgz#f421a90eeb8e399e4257d52f671bffd14efbd28e" dependencies: cheerio "0.22.0" decamelize "^1.2.0" + fs-extra "^4.0.2" markdown-it "^8.3.2" markdown-it-container "^2.0.0" node-watch "^0.5.5"