mirror of
https://github.com/142vip/408CSFamily.git
synced 2026-04-13 17:29:51 +08:00
feat: 新增markdown转思维导图脚本,导航栏改版
This commit is contained in:
56
scripts/mark-map
Executable file
56
scripts/mark-map
Executable file
@@ -0,0 +1,56 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
/**
|
||||
* 将思维导图的md格式转化为html,提供在线预览
|
||||
* 链接:https://www.npmjs.com/package/markmap-cli
|
||||
*/
|
||||
const {execShell} = require("./.exec");
|
||||
const path = require('path');
|
||||
const fs = require('fs');
|
||||
const markMapPath = path.join(__dirname, '../', 'docs/manuscripts/mark-map')
|
||||
const markMapHtmlPath = path.join(__dirname, '../', 'docs/.vuepress/public/mark-map')
|
||||
|
||||
|
||||
/**
|
||||
* 扫面目录
|
||||
*/
|
||||
function scanDirectory(directory, fileType) {
|
||||
const fileList = fs.readdirSync(directory)
|
||||
|
||||
return fileList
|
||||
.map(file => {
|
||||
const filePath = path.join(directory, file);
|
||||
const fileExtension = path.extname(file).toLowerCase();
|
||||
|
||||
if (fileExtension === `.${fileType.toLowerCase()}`) {
|
||||
return filePath
|
||||
}
|
||||
})
|
||||
// 过滤空
|
||||
.filter(c => c != null)
|
||||
}
|
||||
|
||||
|
||||
(async () => {
|
||||
/**
|
||||
* 第一步: 清空站点思维导图文件存放目录
|
||||
*/
|
||||
const delHtmlDir = `rm -rf ${path.join(markMapHtmlPath, '*')}`
|
||||
|
||||
/**
|
||||
* 第二步: 将md文档转化为思维导图网页
|
||||
*/
|
||||
const mdList = scanDirectory(markMapPath, 'md')
|
||||
const mdToHtmlCmdStr = mdList.map(md => `markmap --no-open ${md}`).join(' && ')
|
||||
|
||||
|
||||
/**
|
||||
* 第三步: 根据文件类型将思维导图网页文件移动到站点指定目录
|
||||
*
|
||||
*/
|
||||
const mdHtmlByFileType = path.join(markMapPath, '*.html')
|
||||
const moveHtmlCmdStr = `mv -f ${mdHtmlByFileType} ${markMapHtmlPath}`
|
||||
|
||||
await execShell([delHtmlDir, mdToHtmlCmdStr, moveHtmlCmdStr])
|
||||
|
||||
})()
|
||||
Reference in New Issue
Block a user