Skip to content

Commit 4334218

Browse files
authored
feat: plop new docs or template set alias; update docs about alias (#21)
1 parent 44066fd commit 4334218

File tree

10 files changed

+250
-104
lines changed

10 files changed

+250
-104
lines changed

CHANGELOG.md

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# 1.0.0 (2020-04-13)
1+
# 1.0.0 (2020-07-05)
22

33

44
### Bug Fixes
@@ -50,6 +50,7 @@
5050
* observer pattern ([77c78f7](https://github.com/Rain120/awesome-javascript-code-implementation/commit/77c78f7359161c0e64b3143e3a66fea3f5d4eb46))
5151
* plop create code and docs model ([2dece76](https://github.com/Rain120/awesome-javascript-code-implementation/commit/2dece76fbfd83514551dbabadf7c54d73674730d))
5252
* plop new code and docs template ([61a936b](https://github.com/Rain120/awesome-javascript-code-implementation/commit/61a936b58bc52a1cf984dc6156746b43f65da7f1))
53+
* plop new docs or template set alias; update docs about alias ([99acb07](https://github.com/Rain120/awesome-javascript-code-implementation/commit/99acb07f03348613efab69049a240bf04928dc6b))
5354
* promise; debugger launch ([cc8ad80](https://github.com/Rain120/awesome-javascript-code-implementation/commit/cc8ad803956e65431cedd97f1ebb333ffe78c28e))
5455
* proxy design ([e615f39](https://github.com/Rain120/awesome-javascript-code-implementation/commit/e615f39497043f4c2357c7366cb13226b57208e6))
5556
* sort -> bubbleSort(algorithm, readme, test) ([36fab7b](https://github.com/Rain120/awesome-javascript-code-implementation/commit/36fab7b029d425ac129b6c4f202b18a9a3852fef))
@@ -60,10 +61,10 @@
6061
* update readme for plans ([b427b96](https://github.com/Rain120/awesome-javascript-code-implementation/commit/b427b9667cc97c77df75ef0af56eb84b6b4c3ba6))
6162
* update test.yml -> ci.yml and set command ([43b96b6](https://github.com/Rain120/awesome-javascript-code-implementation/commit/43b96b63fc2788a5ea37fa7567c6a6dced4b875f))
6263
* update vdom-diff docs ([06590c5](https://github.com/Rain120/awesome-javascript-code-implementation/commit/06590c56d0df7cbba68bb705cb7e159f6f765c3a))
63-
* update xmind ([71317c6](https://github.com/Rain120/awesome-javascript-code-implementation/commit/71317c67376bc8196f80e25391adfdc9b2496380))
64-
* update xmind ([4256758](https://github.com/Rain120/awesome-javascript-code-implementation/commit/4256758c5fe0a036ce3ececc43f848e48964d7a0))
65-
* update xmind ([408ca68](https://github.com/Rain120/awesome-javascript-code-implementation/commit/408ca685142dc425e90be64a284016d57d580893))
6664
* update xmind ([cb23933](https://github.com/Rain120/awesome-javascript-code-implementation/commit/cb23933f46152c59a7b08f84d7355b35bba25002))
65+
* update xmind ([408ca68](https://github.com/Rain120/awesome-javascript-code-implementation/commit/408ca685142dc425e90be64a284016d57d580893))
66+
* update xmind ([4256758](https://github.com/Rain120/awesome-javascript-code-implementation/commit/4256758c5fe0a036ce3ececc43f848e48964d7a0))
67+
* update xmind ([71317c6](https://github.com/Rain120/awesome-javascript-code-implementation/commit/71317c67376bc8196f80e25391adfdc9b2496380))
6768
* update: plans; fix: readme bug ([d44e559](https://github.com/Rain120/awesome-javascript-code-implementation/commit/d44e559def7834fcccbb19797a1d29bf5cc4e5b7))
6869
* vdom diff algorithm ([3b7779d](https://github.com/Rain120/awesome-javascript-code-implementation/commit/3b7779dcad7e184027d1bddfa6387224c2f009d3))
6970
* vuepress docs v1.0.0 ([785caeb](https://github.com/Rain120/awesome-javascript-code-implementation/commit/785caeb41beeff7a0f53646fc952d1c89ebb61d5))

README.md

+14-2
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,9 @@ Document Link:
4545

4646
[Xmind Download](plans.xmind)
4747

48-
#### 🔨 Usage
48+
#### 🔨 Quick Start
4949

50-
⌨️
50+
<!-- ⌨️ To be Continue... -->
5151

5252
生成 `code` 模板
5353

@@ -69,6 +69,18 @@ npm run template-docs
6969

7070
[how-to-write-docs](docs/zh/how-to-write-docs/README.md)
7171

72+
#### 🌏Deploy
73+
74+
##### -> https://rain120.github.io/awesome-javascript-code-implementation
75+
76+
```
77+
npm run deploy
78+
```
79+
80+
##### -> https://awesome-javascript-code-implementation.netlify.com/
81+
82+
`netlify auto deploy`
83+
7284
#### 🤝 Contributing
7385

7486
![PR](https://img.shields.io/badge/PRs-Welcome-orange?style=flat-square&logo=appveyor)

docs/.vuepress/config.js

+6-12
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,17 @@
11
const path = require('path');
22
const plugins = require('./utils/plugins');
3-
const { sidebarHelper } = require('./utils/sidebarHelper');
3+
const { sidebarHelper, sortSidebar } = require('./utils/sidebarHelper');
44
const nav = require('./utils/nav');
55

66
/**
7-
* @description [guide, how-to-write-docs, ...]
7+
* sortSidebar 根据 alias 设置顺序,默认顺序为 文件夹名字的顺序
88
*/
9-
const docs = sidebarHelper();
10-
const sidebar = [];
11-
docs.map(item => {
12-
if (item.path.includes('guide') || item.path.includes('how-to-write-docs')) {
13-
sidebar.unshift(item)
14-
} else {
15-
sidebar.push(item)
16-
}
17-
});
18-
[sidebar[1], sidebar[0]] = [sidebar[0], sidebar[1]];
9+
10+
const sidebar = sortSidebar(sidebarHelper());
1911

2012
// git pages base project name -> /awesome-javascript-code-implementation/, netlify base: ''
13+
// deploy https://rain120.github.io/awesome-javascript-code-implementation build has argv
14+
// more info go to deploy.sh
2115
const ARGV = (process.argv || []).slice(-1)[0];
2216
const base = ARGV !== 'docs' ? ARGV : '';
2317

docs/.vuepress/utils/alias.js

-78
This file was deleted.

docs/.vuepress/utils/alias.json

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
{
2+
"guide": "介绍",
3+
"how-to-write-docs": "如何写文档? ",
4+
"math-------": "",
5+
"math": "数学",
6+
"factorial": "阶乘",
7+
"fibonacci": "斐波那契数列",
8+
"gcd": "最大公约数",
9+
"lcm": "最小公倍数",
10+
"binary": "二进制",
11+
"primitive-------": "",
12+
"primitive": "原生 Javascript",
13+
"function-------": "",
14+
"function": "函数",
15+
"debounce": "防抖",
16+
"throttle": "节流",
17+
"vdom-diff-------": "",
18+
"vdom-diff": "实现React/Vue DOM Diff算法",
19+
"es6-------": "",
20+
"es6": "ECMAScript 6(ES6)",
21+
"promise": "手写Promise",
22+
"Array-------": "",
23+
"array": "Array(MDN + Function)",
24+
"Object-------": "",
25+
"object": "Object(MDN + Function)",
26+
"types-------": "",
27+
"types": "Types",
28+
"utils-------": "",
29+
"utils": "Utils",
30+
"design-pattern-------": "",
31+
"design-pattern": "设计模式",
32+
"adapter-pattern": "适配器模式",
33+
"decorator-pattern": "装饰器模式",
34+
"factory-pattern": "工厂模式",
35+
"facade-pattern": "外观模式",
36+
"iterator-pattern": "迭代器模式",
37+
"proxy-pattern": "代理模式",
38+
"observer-pattern": "观察者模式",
39+
"singleton-pattern": "单例模式",
40+
"algorithms-------": "",
41+
"algorithms": "算法",
42+
"binaryTree": "二叉树",
43+
"sort-------": "",
44+
"sort": "排序算法",
45+
"bubbleSort": "冒泡排序",
46+
"bucketSort": "桶排序",
47+
"countingSort": "计数排序",
48+
"heapSort": "堆排序",
49+
"insertionSort": "插入排序",
50+
"mergeSort": "归并排序",
51+
"quickSort": "快速排序",
52+
"radixSort": "基数排序",
53+
"selectionSort": "选择排序",
54+
"shellSort": "希尔排序"
55+
}

docs/.vuepress/utils/sidebarHelper.js

+37-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,22 @@ const path = require('path');
44
const filePath = path.join(__dirname, '../../zh');
55
const ignore = ['images', '.vuepress', '.DS_Store'];
66
const README_REG = /README/;
7-
const { alias } = require('./alias');
7+
8+
/**
9+
* @description 特殊处理文档顺序
10+
* alias 的顺序决定了文档菜单的目录顺序,子菜单亦可
11+
* Eg:
12+
* p2: p2
13+
* p1: p1
14+
* p1-c2: p1-c2
15+
* p1-c1: p1-c1
16+
* -> 菜单顺序是
17+
* p2
18+
* p1
19+
* c2
20+
* c1
21+
*/
22+
const alias = require('./alias.json');
823

924
const mapper = code => {
1025
return alias[code];
@@ -32,13 +47,15 @@ function helper({ dir, fPath }) {
3247
const name = sub.replace('\.md', '');
3348
return {
3449
title: mapper(name) || `${name}`,
50+
key: name,
3551
path: `${prefixPath}/${fPath}/${name}`,
3652
}
3753
}
3854
}).filter(Boolean);
3955

4056
return {
4157
title: mapper(fPath) || `${fPath}`,
58+
key: fPath,
4259
path: `${prefixPath}/${fPath}/`,
4360
collapsable: true,
4461
children: Array.isArray(children) ? children : [children],
@@ -53,6 +70,24 @@ function sidebarHelper(dir = filePath) {
5370
});
5471
}
5572

73+
74+
function findIndex(value) {
75+
return Object.keys(alias).findIndex(item => item === value)
76+
}
77+
78+
function sortSidebar(sidebar) {
79+
sidebar.sort((a, b) => {
80+
return findIndex(a.key) - findIndex(b.key);
81+
});
82+
for (const item of sidebar) {
83+
if (item && Array.isArray(item.children)) {
84+
item.children = sortSidebar(item.children);
85+
}
86+
}
87+
return sidebar;
88+
}
89+
5690
module.exports = {
57-
sidebarHelper
91+
sidebarHelper,
92+
sortSidebar,
5893
};

docs/zh/how-to-write-docs/README.md

+52-2
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,13 @@ npm run docs
2020
touch docs/zh/test/README.md
2121
```
2222

23+
```sh
24+
# npm run docs
25+
? please input the docs model name: model
26+
? please input the docs model alias name (default same as model name)?
27+
? generator model path (etc: docs/zh/model) ? docs/zh
28+
```
29+
2330
`Eg: File Path`
2431

2532
```sh
@@ -46,11 +53,54 @@ docs/zh
4653
│   │   └── README.md
4754
```
4855

56+
**模板文件**
57+
`plop-templates/docs/zh/README.md.hbs`
58+
59+
<<< @/plop-templates/docs/zh/README.md.hbs
60+
61+
## 新建 Code 模板 + 单测模板
62+
63+
```sh
64+
npm run template-docs
65+
```
66+
67+
```sh
68+
? please input the name: template
69+
? please input the docs model alias name (default same as model name)?
70+
? Do you want test file ? Yes
71+
? generator path (etc: src/template) ? src
72+
? generator model path (etc: docs/zh/model) ? docs/zh
73+
```
74+
75+
**模板文件**
76+
77+
`plop-templates/code/__tests__.ts.hbs`
78+
79+
<<< @/plop-templates/code/__tests__.ts.hbs
80+
81+
`plop-templates/code/index.ts.hbs`
82+
83+
<<< @/plop-templates/code/index.ts.hbs
84+
85+
`plop-templates/code/README.md.hbs`
86+
87+
<<< @/plop-templates/code/README.md.hbs
88+
89+
## 文档顺序
90+
91+
::: tip
92+
`alias.json` 的顺序就是文档的顺序
93+
:::
94+
4995
## 配置别名
5096

51-
我们不支持中文名文件夹, 所以你需要给文件名配置别名, 只需要在`docs/.vuepress/utils/alias.js`中配置 `key-value`值即可
97+
::: tip
98+
通过使用 [新建文件](#新建文件) 的脚本来动态配置 `alias`, 妈妈再也不用担心我找不到配置了。
99+
:::
100+
101+
我们不支持中文名文件夹, 所以你需要给文件名配置别名, 只需要在`docs/.vuepress/utils/alias.json`中配置 `key-value`值即可
52102

53-
<<< @/docs/.vuepress/utils/alias.js
103+
<<< @/docs/.vuepress/utils/alias.json
54104

55105
## 图片
56106

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
},
4949
"husky": {
5050
"hooks": {
51-
"pre-commit": "lint-staged",
51+
"pre-commit": "npm run changelog && npm run deploy && lint-staged",
5252
"commit-msg": "commitlint -E HUSKY_GIT_PARAMS"
5353
}
5454
},

0 commit comments

Comments
 (0)