Skip to content

Commit 3c69920

Browse files
Merge pull request #9 from swan-team/master
merge master
2 parents 706767f + 573cea7 commit 3c69920

File tree

3,462 files changed

+32015
-55945
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

3,462 files changed

+32015
-55945
lines changed

.gitignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,5 @@ package-lock.json
1212
.vscode
1313
.project
1414
miniapp_docs_*
15-
source/sitemap.txt
15+
source/sitemap.txt
16+
fis-conf.js

README.md

+3-2
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,16 @@
44
### 开启本地预览
55
进入 swan-docs,终端执行 `npm start`;
66

7-
终端看到`Hexo is running at http://localhost:4000/docs/. Press Ctrl+C to stop.` 提示,启动成功。
7+
终端看到`VuePress dev server listening at http://localhost:4000/docs/` 提示,启动成功。
88

99
访问 http://localhost:4000/docs/introduction/register/ 开始编辑(path与线上一致)。
1010

1111
### 编写
1212
编辑器打开模块,找到你要编辑的文档所在文件夹,修改刷新浏览器即可看到修改。
1313

1414
#### 新增文档
15-
如果是新增文档,去到`source/_data/nav.yml`新增一份配置(nav.yml配置说明见编写规范)。然后到对应的目录下建立一个.md。
15+
如果是新增文档,去到`program-docs/nav/nav.yml`新增一份配置(nav.yml配置说明见编写规范)。
16+
然后到对应的目录下(`program-docs/docs/`)建立一个.md。
1617

1718
## 编写规范
1819
### 导航配置

make-sitemap.js

-48
This file was deleted.

package.json

