feat: 命名约定兼容文件名中间有'.'

This commit is contained in:
xugaoyi 2022-04-08 18:35:35 +08:00
parent 3844f83f6d
commit b6ecfe03e2
7 changed files with 53 additions and 21 deletions

View File

@ -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"
}
}

View File

@ -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) || '')
}
}
})

View File

@ -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

View File

@ -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,

View File

@ -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 {

View File

@ -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"

View File

@ -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