From b6ecfe03e241b9cb46fd23f819c8072cc57b9c4d Mon Sep 17 00:00:00 2001 From: xugaoyi <894072666@qq.com> Date: Fri, 8 Apr 2022 18:35:35 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=91=BD=E5=90=8D=E7=BA=A6=E5=AE=9A?= =?UTF-8?q?=E5=85=BC=E5=AE=B9=E6=96=87=E4=BB=B6=E5=90=8D=E4=B8=AD=E9=97=B4?= =?UTF-8?q?=E6=9C=89'.'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 2 +- vdoing/components/ArticleInfo.vue | 10 ++++++++-- vdoing/node_utils/getSidebarData.js | 23 +++++++++++++++++++++-- vdoing/node_utils/modules/readFileList.js | 18 ++++++++++-------- vdoing/node_utils/setFrontmatter.js | 5 ++++- vdoing/package.json | 2 +- vdoing/styles/index.styl | 14 ++++++++------ 7 files changed, 53 insertions(+), 21 deletions(-) diff --git a/package.json b/package.json index 1277be4335..30608507d8 100644 --- a/package.json +++ b/package.json @@ -24,7 +24,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.10.2", + "vuepress-theme-vdoing": "^1.10.3", "yamljs": "^0.3.0" } } diff --git a/vdoing/components/ArticleInfo.vue b/vdoing/components/ArticleInfo.vue index 6665f5d6c8..f2093c0a56 100644 --- a/vdoing/components/ArticleInfo.vue +++ b/vdoing/components/ArticleInfo.vue @@ -93,12 +93,18 @@ export default { // 分类采用解析文件夹地址名称的方式 (即使关闭分类功能也可以正确跳转目录页) const relativePathArr = relativePath.split('/') - const classifyArr = relativePathArr[0].split('.') + // const classifyArr = relativePathArr[0].split('.') relativePathArr.forEach((item, index) => { const nameArr = item.split('.') + if (index !== relativePathArr.length - 1) { - this.classifyList.push(nameArr[1] || nameArr[0] || '') + if (nameArr === 1) { + this.classifyList.push(nameArr[0]) + } else { + const firstDotIndex = item.indexOf('.'); + this.classifyList.push(item.substring(firstDotIndex + 1) || '') + } } }) diff --git a/vdoing/node_utils/getSidebarData.js b/vdoing/node_utils/getSidebarData.js index 02d95823ec..ab52ffda24 100644 --- a/vdoing/node_utils/getSidebarData.js +++ b/vdoing/node_utils/getSidebarData.js @@ -118,7 +118,26 @@ function mapTocToSidebar(root, collapsable, prefix = '') { if (filename === '.DS_Store') { // 过滤.DS_Store文件 return } - let [order, title, type] = filename.split('.'); + // let [order, title, type] = filename.split('.'); + + const fileNameArr = filename.split('.') + const isDir = stat.isDirectory() + let order = '', title = '', type = ''; + if (fileNameArr.length === 2) { + order = fileNameArr[0]; + title = fileNameArr[1]; + } else { + const firstDotIndex = filename.indexOf('.'); + const lastDotIndex = filename.lastIndexOf('.'); + order = filename.substring(0, firstDotIndex); + type = filename.substring(lastDotIndex + 1); + if (isDir) { + title = filename.substring(firstDotIndex + 1); + } else { + title = filename.substring(firstDotIndex + 1, lastDotIndex); + } + } + order = parseInt(order, 10); if (isNaN(order) || order < 0) { log(chalk.yellow(`warning: 该文件 "${file}" 序号出错,请填写正确的序号`)) @@ -127,7 +146,7 @@ function mapTocToSidebar(root, collapsable, prefix = '') { if (sidebar[order]) { // 判断序号是否已经存在 log(chalk.yellow(`warning: 该文件 "${file}" 的序号在同一级别中重复出现,将会被覆盖`)) } - if (stat.isDirectory()) { // 是文件夹目录 + if (isDir) { // 是文件夹目录 sidebar[order] = { title, collapsable, // 是否可折叠,默认true diff --git a/vdoing/node_utils/modules/readFileList.js b/vdoing/node_utils/modules/readFileList.js index 74722962ac..4e8d20d3cd 100644 --- a/vdoing/node_utils/modules/readFileList.js +++ b/vdoing/node_utils/modules/readFileList.js @@ -6,7 +6,7 @@ const path = require('path'); // 路径模块 const chalk = require('chalk') // 命令行打印美化 const log = console.log -function readFileList (dir, filesList = []) { +function readFileList(dir, filesList = []) { const files = fs.readdirSync(dir); files.forEach((item, index) => { let filePath = path.join(dir, item); @@ -16,18 +16,20 @@ function readFileList (dir, filesList = []) { } else { if (path.basename(dir) !== 'docs') { // 过滤docs目录级下的文件 - const fileNameArr = path.basename(filePath).split('.') + const filename = path.basename(filePath) + const fileNameArr = filename.split('.') + const firstDotIndex = filename.indexOf('.'); + const lastDotIndex = filename.lastIndexOf('.'); + let name = null, type = null; if (fileNameArr.length === 2) { // 没有序号的文件 name = fileNameArr[0] type = fileNameArr[1] - } else if (fileNameArr.length === 3) { // 有序号的文件 - name = fileNameArr[1] - type = fileNameArr[2] - } else { // 超过两个‘.’的 - log(chalk.yellow(`warning: 该文件 "${filePath}" 没有按照约定命名,将忽略生成相应数据。`)) - return + } else if (fileNameArr.length >= 3) { // 有序号的文件(或文件名中间有'.') + name = filename.substring(firstDotIndex + 1, lastDotIndex) + type = filename.substring(lastDotIndex + 1) } + if (type === 'md') { // 过滤非md文件 filesList.push({ name, diff --git a/vdoing/node_utils/setFrontmatter.js b/vdoing/node_utils/setFrontmatter.js index 9ad34b984e..2d62f48932 100644 --- a/vdoing/node_utils/setFrontmatter.js +++ b/vdoing/node_utils/setFrontmatter.js @@ -129,7 +129,10 @@ function getCategories(file, categoryText) { let ind = filePathArr.indexOf('docs') if (ind !== -1) { while (filePathArr[++ind] !== undefined) { - categories.push(filePathArr[ind].split('.').pop()) // 获取分类 + const item = filePathArr[ind] + const firstDotIndex = item.indexOf('.'); + categories.push(item.substring(firstDotIndex + 1) || '') // 获取分类 + // categories.push(filePathArr[ind].split('.').pop()) // 获取分类 } } } else { diff --git a/vdoing/package.json b/vdoing/package.json index 8e20471e6c..ae2f11fd39 100644 --- a/vdoing/package.json +++ b/vdoing/package.json @@ -1,6 +1,6 @@ { "name": "vuepress-theme-vdoing", - "version": "1.10.2", + "version": "1.10.3", "description": "Vdoing theme for VuePress. 一个基于VuePress的知识管理兼博客主题。", "author": { "name": "gaoyi(Evan) Xu" diff --git a/vdoing/styles/index.styl b/vdoing/styles/index.styl index 06cb182790..1134997d04 100644 --- a/vdoing/styles/index.styl +++ b/vdoing/styles/index.styl @@ -222,12 +222,14 @@ h2 h3 font-size 1.35rem -h4 - font-size 1.25rem -h5 - font-size 1.15rem -h6 - font-size 1.05rem + +.page + h4 + font-size 1.25rem + h5 + font-size 1.15rem + h6 + font-size 1.05rem a.header-anchor font-size 0.85em