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", "deploy": "bash deploy.sh",
"editFm": "node utils/editFrontmatter.js", "editFm": "node utils/editFrontmatter.js",
"baiduPush": "node utils/baiduPush.js https://xugaoyi.com && bash baiduPush.sh", "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", "license": "MIT",
"devDependencies": { "devDependencies": {
@ -21,7 +22,7 @@
"vuepress-plugin-one-click-copy": "^1.0.2", "vuepress-plugin-one-click-copy": "^1.0.2",
"vuepress-plugin-thirdparty-search": "^1.0.2", "vuepress-plugin-thirdparty-search": "^1.0.2",
"vuepress-plugin-zooming": "^1.1.7", "vuepress-plugin-zooming": "^1.1.7",
"vuepress-theme-vdoing": "^1.5.3", "vuepress-theme-vdoing": "^1.6.0",
"yamljs": "^0.3.0" "yamljs": "^0.3.0"
}, },
"dependencies": { "dependencies": {

View File

@ -38,6 +38,19 @@
>{{articleInfo.classify2}}</router-link> >{{articleInfo.classify2}}</router-link>
<span v-else>{{articleInfo.classify2}}</span> <span v-else>{{articleInfo.classify2}}</span>
</li> </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> </ul>
<div class="info"> <div class="info">
<div <div
@ -103,9 +116,11 @@ export default {
// //
const relativePathArr = relativePath.split('/') const relativePathArr = relativePath.split('/')
const classifyArr = relativePathArr[0].split('.') const classifyArr = relativePathArr[0].split('.')
const classify1 = classifyArr.length > 1 ? classifyArr[1] : classifyArr[0] // const classify1 = classifyArr.length > 1 ? classifyArr[1] : classifyArr[0] //
const classify2 = relativePathArr.length > 2 ? relativePathArr[1].split('.')[1] : undefined// 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// const cataloguePermalink = sidebar && sidebar.catalogue ? sidebar.catalogue[classify1] : undefined//
@ -119,6 +134,7 @@ export default {
date, date,
classify1, classify1,
classify2, classify2,
classify3,
cataloguePermalink, cataloguePermalink,
author, author,
categories categories

View File

@ -30,6 +30,7 @@
v-else-if="type(item) === 'object'" v-else-if="type(item) === 'object'"
:key="index" :key="index"
> >
<!-- 一级目录 -->
<dt :id="anchorText = item.title"> <dt :id="anchorText = item.title">
<a <a
:href="`#${anchorText}`" :href="`#${anchorText}`"
@ -38,11 +39,40 @@
{{`${index+1}. ${item.title}`}} {{`${index+1}. ${item.title}`}}
</dt> </dt>
<dd> <dd>
<router-link <!-- 二级目录 -->
:to="s[2]" <template
v-for="(s, i) in item.children" v-for="(c, i) in item.children"
:key="i" >
>{{`${index+1}-${i+1}. ${s[1]}`}}</router-link> <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> </dd>
</dl> </dl>
</template> </template>
@ -88,7 +118,7 @@ export default {
if (!catalogueList) { if (!catalogueList) {
console.error('未获取到目录数据请查看front matter中设置的key是否正确。') console.error('未获取到目录数据请查看front matter中设置的key是否正确。')
} }
console.log(catalogueList)
return catalogueList return catalogueList
}, },
type (o) { // type (o) { //
@ -154,4 +184,15 @@ dl, dd
width 50% width 50%
@media (max-width $MQMobileNarrow) @media (max-width $MQMobileNarrow)
width 100% 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> </style>

View File

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

View File

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

View File

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