+33-34
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,41 @@
11
{
22
"name": "swan-docs",
33
"version": "1.0.0",
4-
"private": true,
5-
"description": "智能小程序文档",
6-
"hexo": {
7-
"version": "3.7.1"
8-
},
4+
"description": "",
5+
"main": "index.js",
96
"scripts": {
10-
"prebuild": "npm install && hexo --safe && node make-sitemap.js",
11-
"prestart": "npm install && hexo --safe",
12-
"copy": "cp -r source/_posts output/miniappdocs/sourcedocs/ && cp -r source/_data/nav.yml output/miniappdocs/sourcedocs/",
13-
"start": "node make-sitemap.js && npx hexo server",
14-
"build": "npx hexo clean && NODE_OPTIONS=--max-old-space-size=4096 npx hexo generate && npm run copy"
7+
"prestart": "npm i",
8+
"prebuild": "npm i",
9+
"predev:program": "npm i",
10+
"prebuild:program": "npm i",
11+
"dev:game": "cd game-docs && npm start",
12+
"build:game": "cd game-docs && npm run build",
13+
"dev:program": "vuepress dev program-docs/docs --no-cache",
14+
"build:program": "vuepress build program-docs/docs --no-cache",
15+
"build": "vuepress build program-docs/docs --no-cache",
16+
"start": "vuepress dev program-docs/docs --no-cache"
1517
},
16-
"dependencies": {
17-
"cheerio": "1.0.0-rc.2",
18-
"hexo": "3.7.1",
19-
"hexo-generator-archive": "^0.1.4",
20-
"hexo-generator-category": "^0.1.3",
21-
"hexo-generator-index": "^0.2.0",
22-
"hexo-generator-search": "^2.2.5",
23-
"hexo-generator-tag": "^0.2.0",
24-
"hexo-include-markdown": "1.0.2",
25-
"hexo-neat": "^1.0.4",
26-
"hexo-renderer-ejs": "^0.3.0",
27-
"hexo-renderer-less": "^0.2.0",
28-
"hexo-renderer-marked": "^0.3.0",
29-
"hexo-server": "^0.2.0",
30-
"uglify-js": "^2.8.29"
18+
"directories": {
19+
"doc": "docs",
20+
"test": "test"
3121
},
32-
"repository": {
33-
"type": "git",
34-
"url": "git@github.com:swan-team/swan-docs.git"
22+
"dependencies": {
23+
"axios": "^0.19.0",
24+
"fs-extra": "^8.1.0",
25+
"globby": "^10.0.1",
26+
"jquery": "^3.4.1",
27+
"less": "^3.10.3",
28+
"less-loader": "^5.0.0",
29+
"markdown-it-task-checkbox": "^1.0.6",
30+
"strip-ansi": "^6.0.0",
31+
"qrcode.vue": "^1.7.0",
32+
"qs": "^6.9.1",
33+
"vue-clipboard2": "^0.3.1",
34+
"vuepress": "^1.2.0",
35+
"vuepress-plugin-container": "^2.1.2",
36+
"vuepress-plugin-smooth-scroll": "0.0.9"
3537
},
36-
"keywords": [
37-
"swan",
38-
"智能小程序",
39-
"文档"
40-
],
41-
"author": "swan-team"
38+
"keywords": [],
39+
"author": "swan-team",
40+
"license": "ISC"
4241
}

program-docs/docs/.vuepress/config.js

+74
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
/**
2+
* @file 配置文件
3+
* @author wulinfei
4+
*/
5+
6+
const router = require('./plugins/router.js');
7+
const navLoader = require('./utils/nav-loader');
8+
const preWrapper = require('./plugins/code-pre-wapper');
9+
const search = require('./plugins/gen-search');
10+
const container = require('./plugins/container');
11+
const path = require('path');
12+
13+
module.exports = {
14+
base: '/docs/',
15+
title: '百度智能小程序文档',
16+
head: [
17+
['link', {rel: 'shortcut icon', href: 'https://www.baidu.com/favicon.ico', type: 'image/x-icon'}],
18+
['link', {rel: 'dns-prefetch', href: '//smartprogram.baidu.com'}]
19+
],
20+
port: 4000,
21+
dest: 'output/miniappdocs-program',
22+
cache: false,
23+
shouldPrefetch: () => false,
24+
extraWatchFiles: [
25+
'../nav/nav.yml'
26+
],
27+
themeConfig: {
28+
navData: navLoader.getNavData(),
29+
nav: {
30+
navOther: [
31+
{text: '服务市场', link: 'https://smartprogram.baidu.com/developer/servicemarket.html'}
32+
],
33+
smartDocs: 'https://smartprogram.baidu.com/docs/',
34+
smartProgram: 'https://smartprogram.baidu.com/developer/index.html'
35+
},
36+
headerNavOther: [
37+
{text: '社区', link: 'https://smartprogram.baidu.com/forum/'}
38+
]
39+
},
40+
plugins: [
41+
router,
42+
search,
43+
container,
44+
['vuepress-plugin-smooth-scroll', false]
45+
],
46+
patterns: [],
47+
extendMarkdown: md => {
48+
// Convert '\n' in paragraphs into <br>
49+
md.set({breaks: true});
50+
md.use(require('./plugins/md-loader'), md);
51+
md.use(require('markdown-it-task-checkbox'), {
52+
disabled: false,
53+
ulClass: 'task-list',
54+
liClass: 'task-list-item'
55+
});
56+
57+
},
58+
chainMarkdown(config) {
59+
config.plugin('pre-wrapper').use(preWrapper);
60+
},
61+
devServer: {
62+
disableHostCheck: true,
63+
proxy: {
64+
'/forum/api/*': {
65+
target: 'http://cp01-lizhiguang.epc.baidu.com:8014',
66+
ws: true,
67+
changeOrigin: true
68+
}
69+
}
70+
}
71+
};
72+
73+
74+
+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/**
2+
* @file 客户端应用的增强
3+
* @author wulinfei
4+
*/
5+
6+
const VueClipboard = require('vue-clipboard2');
7+
8+
const hashRegx = /^#(\d)/;
9+
export default ({Vue, router}) => {
10+
// 代码片段支持复制
11+
Vue.use(VueClipboard);
12+
13+
// 支持平滑滚动
14+
router.options.scrollBehavior = (to, from, savedPosition) => {
15+
if (savedPosition) {
16+
return window.scrollTo({
17+
top: savedPosition.y,
18+
behavior: 'smooth'
19+
});
20+
}
21+
else if (to.hash) {
22+
// 将数字开头的hash前加上 _
23+
const hashId = to.hash.replace(hashRegx, '#_$1').toLowerCase();
24+
25+
const targetElement = document.querySelector(hashId);
26+
if (targetElement) {
27+
return window.scrollTo({
28+
top: getElementPosition(targetElement).y - 120,
29+
behavior: 'smooth'
30+
});
31+
}
32+
return false;
33+
}
34+
else {
35+
return window.scrollTo({
36+
top: 0,
37+
behavior: 'smooth'
38+
});
39+
}
40+
};
41+
};
42+
43+
function getElementPosition(el) {
44+
const docEl = document.documentElement;
45+
const docRect = docEl.getBoundingClientRect();
46+
const elRect = el.getBoundingClientRect();
47+
return {
48+
x: elRect.left - docRect.left,
49+
y: elRect.top - docRect.top
50+
};
51+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/**
2+
* @file code代码重新包装
3+
* @author wulinfei
4+
*/
5+
6+
const extensionLanguageMap = {
7+
swan: 'markup',
8+
md: 'markdown',
9+
ts: 'typescript',
10+
py: 'python',
11+
sh: 'bash',
12+
yml: 'yaml'
13+
};
14+
15+
const getLangExtension = exlang => {
16+
const lowerlang = exlang.toLowerCase();
17+
return extensionLanguageMap[lowerlang] || lowerlang;
18+
};
19+
20+
module.exports = md => {
21+
const fence = md.renderer.rules.fence;
22+
md.renderer.rules.fence = (...args) => {
23+
const [tokens, idx] = args;
24+
const token = tokens[idx];
25+
const rawlang = token.info.trim();
26+
token.info = getLangExtension(rawlang);
27+
const tabName = rawlang.toUpperCase() || 'TEXT';
28+
const rawCode = fence(...args);
29+
return `<!--beforebegin--><CodeTabContent name="${tabName}">`
30+
+ `<!--afterbegin-->${rawCode}<!--beforeend--></CodeTabContent><!--afterend-->`;
31+
};
32+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/**
2+
* @file container.js
3+
* @description 文档内容组件
4+
* @author wulinfei
5+
*/
6+
7+
module.exports = {
8+
plugins: [
9+
// 代码块Tab
10+
['container', {
11+
type: 'codeTab',
12+
defaultTitle: '',
13+
before: info => `<CodeTab>${info}`,
14+
after: '</CodeTab>'
15+
}],
16+
// 二维码
17+
['container', {
18+
type: 'qrcode',
19+
defaultTitle: '',
20+
before: info => `<QRCode ${info}>`,
21+
after: '</QRCode>'
22+
}],
23+
// 提示中的error 用于bug等 红色
24+
['container', {
25+
type: 'errorTip',
26+
defaultTitle: 'Bug'
27+
}],
28+
// 提示中的info 用于tip等 绿色
29+
['container', {
30+
type: 'infoTip',
31+
defaultTitle: 'Tip'
32+
}],
33+
// 打开开发者工具
34+
['container', {
35+
type: 'openIde',
36+
before: info => `<OpenIde ${info}>`,
37+
after: '</OpenIde>'
38+
}],
39+
// 设计指南
40+
['container', {
41+
type: 'design',
42+
defaultTitle: '设计指南'
43+
}]
44+
]
45+
};

0 commit comments

Comments
 (0)