fix: 修改readFileList文件获取文件的一下问题

This commit is contained in:
xugaoyi 2022-05-22 19:32:55 +08:00
parent 7cc62dd399
commit 31ea46dced
2 changed files with 34 additions and 33 deletions

View File

@ -9,12 +9,11 @@ const readFileList = require('./modules/readFileList');
const urlsRoot = path.join(__dirname, '..', 'urls.txt'); // 百度链接推送文件
const DOMAIN = process.argv.splice(2)[0]; // 获取命令行传入的参数
if (!DOMAIN) {
console.log(chalk.red('请在运行此文件时指定一个你要进行百度推送的域名参数node utils/baiduPush.js https://xugaoyi.com'))
return
}
if (DOMAIN) {
main();
} else {
console.log(chalk.red('请在运行此文件时指定一个你要进行百度推送的域名参数node utils/baiduPush.js https://xugaoyi.com'))
}
/**
* 主体函数

View File

@ -15,18 +15,20 @@ function readFileList(dir = docsRoot, 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,