Skip to content

Commit a2d4f75

Browse files
committed
feat: support generate uuid
1 parent 66e1b2b commit a2d4f75

File tree

9 files changed

+54
-12
lines changed

9 files changed

+54
-12
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
<!--
2+
abbrlink: s31w9gd1
3+
-->
14
_.-"\
25
_.-" \
36
,-" \

docs/主题/默认主题.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
<!--
2+
abbrlink: 85li8wdd
3+
-->
4+
15
## 默认主题
26

37
create-react-doc 的默认主题为 [crd-seed](https://github.com/MuYunyun/create-react-doc/tree/main/packages/crd-seed)。该主题有以下特性:

docs/书写组件.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
<!--
2+
abbrlink: lx1euo1b
3+
-->
4+
15
import { Button } from '../components/index.jsx'
26

37
## 书写组件

docs/其它工具.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
<!--
2+
abbrlink: 292h2c5k
3+
-->
4+
15
## 其它工具
26

37
### crd-leetcode-cli

docs/更新日志.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
<!--
2+
abbrlink: 179nqpxt
3+
-->
4+
15
# CHANGELOG
26

37
`create-react-doc` 严格遵循 [Semantic Versioning 2.0.0](http://semver.org/lang/zh-CN/) 语义化版本规范。

docs/站点发布.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
<!--
2+
abbrlink: ude9296y
3+
-->
4+
15
## 站点发布
26

37
[快速上手](http://muyunyun.cn/create-react-doc/%E5%BF%AB%E9%80%9F%E4%B8%8A%E6%89%8B) 一节中介绍了如何快速搭建站点, 本节将介绍如何将搭建好的站点打包、发布到 gh-pages。

docs/高阶用法.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
<!--
2+
abbrlink: 9v9ug9h8
3+
-->
4+
15
## 高阶用法
26

37
与 git 文件结构类似, 如果在展示的文件夹中有私有文件不方便展示在文档站点, 可以在 `.gitignore` 文件中设置过滤文件, 这样它们就不会展示在文档站点中了。eg: [.gitignore](https://github.com/MuYunyun/blog/blob/main/.gitignore)

packages/crd-scripts/src/conf/node-directory-tree.js

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ const fs = require('fs')
33
const PATH = require('path')
44
const YAML = require('yamljs')
55
const { execSync } = require('child_process')
6-
const { replaceFileContent, generateRandomId } = require('crd-utils')
6+
const { replaceForFrontMatter, generateRandomId } = require('crd-utils')
77
const { getDigitFromDir, timeFormat } = require('../utils')
88

99
const constants = {
@@ -79,13 +79,20 @@ function directoryTree({
7979
if (!contentStr) return
8080
const contentMatch = contentStr.match(/^<!--([^>]*)-->/)
8181
if (options.generate) {
82+
const randomId = generateRandomId(8)
8283
if (!contentMatch) {
83-
84+
replaceForFrontMatter({
85+
path,
86+
target: `<!--\nabbrlink: ${randomId}\n-->\n`
87+
})
8488
}
8589
if (contentMatch && contentMatch[1].indexOf('abbrlink') === -1) {
86-
const randomId = generateRandomId(8)
87-
replaceFileContent(path, contentMatch[1], `\nabbrlink: ${randomId}${contentMatch[1]}`)
88-
console.log('✅ replaceFileContent success')
90+
replaceForFrontMatter({
91+
path,
92+
source: contentMatch[1],
93+
target: `\nabbrlink: ${randomId}${contentMatch[1]}`
94+
})
95+
console.log('✅ replaceForFrontMatter success')
8996
}
9097
}
9198

packages/crd-utils/index.js

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,26 @@ const getDocsConfig = () => {
1616
return yaml.safeLoad(fs.readFileSync(docsConfig))
1717
}
1818

19-
const replaceFileContent = (path, source, target) => {
19+
/**
20+
* replace file content for Front-matter
21+
* path: file path
22+
* source?: source content
23+
* target: target content
24+
*/
25+
const replaceForFrontMatter = ({
26+
path,
27+
source,
28+
target
29+
}) => {
2030
fs.readFile(path, (err, data) => {
2131
if (err) {
2232
console.log(`❎ readFileContent error in ${path}`)
2333
return
2434
}
2535
console.log(`✅ readFileContent success in ${path}`)
26-
const replaceResult = data.toString().replace(source, target)
36+
const replaceResult = source
37+
? data.toString().replace(source, target)
38+
: `${target}\n${data.toString()}`
2739
fs.writeFile(path, replaceResult, (err) => {
2840
if (err) {
2941
console.log(`❎ writeFileContent error in ${path}`)
@@ -34,10 +46,6 @@ const replaceFileContent = (path, source, target) => {
3446
})
3547
}
3648

37-
const insertFrontMatter = () => {
38-
// todo...
39-
}
40-
4149
// generate a random string, length of it is n.
4250
const generateRandomId = (n) => {
4351
const str = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
@@ -53,7 +61,7 @@ module.exports = {
5361
resolveApp,
5462
resolveTool,
5563
getDocsConfig,
56-
replaceFileContent,
64+
replaceForFrontMatter,
5765
generateRandomId,
5866
// common paths
5967
docsGitIgnore: resolveApp('.gitignore'),

0 commit comments

Comments
 (0)