Join our webinar on Wednesday, June 26, at 1pm EDTHow Chia Mitigates Risk in the Crypto Industry.Register
Socket
Socket
Sign inDemoInstall

vuepress-theme-vdoing

Package Overview
Dependencies
265
Maintainers
1
Versions
80
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.10.4 to 1.11.0

49

node_utils/setFrontmatter.js

@@ -18,9 +18,11 @@ const fs = require('fs'); // 文件模块

function setFrontmatter(sourceDir, themeConfig) {
const { isCategory, isTag, categoryText = '随笔', extendFrontmatter } = themeConfig
const files = readFileList(sourceDir) // 读取所有md文件数据
// 扩展自定义生成frontmatter
const extendFrontmatterStr = extendFrontmatter ?
jsonToYaml.stringify(extendFrontmatter)
.replace(/\n\s{2}/g, "\n")
.replace(/"|---\n/g, "")
: '';
const isCategory = themeConfig.category
const isTag = themeConfig.tag
const categoryText = themeConfig.categoryText || '随笔'
const files = readFileList(sourceDir); // 读取所有md文件数据
files.forEach(file => {

@@ -53,6 +55,2 @@ let dataStr = fs.readFileSync(file.filePath, 'utf8');// 读取每个md文件内容

// 注意下面这些反引号字符串的格式会映射到文件
// const cateStr = isCategory === false ? '' : `
// categories:
// - ${categories[0]}${categories[1] ? os.EOL + ' - ' + categories[1] : ''}`;
const tagsStr = isTag === false ? '' : `

@@ -66,3 +64,3 @@ tags:

permalink: ${getPermalink()}${file.filePath.indexOf('_posts') > -1 ? os.EOL + 'sidebar: auto' : ''}${cateStr}${tagsStr}
---`;
${extendFrontmatterStr}---`;

@@ -73,4 +71,4 @@ fs.writeFileSync(file.filePath, `${fmData}${os.EOL}${fileMatterObj.content}`); // 写入

} else { // 已有FrontMatter
const matterData = fileMatterObj.data;
let mark = false;
let matterData = fileMatterObj.data;
let hasChange = false;

@@ -80,3 +78,3 @@ // 已有FrontMatter,但是没有title、date、permalink、categories、tags数据的

matterData.title = file.name;
mark = true;
hasChange = true;
}

@@ -87,3 +85,3 @@

matterData.date = dateFormat(getBirthtime(stat));
mark = true;
hasChange = true;
}

@@ -93,3 +91,3 @@

matterData.permalink = getPermalink();
mark = true;
hasChange = true;
}

@@ -99,3 +97,3 @@

matterData.sidebar = "auto";
mark = true;
hasChange = true;
}

@@ -106,12 +104,21 @@

matterData.categories = getCategories(file, categoryText)
mark = true;
hasChange = true;
}
if (isTag !== false && !matterData.hasOwnProperty('tags')) { // 标签
matterData.tags = [''];
mark = true;
hasChange = true;
}
}
if (mark) {
// 扩展自动生成frontmatter的字段
if (type(extendFrontmatter) === 'object') {
Object.keys(extendFrontmatter).forEach(keyName => {
if (!matterData.hasOwnProperty(keyName)) {
matterData[keyName] = extendFrontmatter[keyName]
hasChange = true;
}
})
}
if (hasChange) {
if (matterData.date && type(matterData.date) === 'date') {

@@ -118,0 +125,0 @@ matterData.date = repairDate(matterData.date) // 修复时间格式

{
"name": "vuepress-theme-vdoing",
"version": "1.10.4",
"version": "1.11.0",
"description": "Vdoing theme for VuePress. 一个基于VuePress的知识管理兼博客主题。",

@@ -5,0 +5,0 @@ "author": {

@@ -135,2 +135,10 @@ import { DefaultThemeConfig } from '@vuepress/types'

/**
* 扩展自动生成frontmatter。
* 说明:当md文件的frontmatter不存在相应的字段时将自动添加。不会覆盖已有的数据。
*/
extendFrontmatter?: {
[key: string]: any
}
/**
* 自定义hmtl(广告)模块

@@ -137,0 +145,0 @@ * @see: https://doc.xugaoyi.com/pages/a20ce8/#htmlmodules

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc