+
-
-
-
{{ data.heroText || $title || 'Hello' }}
-{{ data.tagline || $description || 'Welcome to your VuePress site' }}
-
+
+
{{ homeData.heroText || $title || 'Hello' }}
+{{ homeData.tagline || $description || 'Welcome to your VuePress site' }}
+
-
+
-
-
+
-
+ {{ feature.title }}
@@ -23,14 +24,14 @@
+
+
}, ...}
+ let matterData = fileMatterObj.data; // 得到md文件的front Matter
- // files.forEach(file => {
- // let dataStr = fs.readFileSync(file.filePath, 'utf8');// 读取每个md文件内容
-
- // /**
- // * fileMatterObj => {content:'剔除frontmatter后的文件内容字符串', data:{}, ...}
- // */
- // const fileMatterObj = matter(dataStr);
-
- // if (Object.keys(fileMatterObj.data).length === 0) { // 未定义FrontMatter数据
- // const stat = fs.statSync(file.filePath);
- // const dateStr = dateFormat(stat.birthtime);// 文件的创建时间
- // const newData = `---\r\ntitle: ${file.name}\r\ndate: ${dateStr}\r\npermalink: ${file.permalink}\r\n---\r\n` + fileMatterObj.content;
- // fs.writeFileSync(file.filePath, newData); // 写入
- // console.log(`write FrontMatter:${file.filePath} `)
-
- // } else { // 已有FrontMatter
- // const matterData = fileMatterObj.data;
- // let mark = false;
-
- // // 已有FrontMatter,但是没有title、date、permalink数据的
- // if (!matterData.hasOwnProperty('title')) {
- // matterData.title = file.name;
- // mark = true;
- // }
-
- // if (!matterData.hasOwnProperty('date')) {
- // const stat = fs.statSync(file.filePath);
- // matterData.date = dateFormat(stat.birthtime);
- // mark = true;
- // }
-
- // if (!matterData.hasOwnProperty('permalink')) {
- // matterData.permalink = file.permalink;
- // mark = true;
- // }
-
- // if (mark) {
- // if(matterData.date && type(matterData.date) === 'date') {
- // matterData.date = repairDate(matterData.date) // 修复时间格式
- // }
- // const newData = jsonToYaml.stringify(matterData).replace(/\n\s{2}/g,"\n") + '---\r\n' + fileMatterObj.content;
- // fs.writeFileSync(file.filePath, newData); // 写入
- // console.log(`update FrontMatter:${file.filePath} `)
- // }
-
-
- // // 更新title和permalink
- // if (arg === '-update' && matterData.title != file.name){ // 当title和文件名不一致时才更新
- // matterData.title = file.name;
- // if (/pages/.test(matterData.permalink)) {
- // matterData.permalink = file.permalink;
- // }
- // // 修复date时区和格式被修改的问题 (并非更新date的值)
- // matterData.date = repairDate(matterData.date);
-
- // const newData2 = jsonToYaml.stringify(JSON.parse(JSON.stringify(matterData))) + '---\r\n' + fileMatterObj.content;
- // fs.writeFileSync(file.filePath, newData2); // 写入
- // console.log(`update FrontMatter title and permalink:${file.filePath}`)
- // }
-
- // }
+ if (config.delete == true) { // 删除操作
+ for(let key in config.data) {
+ delete matterData[key]
+ }
+ } else { // 添加、修改操作
+ Object.assign(matterData, config.data) // 将配置数据合并到front Matter对象
+ }
- // })
-
-}
-
-// 类型判断
-function type(o){
- var s = Object.prototype.toString.call(o)
- return s.match(/\[object (.*?)\]/)[1].toLowerCase()
-}
-
- // 修复date时区格式的问题
-function repairDate(date) {
- date = new Date(date);
- return `${date.getUTCFullYear()}-${zero(date.getUTCMonth()+1)}-${zero(date.getUTCDate())} ${zero(date.getUTCHours())}:${zero(date.getUTCMinutes())}:${zero(date.getUTCSeconds())}`;
-}
-
-// 日期的格式
-function dateFormat(date) {
- return `${date.getFullYear()}-${zero(date.getMonth()+1)}-${zero(date.getDate())} ${zero(date.getHours())}:${zero(date.getMinutes())}:${zero(date.getSeconds())}`
-}
-
-// 小于10补0
-function zero(d){
- return d.toString().padStart(2,'0')
+ if(matterData.date && type(matterData.date) === 'date') {
+ matterData.date = repairDate(matterData.date) // 修复时间格式
+ }
+ const newData = jsonToYaml.stringify(matterData).replace(/\n\s{2}/g,"\n").replace(/"/g,"") + '---\r\n' + fileMatterObj.content;
+ fs.writeFileSync(file.filePath, newData); // 写入
+ console.log(`update frontmatter:${file.filePath} `)
+ })
}
diff --git a/utils/frontmatter.js b/utils/frontmatter.js
index 521ab6a..4c97f47 100644
--- a/utils/frontmatter.js
+++ b/utils/frontmatter.js
@@ -7,6 +7,7 @@ const matter = require('gray-matter'); // FrontMatter解析器 https://github.co
const jsonToYaml = require('json2yaml')
const arg = process.argv.splice(2)[0]; // 获取命令行传入的参数
const readFileList = require('./modules/readFileList');
+const { type, repairDate, dateFormat} = require('./modules/fn');
main();
@@ -29,7 +30,7 @@ function main() {
const dateStr = dateFormat(stat.birthtime);// 文件的创建时间
const newData = `---\r\ntitle: ${file.name}\r\ndate: ${dateStr}\r\npermalink: ${file.permalink}\r\n---\r\n` + fileMatterObj.content;
fs.writeFileSync(file.filePath, newData); // 写入
- console.log(`write FrontMatter:${file.filePath} `)
+ console.log(`write frontmatter:${file.filePath} `)
} else { // 已有FrontMatter
const matterData = fileMatterObj.data;
@@ -56,9 +57,9 @@ function main() {
if(matterData.date && type(matterData.date) === 'date') {
matterData.date = repairDate(matterData.date) // 修复时间格式
}
- const newData = jsonToYaml.stringify(matterData).replace(/\n\s{2}/g,"\n") + '---\r\n' + fileMatterObj.content;
+ const newData = jsonToYaml.stringify(matterData).replace(/\n\s{2}/g,"\n").replace(/"/g,"") + '---\r\n' + fileMatterObj.content;
fs.writeFileSync(file.filePath, newData); // 写入
- console.log(`update FrontMatter:${file.filePath} `)
+ console.log(`update frontmatter:${file.filePath} `)
}
@@ -71,7 +72,7 @@ function main() {
// 修复date时区和格式被修改的问题 (并非更新date的值)
matterData.date = repairDate(matterData.date);
- const newData2 = jsonToYaml.stringify(JSON.parse(JSON.stringify(matterData))).replace(/\n\s{2}/g,"\n") + '---\r\n' + fileMatterObj.content;
+ const newData2 = jsonToYaml.stringify(JSON.parse(JSON.stringify(matterData))).replace(/\n\s{2}/g,"\n").replace(/"/g,"") + '---\r\n' + fileMatterObj.content;
fs.writeFileSync(file.filePath, newData2); // 写入
console.log(`update FrontMatter title and permalink:${file.filePath}`)
}
@@ -82,24 +83,4 @@ function main() {
}
-// 类型判断
-function type(o){
- var s = Object.prototype.toString.call(o)
- return s.match(/\[object (.*?)\]/)[1].toLowerCase()
-}
- // 修复date时区格式的问题
-function repairDate(date) {
- date = new Date(date);
- return `${date.getUTCFullYear()}-${zero(date.getUTCMonth()+1)}-${zero(date.getUTCDate())} ${zero(date.getUTCHours())}:${zero(date.getUTCMinutes())}:${zero(date.getUTCSeconds())}`;
-}
-
-// 日期的格式
-function dateFormat(date) {
- return `${date.getFullYear()}-${zero(date.getMonth()+1)}-${zero(date.getDate())} ${zero(date.getHours())}:${zero(date.getMinutes())}:${zero(date.getSeconds())}`
-}
-
-// 小于10补0
-function zero(d){
- return d.toString().padStart(2,'0')
-}
diff --git a/utils/modules/fn.js b/utils/modules/fn.js
new file mode 100644
index 0000000..48cbbd1
--- /dev/null
+++ b/utils/modules/fn.js
@@ -0,0 +1,21 @@
+// 类型判断
+exports.type = function (o){
+ var s = Object.prototype.toString.call(o)
+ return s.match(/\[object (.*?)\]/)[1].toLowerCase()
+}
+
+ // 修复date时区格式的问题
+ exports.repairDate = function (date) {
+ date = new Date(date);
+ return `${date.getUTCFullYear()}-${zero(date.getUTCMonth()+1)}-${zero(date.getUTCDate())} ${zero(date.getUTCHours())}:${zero(date.getUTCMinutes())}:${zero(date.getUTCSeconds())}`;
+}
+
+// 日期的格式
+exports.dateFormat = function (date) {
+ return `${date.getFullYear()}-${zero(date.getMonth()+1)}-${zero(date.getDate())} ${zero(date.getHours())}:${zero(date.getMinutes())}:${zero(date.getSeconds())}`
+}
+
+// 小于10补0
+function zero(d){
+ return d.toString().padStart(2,'0')
+}
\ No newline at end of file
-
-
+
+
-
-
+
{{ feature.title }}
@@ -42,51 +43,57 @@
-
-
-
-
-
+
@@ -94,13 +101,16 @@
\ No newline at end of file
+
diff --git a/theme-vdoing/components/Home改变中.vue b/theme-vdoing/components/Home改变中.vue
deleted file mode 100644
index 18ee37e..0000000
--- a/theme-vdoing/components/Home改变中.vue
+++ /dev/null
@@ -1,485 +0,0 @@
-
-
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
diff --git a/theme-vdoing/components/Home未改版.vue b/theme-vdoing/components/Home未改版.vue
new file mode 100644
index 0000000..cf5aa49
--- /dev/null
+++ b/theme-vdoing/components/Home未改版.vue
@@ -0,0 +1,468 @@
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
- {{ homeData.heroText || $title || 'Hello' }}
-{{ homeData.tagline || $description || 'Welcome to your VuePress site' }}
-
-
-
-
-
-
-
-
-
- {{ feature.title }}
-{{ feature.details }}
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- {{ feature.title }}
-{{ feature.details }}
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
\ No newline at end of file
diff --git a/theme-vdoing/components/Timeline.vue b/theme-vdoing/components/Timeline.vue
index 52e9ab8..6da8d25 100644
--- a/theme-vdoing/components/Timeline.vue
+++ b/theme-vdoing/components/Timeline.vue
@@ -54,9 +54,6 @@ export default {
},
mounted() {
const fmData = this.$frontmatter.pageComponent.data
- if(fmData && fmData.tagBgColor) {
- this.pageData.tagBgColor = fmData.tagBgColor
- }
if(fmData && fmData.slogan) {
this.pageData.slogan = fmData.slogan
}
diff --git a/utils/config.yaml b/utils/config.yaml
deleted file mode 100644
index c58d46b..0000000
--- a/utils/config.yaml
+++ /dev/null
@@ -1,14 +0,0 @@
-#批量添加和修改front matter配置文件
-
-# 防止误操作,每次批量修改时手动改成true,修改完成后会自动变成false
-editable: true
-
-# 需要批量处理的路径,docs文件夹内的文件夹
-path:
- - 01.前端
- - 25.JavaScript文章
-
- # 要写入front matter的数据
-data:
- tags:
- - js
\ No newline at end of file
diff --git a/utils/config.yml b/utils/config.yml
new file mode 100644
index 0000000..484c140
--- /dev/null
+++ b/utils/config.yml
@@ -0,0 +1,12 @@
+#批量添加和修改、删除front matter配置文件
+
+# 需要批量处理的路径,docs文件夹内的文件夹
+path:
+ - 《ES6 教程》笔记
+
+# delete: true # 是否删除字段操作
+
+ # 要写入或删除front matter的数据 (front matter中没有的数据则添加,已有的数据则覆盖。如果是删除操作会忽略字段的值。)
+data:
+ author:
+ name: 阮一峰
\ No newline at end of file
diff --git a/utils/editFrontmatter.js b/utils/editFrontmatter.js
index 413250a..4f9729e 100644
--- a/utils/editFrontmatter.js
+++ b/utils/editFrontmatter.js
@@ -1,126 +1,62 @@
/**
- * 批量添加和修改front matter
+ * 批量添加和修改front matter ,需要 ./config.yml 配置文件的配合。
*/
const fs = require('fs'); // 文件模块
const path = require('path'); // 路径模块
-const logger = require('tracer').colorConsole(); // 控制台工具(用于控制台打印信息包含时间、打印类型、文件及代码行号、对象、颜色)
const matter = require('gray-matter'); // FrontMatter解析器 https://github.com/jonschlinkert/gray-matter
const jsonToYaml = require('json2yaml')
const yamlToJs = require('yamljs')
-const arg = process.argv.splice(2)[0]; // 获取命令行传入的参数
+const inquirer = require('inquirer') // 命令行操作
+
const readFileList = require('./modules/readFileList');
+const { type, repairDate} = require('./modules/fn');
-const configFile = require('./config.yaml')
+const configPath = path.join(__dirname, 'config.yml') // 配置文件的路径
-// const configStr = fs.readFileSync(, 'utf8');
-console.log(fs.readFileSync(configFile).toString())
-// const configDate = yamlToJs.parse(fs.readFileSync(configFile).toString())
-
-// const fm = {
-// data: {
-// tags: ['js']
-// },
-// path: ['01.前端','25.JavaScript文章22']
-// }
-
-// console.log(config)
-
-// const filePath = path.join(__dirname, '..', 'docs', ...config.path);
-
-// main();
+main();
/**
* 主体函数
*/
-function main() {
+async function main() {
+
+ const promptList = [{
+ type: "confirm",
+ message: "批量操作frontmatter有修改数据的风险,确定要继续吗?",
+ name: "edit",
+ }];
+ let edit = true;
+
+ await inquirer.prompt(promptList).then(answers => {
+ edit = answers.edit
+ })
+
+ if(!edit) { // 退出操作
+ return
+ }
+
+ const config = yamlToJs.load(configPath) // 解析配置文件的数据转为js对象
+ const filePath = path.join(__dirname, '..', 'docs', ...config.path); // 要批量修改的文件路径
const files = readFileList(filePath); // 读取所有md文件数据
- console.log(files)
+ files.forEach(file => {
+ let dataStr = fs.readFileSync(file.filePath, 'utf8');// 读取每个md文件的内容
+ const fileMatterObj = matter(dataStr) // 解析md文件的front Matter。 fileMatterObj => {content:'剔除frontmatter后的文件内容字符串', data:{
+
+
+
+
+
+
+
+
+
+
+
+
+ {{ data.heroText || $title || 'Hello' }}
+{{ data.tagline || $description || 'Welcome to your VuePress site' }}
+
+
+
+
+
+
+
+
+
+ {{ feature.title }}
+{{ feature.details }}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ {{ feature.title }}
+{{ feature.details }}
+
+
+
+
+
+
+
+
+
+
+
+
+
+