v1.8.4
This commit is contained in:
parent
03bbcada4f
commit
45d98731b4
|
|
@ -22,7 +22,7 @@
|
|||
"vuepress-plugin-one-click-copy": "^1.0.2",
|
||||
"vuepress-plugin-thirdparty-search": "^1.0.2",
|
||||
"vuepress-plugin-zooming": "^1.1.7",
|
||||
"vuepress-theme-vdoing": "^1.8.3",
|
||||
"vuepress-theme-vdoing": "^1.8.4",
|
||||
"yamljs": "^0.3.0"
|
||||
},
|
||||
"dependencies": {
|
||||
|
|
|
|||
|
|
@ -85,7 +85,7 @@ function mapTocToPostSidebar (root) {
|
|||
}
|
||||
|
||||
const contentStr = fs.readFileSync(file, 'utf8') // 读取md文件内容,返回字符串
|
||||
const { data } = matter(contentStr) // 解析出front matter数据
|
||||
const { data } = matter(contentStr, {}) // 解析出front matter数据
|
||||
const permalink = data.permalink || ''
|
||||
if (data.title) {
|
||||
title = data.title
|
||||
|
|
@ -135,7 +135,7 @@ function mapTocToSidebar (root, collapsable, prefix = '') {
|
|||
return;
|
||||
}
|
||||
const contentStr = fs.readFileSync(file, 'utf8') // 读取md文件内容,返回字符串
|
||||
const { data } = matter(contentStr) // 解析出front matter数据
|
||||
const { data } = matter(contentStr, {}) // 解析出front matter数据
|
||||
const permalink = data.permalink || ''
|
||||
|
||||
// 目录页对应的永久链接,用于给面包屑提供链接
|
||||
|
|
|
|||
|
|
@ -7,10 +7,10 @@ const readFileList = require('./modules/readFileList');
|
|||
const { type, repairDate, dateFormat } = require('./modules/fn');
|
||||
const log = console.log
|
||||
const path = require('path');
|
||||
const os = require('os');
|
||||
|
||||
const PREFIX = '/pages/'
|
||||
|
||||
|
||||
/**
|
||||
* 给.md文件设置frontmatter(标题、日期、永久链接等数据)
|
||||
*/
|
||||
|
|
@ -26,7 +26,7 @@ function setFrontmatter (sourceDir, themeConfig) {
|
|||
let dataStr = fs.readFileSync(file.filePath, 'utf8');// 读取每个md文件内容
|
||||
|
||||
// fileMatterObj => {content:'剔除frontmatter后的文件内容字符串', data:{<frontmatter对象>}, ...}
|
||||
const fileMatterObj = matter(dataStr);
|
||||
const fileMatterObj = matter(dataStr, {});
|
||||
|
||||
if (Object.keys(fileMatterObj.data).length === 0) { // 未定义FrontMatter数据
|
||||
const stat = fs.statSync(file.filePath);
|
||||
|
|
@ -40,18 +40,18 @@ function setFrontmatter (sourceDir, themeConfig) {
|
|||
|
||||
let cateLabelStr = '';
|
||||
categories.forEach(item => {
|
||||
cateLabelStr += '\r\n - ' + item
|
||||
cateLabelStr += os.EOL + ' - ' + item
|
||||
});
|
||||
|
||||
let cateStr = '';
|
||||
if (!(isCategory === false)) {
|
||||
cateStr = '\r\ncategories:' + cateLabelStr
|
||||
cateStr = os.EOL + 'categories:' + cateLabelStr
|
||||
};
|
||||
|
||||
// 注意下面这些反引号字符串的格式会映射到文件
|
||||
// const cateStr = isCategory === false ? '' : `
|
||||
// categories:
|
||||
// - ${categories[0]}${categories[1] ? '\r\n - ' + categories[1] : ''}`;
|
||||
// - ${categories[0]}${categories[1] ? os.EOL + ' - ' + categories[1] : ''}`;
|
||||
|
||||
const tagsStr = isTag === false ? '' : `
|
||||
tags:
|
||||
|
|
@ -60,10 +60,10 @@ tags:
|
|||
const fmData = `---
|
||||
title: ${file.name}
|
||||
date: ${dateStr}
|
||||
permalink: ${getPermalink()}${file.filePath.indexOf('_posts') > -1 ? '\r\nsidebar: auto' : ''}${cateStr}${tagsStr}
|
||||
permalink: ${getPermalink()}${file.filePath.indexOf('_posts') > -1 ? os.EOL + 'sidebar: auto' : ''}${cateStr}${tagsStr}
|
||||
---`;
|
||||
|
||||
fs.writeFileSync(file.filePath, `${fmData}\r\n${fileMatterObj.content}`); // 写入
|
||||
fs.writeFileSync(file.filePath, `${fmData}${os.EOL}${fileMatterObj.content}`); // 写入
|
||||
log(chalk.blue('tip ') + chalk.green(`write frontmatter(写入frontmatter):${file.filePath} `))
|
||||
|
||||
} else { // 已有FrontMatter
|
||||
|
|
@ -108,7 +108,7 @@ permalink: ${getPermalink()}${file.filePath.indexOf('_posts') > -1 ? '\r\nsideba
|
|||
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;
|
||||
const newData = jsonToYaml.stringify(matterData).replace(/\n\s{2}/g, "\n").replace(/"/g, "") + '---' + os.EOL + fileMatterObj.content;
|
||||
fs.writeFileSync(file.filePath, newData); // 写入
|
||||
log(chalk.blue('tip ') + chalk.green(`write frontmatter(写入frontmatter):${file.filePath} `))
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "vuepress-theme-vdoing",
|
||||
"version": "1.8.3",
|
||||
"version": "1.8.4",
|
||||
"description": "Vdoing theme for VuePress. 一个基于VuePress的知识管理兼博客主题。",
|
||||
"author": {
|
||||
"name": "gaoyi(Evan) Xu"
|
||||
|
|
|
|||
Loading…
Reference in New Issue