Skip to content

Commit 66e1b2b

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

File tree

3 files changed

+23
-2
lines changed

3 files changed

+23
-2
lines changed

docs/数学公式.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<!--
2+
abbrlink: slkczvi1
23
title: 数学公式
34
date: 2019-05-12 13:23:44
45
-->

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

Lines changed: 6 additions & 2 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 } = require('crd-utils')
6+
const { replaceFileContent, generateRandomId } = require('crd-utils')
77
const { getDigitFromDir, timeFormat } = require('../utils')
88

99
const constants = {
@@ -79,8 +79,12 @@ function directoryTree({
7979
if (!contentStr) return
8080
const contentMatch = contentStr.match(/^<!--([^>]*)-->/)
8181
if (options.generate) {
82+
if (!contentMatch) {
83+
84+
}
8285
if (contentMatch && contentMatch[1].indexOf('abbrlink') === -1) {
83-
replaceFileContent(path, contentMatch[1], `\nabbrlink: 290a4219${contentMatch[1]}`)
86+
const randomId = generateRandomId(8)
87+
replaceFileContent(path, contentMatch[1], `\nabbrlink: ${randomId}${contentMatch[1]}`)
8488
console.log('✅ replaceFileContent success')
8589
}
8690
}

packages/crd-utils/index.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,27 @@ const replaceFileContent = (path, source, target) => {
3434
})
3535
}
3636

37+
const insertFrontMatter = () => {
38+
// todo...
39+
}
40+
41+
// generate a random string, length of it is n.
42+
const generateRandomId = (n) => {
43+
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']
44+
let res = ""
45+
for (let i = 0; i < n; i++) {
46+
const id = Math.ceil(Math.random() * 35)
47+
res += str[id]
48+
}
49+
return res
50+
}
51+
3752
module.exports = {
3853
resolveApp,
3954
resolveTool,
4055
getDocsConfig,
4156
replaceFileContent,
57+
generateRandomId,
4258
// common paths
4359
docsGitIgnore: resolveApp('.gitignore'),
4460
docsBase: resolveApp(''),

0 commit comments

Comments
 (0)