Skip to content

Commit e0910a0

Browse files
committed
feat: 🚀 插件更改扫描方式
1 parent ff8c6ff commit e0910a0

File tree

107 files changed

+34
-31
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

107 files changed

+34
-31
lines changed

.vscode/settings.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@
7272
"twikoo",
7373
"waline",
7474
"artalk",
75-
"giscus"
75+
"giscus",
76+
"teeker"
7677
]
7778
}

package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"type": "module",
44
"private": true,
55
"workspaces": [
6-
"vitepress-theme-tk",
6+
"vitepress-theme-teeker",
77
"plugins/*",
88
"docs",
99
"build",
@@ -24,7 +24,7 @@
2424
"build": "pnpm run clean && pnpm run -C build start",
2525
"clean": "rimraf dist",
2626
"stub:build": "pnpm run -C build stub",
27-
"stub:theme": "pnpm run -C vitepress-theme-tk stub",
27+
"stub:theme": "pnpm run -C vitepress-theme-teeker stub",
2828
"stub:sidebar": "pnpm run -C plugins/vitepress-plugin-sidebar-resolve stub",
2929
"stub:fileContentLoader": "pnpm run -C plugins/vitepress-plugin-file-content-loader stub",
3030
"stub:permalink": "pnpm run -C plugins/vitepress-plugin-permalink stub",

plugins/vitepress-plugin-catalogue/src/helper.ts

+14-13
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,16 @@ import { basename, extname, resolve } from "node:path";
33
import matter from "gray-matter";
44
import type { CatalogueOption } from "./types";
55

6-
// 默认扫描的文件夹列表
7-
export const DEFAULT_INCLUDE_DIR = ["目录页"];
6+
// 默认忽略的文件夹列表
7+
export const DEFAULT_IGNORE_DIR = ["scripts", "components", "assets", ".vitepress", "node_modules", "dist", "public"];
88

9+
// key 为文件路径,value 为 frontmatter 的 path 值
910
let catalogues: Record<string, string> = {};
1011

1112
export default (option: CatalogueOption = {}) => {
12-
const { path = process.cwd(), includeList = [] } = option;
13+
const { path = process.cwd(), ignoreList = [] } = option;
1314
// 获取指定根目录下的所有目录绝对路径
14-
const dirPaths = readDirPaths(path, includeList);
15+
const dirPaths = readDirPaths(path, ignoreList);
1516

1617
// 遍历根目录下的每个子目录
1718
dirPaths.forEach(dirPath => scannerMdFile(dirPath, option, basename(dirPath)));
@@ -23,8 +24,8 @@ export default (option: CatalogueOption = {}) => {
2324
* 指定根目录下的所有目录绝对路径,win 如 ['D:\docs\01.guide', 'D:\docs\02.design'],linux 如 ['/usr/local/docs/01.guide', '/usr/local/docs/02.design']
2425
* @param sourceDir 指定文件/文件夹的根目录
2526
*/
26-
const readDirPaths = (sourceDir: string, includeList: CatalogueOption["includeList"] = []) => {
27-
const includeListAll = [...DEFAULT_INCLUDE_DIR, ...includeList];
27+
const readDirPaths = (sourceDir: string, ignoreList: CatalogueOption["ignoreList"] = []) => {
28+
const ignoreListAll = [...DEFAULT_IGNORE_DIR, ...ignoreList];
2829
const dirPaths: string[] = [];
2930
// 读取目录,返回数组,成员是 root 下所有的目录名(包含文件夹和文件,不递归)
3031
const secondDirNames = readdirSync(sourceDir);
@@ -33,7 +34,7 @@ const readDirPaths = (sourceDir: string, includeList: CatalogueOption["includeLi
3334
// 将路径或路径片段的序列解析为绝对路径,等于使用 cd 命令
3435
const secondDirPath = resolve(sourceDir, secondDirName);
3536
// 是否为文件夹目录,并排除指定文件夹
36-
if (isSome(includeListAll, secondDirName) && statSync(secondDirPath).isDirectory()) {
37+
if (!isSome(ignoreListAll, secondDirName) && statSync(secondDirPath).isDirectory()) {
3738
dirPaths.push(secondDirPath);
3839
}
3940
});
@@ -48,26 +49,26 @@ const readDirPaths = (sourceDir: string, includeList: CatalogueOption["includeLi
4849
* @param prefix 目录前缀,每次递归都加前端目录名
4950
*/
5051
const scannerMdFile = (root: string, option: CatalogueOption, prefix = "") => {
51-
const { includeList = [] } = option;
52-
const includeListAll = [...DEFAULT_INCLUDE_DIR, ...includeList];
52+
const { ignoreList = [] } = option;
53+
const ignoreListAll = [...DEFAULT_IGNORE_DIR, ...ignoreList];
5354
// 读取目录名(文件和文件夹)
5455
let secondDirOrFilenames = readdirSync(root);
5556

5657
secondDirOrFilenames.forEach(dirOrFilename => {
58+
if (isSome(ignoreListAll, dirOrFilename)) return [];
59+
5760
const filePath = resolve(root, dirOrFilename);
5861

5962
if (statSync(filePath).isDirectory()) {
6063
// 是文件夹目录
61-
if (!isSome(includeListAll, dirOrFilename)) return;
62-
6364
scannerMdFile(filePath, option, `${prefix}/${dirOrFilename}`);
6465
} else {
6566
// 是文件
6667
if (!isMdFile(dirOrFilename)) return;
6768

6869
const content = readFileSync(filePath, "utf-8");
6970

70-
// 解析出 front matter 数据
71+
// 解析出 frontmatter 数据
7172
const { data: { catalogue, path = "" } = {} } = matter(content, {});
7273

7374
if (catalogue && path) {
@@ -95,5 +96,5 @@ const isMdFile = (filePath: string) => {
9596
* @param name 元素
9697
*/
9798
const isSome = (arr: Array<string | RegExp>, name: string) => {
98-
return arr.some(item => name.includes(item as string) || (item instanceof RegExp && item.test(name)));
99+
return arr.some(item => item === name || (item instanceof RegExp && item.test(name)));
99100
};

plugins/vitepress-plugin-catalogue/src/types.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
export interface CatalogueOption {
22
/**
3-
* 指定扫描的文件/文件夹列表,支持正则表达式
3+
* 忽略的文件/文件夹列表,支持正则表达式
44
*
5-
* @default ["目录页"]
5+
* @default []
66
*/
7-
includeList?: Array<RegExp | string>;
7+
ignoreList?: Array<RegExp | string>;
88
/**
99
* 文章所在的目录,基于 package.json 所在目录
1010
*

plugins/vitepress-plugin-doc-analysis/src/helper.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { readdirSync, readFileSync, statSync } from "node:fs"; // 文件模块
2-
import { extname, relative, resolve } from "node:path"; // 路径模块
3-
import chalk from "chalk"; // 命令行打印美化
1+
import { readdirSync, readFileSync, statSync } from "node:fs";
2+
import { extname, relative, resolve } from "node:path";
3+
import chalk from "chalk";
44
import { FileInfo, DocAnalysisOption } from "./types";
55
import matter from "gray-matter";
66

pnpm-lock.yaml

+5-5
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pnpm-workspace.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
packages:
2-
- vitepress-theme-tk
2+
- vitepress-theme-teeker
33
- plugins/*
44
- docs
55
- build

vitepress-theme-tk/package.json renamed to vitepress-theme-teeker/package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
{
22
"name": "vitepress-theme-tk",
33
"version": "1.0.0",
4-
"description": "vitepress-theme-tk",
5-
"author": "tianke",
4+
"description": "vitepress-theme-teeker",
5+
"author": "teeker",
66
"type": "module",
77
"license": "MIT",
88
"main": "./src/index.ts",

vitepress-theme-tk/src/hooks/useDesign.ts renamed to vitepress-theme-teeker/src/hooks/useDesign.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ export const useDesign = () => {
1010
};
1111

1212
return {
13-
namespace: variables,
13+
variables,
14+
namespace: variables.namespace,
1415
getPrefixClass,
1516
};
1617
};
File renamed without changes.

0 commit comments

Comments
 (0)