This commit is contained in:
xugaoyi 2020-12-10 21:59:57 +08:00
parent 8aaa310abb
commit 0e1a6fd0f7
6 changed files with 126 additions and 34 deletions

View File

@ -7,7 +7,8 @@
"deploy": "bash deploy.sh",
"editFm": "node utils/editFrontmatter.js",
"baiduPush": "node utils/baiduPush.js https://xugaoyi.com && bash baiduPush.sh",
"publish": "cd theme-vdoing && npm publish && cd ../ && npm update vuepress-theme-vdoing"
"publish": "cd theme-vdoing && npm publish && cd ../ && npm run updateTheme",
"updateTheme": "npm uninstall vuepress-theme-vdoing && rm -rf node_modules && npm i && npm i vuepress-theme-vdoing"
},
"license": "MIT",
"devDependencies": {
@ -21,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.5.3",
"vuepress-theme-vdoing": "^1.6.0",
"yamljs": "^0.3.0"
},
"dependencies": {

View File

@ -38,6 +38,19 @@
>{{articleInfo.classify2}}</router-link>
<span v-else>{{articleInfo.classify2}}</span>
</li>
<li v-if="articleInfo.classify3">
<router-link
v-if="articleInfo.cataloguePermalink"
:to="articleInfo.cataloguePermalink + '/#' + articleInfo.classify3"
:title="articleInfo.classify1+'#'+articleInfo.classify3"
>{{articleInfo.classify3}}</router-link>
<router-link
v-else-if="$themeConfig.category !== false"
:to="`/categories/?category=${encodeURIComponent(articleInfo.classify3)}`"
title="分类"
>{{articleInfo.classify3}}</router-link>
<span v-else>{{articleInfo.classify3}}</span>
</li>
</ul>
<div class="info">
<div
@ -103,9 +116,11 @@ export default {
//
const relativePathArr = relativePath.split('/')
const classifyArr = relativePathArr[0].split('.')
const classify1 = classifyArr.length > 1 ? classifyArr[1] : classifyArr[0] //
const classify2 = relativePathArr.length > 2 ? relativePathArr[1].split('.')[1] : undefined//
const classify3 = relativePathArr.length > 3 ? relativePathArr[2].split('.')[1] : undefined//
const cataloguePermalink = sidebar && sidebar.catalogue ? sidebar.catalogue[classify1] : undefined//
@ -119,6 +134,7 @@ export default {
date,
classify1,
classify2,
classify3,
cataloguePermalink,
author,
categories

View File

@ -30,6 +30,7 @@
v-else-if="type(item) === 'object'"
:key="index"
>
<!-- 一级目录 -->
<dt :id="anchorText = item.title">
<a
:href="`#${anchorText}`"
@ -38,11 +39,40 @@
{{`${index+1}. ${item.title}`}}
</dt>
<dd>
<router-link
:to="s[2]"
v-for="(s, i) in item.children"
:key="i"
>{{`${index+1}-${i+1}. ${s[1]}`}}</router-link>
<!-- 二级目录 -->
<template
v-for="(c, i) in item.children"
>
<template
v-if="type(c) === 'array'"
>
<router-link
:to="c[2]"
:key="i"
>{{`${index+1}-${i+1}. ${c[1]}`}}</router-link>
</template>
<!-- 三级目录 -->
<div
v-else-if="type(c) === 'object'"
:key="i"
class="sub-cat-wrap"
>
<div :id="anchorText = c.title" class="sub-title">
<a
:href="`#${anchorText}`"
class="header-anchor"
>#</a>
{{`${index+1}-${i+1}. ${c.title}`}}
</div>
<router-link
v-for="(cc, ii) in c.children"
:to="cc[2]"
:key="`${index+1}-${i+1}-${ii+1}`"
>
{{`${index+1}-${i+1}-${ii+1}. ${cc[1]}`}}
</router-link>
</div>
</template>
</dd>
</dl>
</template>
@ -88,7 +118,7 @@ export default {
if (!catalogueList) {
console.error('未获取到目录数据请查看front matter中设置的key是否正确。')
}
console.log(catalogueList)
return catalogueList
},
type (o) { //
@ -154,4 +184,15 @@ dl, dd
width 50%
@media (max-width $MQMobileNarrow)
width 100%
.sub-cat-wrap
margin 5px 0 8px 0
font-size .9rem
.sub-title
margin-top -($navbarHeight)
padding-top $navbarHeight
margin-bottom 5px
font-size 1rem
&:hover
.header-anchor
opacity 1
</style>

View File

@ -81,7 +81,7 @@ export default {
&.is-sub-group
padding-left 0
& > .sidebar-heading
font-size 0.95em
font-size 1em
line-height 1.4
font-weight normal
padding-left 2rem
@ -90,7 +90,7 @@ export default {
& > .sidebar-group-items
padding-left 1rem
& > li > .sidebar-link
font-size 0.95em
font-size 0.98em
border-left none
&.depth-2
& > .sidebar-heading

View File

@ -28,30 +28,60 @@ function setFrontmatter (sourceDir, themeConfig) {
// fileMatterObj => {content:'剔除frontmatter后的文件内容字符串', data:{<frontmatter对象>}, ...}
const fileMatterObj = matter(dataStr);
if (Object.keys(fileMatterObj.data).length === 0) { // 未定义FrontMatter数据
const stat = fs.statSync(file.filePath);
const dateStr = dateFormat(getBirthtime(stat));// 文件的创建时间
const categories = getCategories(file, categoryText)
if (Object.keys(fileMatterObj.data).length === 0) {
// 未定义FrontMatter数据
const stat = fs.statSync(file.filePath)
const dateStr = dateFormat(
getBirthtime(stat)
) // 文件的创建时间
const categories = getCategories(
file,
categoryText
)
// 注意下面这些反引号字符串的格式会映射到文件
const cateStr = isCategory === false ? '' : `
categories:
- ${categories[0]}${categories[1] ? '\r\n - ' + categories[1] : ''}`;
let cateLabelStr = ''
categories.forEach(((item)) => {
cateLabelStr += '\r\n - ' + item
})
const tagsStr = isTag === false ? '' : `
let cateStr = ''
if (!(isCategory === false)) {
cateStr = '\r\ncategories:' + cateLabelStr
}
// 注意下面这些反引号字符串的格式会映射到文件
// const cateStr = isCategory === false ? '' : `
// categories:
// - ${categories[0]}${categories[1] ? '\r\n - ' + categories[1] : ''}`;
const tagsStr =
isTag === false
? ''
: `
tags:
- `;
- `
const fmData = `---
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
? '\r\nsidebar: auto'
: ''
}${cateStr}${tagsStr}
---`
fs.writeFileSync(file.filePath, `${fmData}\r\n${fileMatterObj.content}`); // 写入
log(chalk.blue('tip ') + chalk.green(`write frontmatter(写入frontmatter)${file.filePath} `))
} else { // 已有FrontMatter
fs.writeFileSync(
file.filePath,
`${fmData}\r\n${fileMatterObj.content}`
) // 写入
log(
chalk.blue('tip ') +
chalk.green(
`write frontmatter(写入frontmatter)${file.filePath} `
)
)
} else { // 已有FrontMatter
const matterData = fileMatterObj.data;
let mark = false;
@ -106,13 +136,17 @@ permalink: ${getPermalink()}${file.filePath.indexOf('_posts') > -1 ? '\r\nsideba
function getCategories (file, categoryText) {
let categories = []
if (file.filePath.indexOf('_posts') === -1) { // 不在_posts文件夹
const filePathArr = file.filePath.split(path.sep) // path.sep用于兼容不同系统下的路径斜杠
const c = filePathArr[filePathArr.length - 3].split('.').pop() // 获取分类1
if (c !== 'docs') {
categories.push(c)
if (file.filePath.indexOf('_posts') === -1) {
// 不在_posts文件夹
let filePathArr = file.filePath.split(path.sep) // path.sep用于兼容不同系统下的路径斜杠
filePathArr.pop()
let ind = filePathArr.indexOf('docs')
if (ind !== -1) {
while (filePathArr[++ind] !== undefined) {
categories.push(filePathArr[ind].split('.').pop()) // 获取分类
}
}
categories.push(filePathArr[filePathArr.length - 2].split('.').pop()) // 获取分类2
} else {
categories.push(categoryText)
}

View File

@ -1,6 +1,6 @@
{
"name": "vuepress-theme-vdoing",
"version": "1.5.3",
"version": "1.6.0",
"description": "Vdoing theme for VuePress. 一个基于VuePress的知识管理兼博客主题。",
"author": {
"name": "gaoyi(Evan) Xu"