更新任务

This commit is contained in:
jimmy committed 2025-01-18 21:41:58 +08:00
1 parent 92618b9a05
commit 2fe64b8f26
159 files changed
+714 -3448

No files matched your search

+8
View File
@@ -0,0 +1,8 @@
# 默认忽略的文件
/shelf/
/workspace.xml
# 基于编辑器的 HTTP 客户端请求
/httpRequests/
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml
+6
View File
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="GitToolBoxBlameSettings">
<option name="version" value="2" />
</component>
</project>
+8
View File
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/autoSidebar.iml" filepath="$PROJECT_DIR$/.idea/autoSidebar.iml" />
</modules>
</component>
</project>
+148
View File
@@ -0,0 +1,148 @@
import fs from 'fs'
import path from 'path'
import type { DefaultTheme } from 'vitepress'
import { FileUtils } from './utils/fileUtils'
type SidebarItem = DefaultTheme.SidebarItem
// type Sidebar = DefaultTheme.Sidebar
export function createSideBar (docsDir:string) {
console.log('createSideBarZH ======================= ')
// console.log(createSideBarEN1())
let dDir = FileUtils.getRoleFolderName(docsDir,-1)
let filesRecursively = getFilesRecursively(docsDir)
let message = divideSidebar(filesRecursively.contents, dDir)
message.forEach(message => {
// console.log(message)
})
if (message.length > 0) {
message[0].collapsed = true
}
return {
'/notes/': message,
}
}
/**
* 要获取的文件夹目录
*/
function getFilesRecursively (dirPath: string) {
const result: FileOrDir = {
type: 'directory',
path: dirPath,
contents: [],
parentFolder: '',
}
// 获取当前目录下的所有文件和文件夹
const items = fs.readdirSync(dirPath)
items.forEach(item => {
const fullPath = path.join(dirPath, item)
const stats = fs.statSync(fullPath)
if (stats.isDirectory()) {
// 如果是文件夹,递归调用并保留目录结构
if (result.contents === null || result.contents === undefined) {
result.contents = []
}
result.contents.push(getFilesRecursively(fullPath)) // 递归进入子文件夹
} else if (stats.isFile()) {
if (result.contents === null || result.contents === undefined) {
result.contents = []
}
// 如果是文件,直接加入当前目录的内容
result.contents.push({
type: 'file',
path: fullPath,
contents: undefined,
parentFolder: result.path,
})
}
})
return result
}
/**
* 获取根目录
* @param dir
*/
function getProjectRoot (dir: string): string {
const root = path.resolve(dir)
// 查找 package.json 文件,判断是否到达根目录
if (fs.existsSync(path.join(root, 'package.json'))) {
return root
} else {
const parentDir = path.dirname(root)
// 递归向上查找
if (parentDir === root) {
throw new Error('Could not find the project root.')
}
return getProjectRoot(parentDir)
}
}
/**
* 通过文件夹目录划分 Sidebar
*/
function divideSidebar (
files: FileOrDir[] | undefined, rootDir: string): SidebarItem[] {
// undefined 处理
if (!files?.length) return []
let ans: SidebarItem[] = []
for (let i = 0; i < files!.length; i++) {
let file = files[i]
// 如果有子项目,则该级别无链接
if (file.type === 'file') {
let fileName = FileUtils.getFileName(file.path)
// 是否为 index 文件【index 跳过】
if (fileName.includes('index')) continue
let lastFolderName = FileUtils.getLastFolderName(file.parentFolder)
let relativePath = FileUtils.getRelativePath(file.path, rootDir)
console.log(relativePath,'=============')
let obj: SidebarItem = {
text: fileName,
link: relativePath,
}
ans.push(obj)
} else if (file.type === 'directory') {
let folderName = FileUtils.getLastFolderName(file.path)
let res: SidebarItem[] = []
if (!(file.contents?.length !== 0)) {
// 空文件夹进行单独处理
let obj: SidebarItem = {
text: folderName + '[待更新]',
collapsed: false,
items: [],
}
res.push(obj)
} else {
let items = divideSidebar(file.contents, rootDir)
res.push({
text: folderName,
collapsed: false,
items: items,
})
}
ans = ans.concat(res)
}
}
return ans
}
/**
* 文件和文件夹的区分
*/
type FileOrDir = {
// 父文件夹
parentFolder: string,
type: 'directory' | 'file',
path: string,
contents: FileOrDir[] | undefined
}
+56
View File
@@ -0,0 +1,56 @@
/**
* Time:2025/1/18 13:06 09
* Name:index.ts
* Path:autoSidebar
* ProjectName:github.io
* Author:charlatans
*
* Il n'ya qu'un héroïsme au monde :
* c'est de voir le monde tel qu'il est et de l'aimer.
*/
import type { Plugin, ViteDevServer } from 'vite'
import fs from 'fs'
import path from 'path'
import { createSideBar } from './createSideBar'
import { FileUtils } from './utils/fileUtils'
/**
* 根据目录生成展示列表【目录从根目录开始】
* @param genPath 生成 Sidebar 文件目录
* @param docPath 文档目录
*/
export default function autoGenerateSidebar (
genPath: string, docPath: string): Plugin {
let roleFolderName = FileUtils.getRoleFolderName(__dirname, -1)
// 完整路径
const docP = path.join(roleFolderName, docPath)
let sidebarP = path.join(roleFolderName, genPath)
return {
name: 'autoSidebar',
config (config) {
let sideBar = createSideBar(docP)
// 生成的 TypeScript 文件内容
const decodedData = JSON.stringify(sideBar, (key, value) => {
if (typeof value === 'string') {
// 解码字符串中的 URL 编码
return decodeURIComponent(value);
}
return value;
}, 2);
const tsContent = `export default ${decodedData}`
// 定义生成文件的路径
const tsFilePath = path.resolve(sidebarP, 'autoSidebar.ts')
// 确保目录存在,如果不存在则创建它
fs.mkdirSync(sidebarP, { recursive: true })
// 写入文件
fs.writeFileSync(tsFilePath, tsContent, 'utf-8')
console.log('Generated TypeScript file at', tsFilePath)
return config
},
}
}
+19
View File
@@ -0,0 +1,19 @@
{
"name": "auto-sidebar",
"version": "1.00.00.0001",
"author": "duyl328",
"description": "",
"keywords": [
"vite",
"vitepress"
],
"type": "module",
"main": "index.ts",
"scripts": {
"build": "vite build"
},
"license": "MIT",
"devDependencies": {
"vite": "^4.5.0"
}
}
+326
View File
@@ -0,0 +1,326 @@
lockfileVersion: '9.0'
settings:
autoInstallPeers: true
excludeLinksFromLockfile: false
importers:
.:
devDependencies:
vite:
specifier: ^4.5.0
version: 4.5.0
packages:
'@esbuild/android-arm64@0.18.20':
resolution: {integrity: sha512-Nz4rJcchGDtENV0eMKUNa6L12zz2zBDXuhj/Vjh18zGqB44Bi7MBMSXjgunJgjRhCmKOjnPuZp4Mb6OKqtMHLQ==, tarball: https://registry.npmmirror.com/@esbuild/android-arm64/-/android-arm64-0.18.20.tgz}
engines: {node: '>=12'}
cpu: [arm64]
os: [android]
'@esbuild/android-arm@0.18.20':
resolution: {integrity: sha512-fyi7TDI/ijKKNZTUJAQqiG5T7YjJXgnzkURqmGj13C6dCqckZBLdl4h7bkhHt/t0WP+zO9/zwroDvANaOqO5Sw==, tarball: https://registry.npmmirror.com/@esbuild/android-arm/-/android-arm-0.18.20.tgz}
engines: {node: '>=12'}
cpu: [arm]
os: [android]
'@esbuild/android-x64@0.18.20':
resolution: {integrity: sha512-8GDdlePJA8D6zlZYJV/jnrRAi6rOiNaCC/JclcXpB+KIuvfBN4owLtgzY2bsxnx666XjJx2kDPUmnTtR8qKQUg==, tarball: https://registry.npmmirror.com/@esbuild/android-x64/-/android-x64-0.18.20.tgz}
engines: {node: '>=12'}
cpu: [x64]
os: [android]
'@esbuild/darwin-arm64@0.18.20':
resolution: {integrity: sha512-bxRHW5kHU38zS2lPTPOyuyTm+S+eobPUnTNkdJEfAddYgEcll4xkT8DB9d2008DtTbl7uJag2HuE5NZAZgnNEA==, tarball: https://registry.npmmirror.com/@esbuild/darwin-arm64/-/darwin-arm64-0.18.20.tgz}
engines: {node: '>=12'}
cpu: [arm64]
os: [darwin]
'@esbuild/darwin-x64@0.18.20':
resolution: {integrity: sha512-pc5gxlMDxzm513qPGbCbDukOdsGtKhfxD1zJKXjCCcU7ju50O7MeAZ8c4krSJcOIJGFR+qx21yMMVYwiQvyTyQ==, tarball: https://registry.npmmirror.com/@esbuild/darwin-x64/-/darwin-x64-0.18.20.tgz}
engines: {node: '>=12'}
cpu: [x64]
os: [darwin]
'@esbuild/freebsd-arm64@0.18.20':
resolution: {integrity: sha512-yqDQHy4QHevpMAaxhhIwYPMv1NECwOvIpGCZkECn8w2WFHXjEwrBn3CeNIYsibZ/iZEUemj++M26W3cNR5h+Tw==, tarball: https://registry.npmmirror.com/@esbuild/freebsd-arm64/-/freebsd-arm64-0.18.20.tgz}
engines: {node: '>=12'}
cpu: [arm64]
os: [freebsd]
'@esbuild/freebsd-x64@0.18.20':
resolution: {integrity: sha512-tgWRPPuQsd3RmBZwarGVHZQvtzfEBOreNuxEMKFcd5DaDn2PbBxfwLcj4+aenoh7ctXcbXmOQIn8HI6mCSw5MQ==, tarball: https://registry.npmmirror.com/@esbuild/freebsd-x64/-/freebsd-x64-0.18.20.tgz}
engines: {node: '>=12'}
cpu: [x64]
os: [freebsd]
'@esbuild/linux-arm64@0.18.20':
resolution: {integrity: sha512-2YbscF+UL7SQAVIpnWvYwM+3LskyDmPhe31pE7/aoTMFKKzIc9lLbyGUpmmb8a8AixOL61sQ/mFh3jEjHYFvdA==, tarball: https://registry.npmmirror.com/@esbuild/linux-arm64/-/linux-arm64-0.18.20.tgz}
engines: {node: '>=12'}
cpu: [arm64]
os: [linux]
'@esbuild/linux-arm@0.18.20':
resolution: {integrity: sha512-/5bHkMWnq1EgKr1V+Ybz3s1hWXok7mDFUMQ4cG10AfW3wL02PSZi5kFpYKrptDsgb2WAJIvRcDm+qIvXf/apvg==, tarball: https://registry.npmmirror.com/@esbuild/linux-arm/-/linux-arm-0.18.20.tgz}
engines: {node: '>=12'}
cpu: [arm]
os: [linux]
'@esbuild/linux-ia32@0.18.20':
resolution: {integrity: sha512-P4etWwq6IsReT0E1KHU40bOnzMHoH73aXp96Fs8TIT6z9Hu8G6+0SHSw9i2isWrD2nbx2qo5yUqACgdfVGx7TA==, tarball: https://registry.npmmirror.com/@esbuild/linux-ia32/-/linux-ia32-0.18.20.tgz}
engines: {node: '>=12'}
cpu: [ia32]
os: [linux]
'@esbuild/linux-loong64@0.18.20':
resolution: {integrity: sha512-nXW8nqBTrOpDLPgPY9uV+/1DjxoQ7DoB2N8eocyq8I9XuqJ7BiAMDMf9n1xZM9TgW0J8zrquIb/A7s3BJv7rjg==, tarball: https://registry.npmmirror.com/@esbuild/linux-loong64/-/linux-loong64-0.18.20.tgz}
engines: {node: '>=12'}
cpu: [loong64]
os: [linux]
'@esbuild/linux-mips64el@0.18.20':
resolution: {integrity: sha512-d5NeaXZcHp8PzYy5VnXV3VSd2D328Zb+9dEq5HE6bw6+N86JVPExrA6O68OPwobntbNJ0pzCpUFZTo3w0GyetQ==, tarball: https://registry.npmmirror.com/@esbuild/linux-mips64el/-/linux-mips64el-0.18.20.tgz}
engines: {node: '>=12'}
cpu: [mips64el]
os: [linux]
'@esbuild/linux-ppc64@0.18.20':
resolution: {integrity: sha512-WHPyeScRNcmANnLQkq6AfyXRFr5D6N2sKgkFo2FqguP44Nw2eyDlbTdZwd9GYk98DZG9QItIiTlFLHJHjxP3FA==, tarball: https://registry.npmmirror.com/@esbuild/linux-ppc64/-/linux-ppc64-0.18.20.tgz}
engines: {node: '>=12'}
cpu: [ppc64]
os: [linux]
'@esbuild/linux-riscv64@0.18.20':
resolution: {integrity: sha512-WSxo6h5ecI5XH34KC7w5veNnKkju3zBRLEQNY7mv5mtBmrP/MjNBCAlsM2u5hDBlS3NGcTQpoBvRzqBcRtpq1A==, tarball: https://registry.npmmirror.com/@esbuild/linux-riscv64/-/linux-riscv64-0.18.20.tgz}
engines: {node: '>=12'}
cpu: [riscv64]
os: [linux]
'@esbuild/linux-s390x@0.18.20':
resolution: {integrity: sha512-+8231GMs3mAEth6Ja1iK0a1sQ3ohfcpzpRLH8uuc5/KVDFneH6jtAJLFGafpzpMRO6DzJ6AvXKze9LfFMrIHVQ==, tarball: https://registry.npmmirror.com/@esbuild/linux-s390x/-/linux-s390x-0.18.20.tgz}
engines: {node: '>=12'}
cpu: [s390x]
os: [linux]
'@esbuild/linux-x64@0.18.20':
resolution: {integrity: sha512-UYqiqemphJcNsFEskc73jQ7B9jgwjWrSayxawS6UVFZGWrAAtkzjxSqnoclCXxWtfwLdzU+vTpcNYhpn43uP1w==, tarball: https://registry.npmmirror.com/@esbuild/linux-x64/-/linux-x64-0.18.20.tgz}
engines: {node: '>=12'}
cpu: [x64]
os: [linux]
'@esbuild/netbsd-x64@0.18.20':
resolution: {integrity: sha512-iO1c++VP6xUBUmltHZoMtCUdPlnPGdBom6IrO4gyKPFFVBKioIImVooR5I83nTew5UOYrk3gIJhbZh8X44y06A==, tarball: https://registry.npmmirror.com/@esbuild/netbsd-x64/-/netbsd-x64-0.18.20.tgz}
engines: {node: '>=12'}
cpu: [x64]
os: [netbsd]
'@esbuild/openbsd-x64@0.18.20':
resolution: {integrity: sha512-e5e4YSsuQfX4cxcygw/UCPIEP6wbIL+se3sxPdCiMbFLBWu0eiZOJ7WoD+ptCLrmjZBK1Wk7I6D/I3NglUGOxg==, tarball: https://registry.npmmirror.com/@esbuild/openbsd-x64/-/openbsd-x64-0.18.20.tgz}
engines: {node: '>=12'}
cpu: [x64]
os: [openbsd]
'@esbuild/sunos-x64@0.18.20':
resolution: {integrity: sha512-kDbFRFp0YpTQVVrqUd5FTYmWo45zGaXe0X8E1G/LKFC0v8x0vWrhOWSLITcCn63lmZIxfOMXtCfti/RxN/0wnQ==, tarball: https://registry.npmmirror.com/@esbuild/sunos-x64/-/sunos-x64-0.18.20.tgz}
engines: {node: '>=12'}
cpu: [x64]
os: [sunos]
'@esbuild/win32-arm64@0.18.20':
resolution: {integrity: sha512-ddYFR6ItYgoaq4v4JmQQaAI5s7npztfV4Ag6NrhiaW0RrnOXqBkgwZLofVTlq1daVTQNhtI5oieTvkRPfZrePg==, tarball: https://registry.npmmirror.com/@esbuild/win32-arm64/-/win32-arm64-0.18.20.tgz}
engines: {node: '>=12'}
cpu: [arm64]
os: [win32]
'@esbuild/win32-ia32@0.18.20':
resolution: {integrity: sha512-Wv7QBi3ID/rROT08SABTS7eV4hX26sVduqDOTe1MvGMjNd3EjOz4b7zeexIR62GTIEKrfJXKL9LFxTYgkyeu7g==, tarball: https://registry.npmmirror.com/@esbuild/win32-ia32/-/win32-ia32-0.18.20.tgz}
engines: {node: '>=12'}
cpu: [ia32]
os: [win32]
'@esbuild/win32-x64@0.18.20':
resolution: {integrity: sha512-kTdfRcSiDfQca/y9QIkng02avJ+NCaQvrMejlsB3RRv5sE9rRoeBPISaZpKxHELzRxZyLvNts1P27W3wV+8geQ==, tarball: https://registry.npmmirror.com/@esbuild/win32-x64/-/win32-x64-0.18.20.tgz}
engines: {node: '>=12'}
cpu: [x64]
os: [win32]
esbuild@0.18.20:
resolution: {integrity: sha512-ceqxoedUrcayh7Y7ZX6NdbbDzGROiyVBgC4PriJThBKSVPWnnFHZAkfI1lJT8QFkOwH4qOS2SJkS4wvpGl8BpA==}
engines: {node: '>=12'}
hasBin: true
fsevents@2.3.3:
resolution: {integrity: sha512-5xoDfX+fL7faATnagmWPpbFtwh/R77WmMMqqHGS65C3vvB0YHrgF+B1YmZ3441tMj5n63k0212XNoJwzlhffQw==, tarball: https://registry.npmmirror.com/fsevents/-/fsevents-2.3.3.tgz}
engines: {node: ^8.16.0 || ^10.6.0 || >=11.0.0}
os: [darwin]
nanoid@3.3.6:
resolution: {integrity: sha512-BGcqMMJuToF7i1rt+2PWSNVnWIkGCU78jBG3RxO/bZlnZPK2Cmi2QaffxGO/2RvWi9sL+FAiRiXMgsyxQ1DIDA==}
engines: {node: ^10 || ^12 || ^13.7 || ^14 || >=15.0.1}
hasBin: true
picocolors@1.0.0:
resolution: {integrity: sha512-1fygroTLlHu66zi26VoTDv8yRgm0Fccecssto+MhsZ0D/DGW2sm8E8AjW7NU5VVTRt5GxbeZ5qBuJr+HyLYkjQ==}
postcss@8.4.31:
resolution: {integrity: sha512-PS08Iboia9mts/2ygV3eLpY5ghnUcfLV/EXTOW1E2qYxJKGGBUtNjN76FYHnMs36RmARn41bC0AZmn+rR0OVpQ==}
engines: {node: ^10 || ^12 || >=14}
rollup@3.29.4:
resolution: {integrity: sha512-oWzmBZwvYrU0iJHtDmhsm662rC15FRXmcjCk1xD771dFDx5jJ02ufAQQTn0etB2emNk4J9EZg/yWKpsn9BWGRw==}
engines: {node: '>=14.18.0', npm: '>=8.0.0'}
hasBin: true
source-map-js@1.0.2:
resolution: {integrity: sha512-R0XvVJ9WusLiqTCEiGCmICCMplcCkIwwR11mOSD9CR5u+IXYdiseeEuXCVAjS54zqwkLcPNnmU4OeJ6tUrWhDw==}
engines: {node: '>=0.10.0'}
vite@4.5.0:
resolution: {integrity: sha512-ulr8rNLA6rkyFAlVWw2q5YJ91v098AFQ2R0PRFwPzREXOUJQPtFUG0t+/ZikhaOCDqFoDhN6/v8Sq0o4araFAw==}
engines: {node: ^14.18.0 || >=16.0.0}
hasBin: true
peerDependencies:
'@types/node': '>= 14'
less: '*'
lightningcss: ^1.21.0
sass: '*'
stylus: '*'
sugarss: '*'
terser: ^5.4.0
peerDependenciesMeta:
'@types/node':
optional: true
less:
optional: true
lightningcss:
optional: true
sass:
optional: true
stylus:
optional: true
sugarss:
optional: true
terser:
optional: true
snapshots:
'@esbuild/android-arm64@0.18.20':
optional: true
'@esbuild/android-arm@0.18.20':
optional: true
'@esbuild/android-x64@0.18.20':
optional: true
'@esbuild/darwin-arm64@0.18.20':
optional: true
'@esbuild/darwin-x64@0.18.20':
optional: true
'@esbuild/freebsd-arm64@0.18.20':
optional: true
'@esbuild/freebsd-x64@0.18.20':
optional: true
'@esbuild/linux-arm64@0.18.20':
optional: true
'@esbuild/linux-arm@0.18.20':
optional: true
'@esbuild/linux-ia32@0.18.20':
optional: true
'@esbuild/linux-loong64@0.18.20':
optional: true
'@esbuild/linux-mips64el@0.18.20':
optional: true
'@esbuild/linux-ppc64@0.18.20':
optional: true
'@esbuild/linux-riscv64@0.18.20':
optional: true
'@esbuild/linux-s390x@0.18.20':
optional: true
'@esbuild/linux-x64@0.18.20':
optional: true
'@esbuild/netbsd-x64@0.18.20':
optional: true
'@esbuild/openbsd-x64@0.18.20':
optional: true
'@esbuild/sunos-x64@0.18.20':
optional: true
'@esbuild/win32-arm64@0.18.20':
optional: true
'@esbuild/win32-ia32@0.18.20':
optional: true
'@esbuild/win32-x64@0.18.20':
optional: true
esbuild@0.18.20:
optionalDependencies:
'@esbuild/android-arm': 0.18.20
'@esbuild/android-arm64': 0.18.20
'@esbuild/android-x64': 0.18.20
'@esbuild/darwin-arm64': 0.18.20
'@esbuild/darwin-x64': 0.18.20
'@esbuild/freebsd-arm64': 0.18.20
'@esbuild/freebsd-x64': 0.18.20
'@esbuild/linux-arm': 0.18.20
'@esbuild/linux-arm64': 0.18.20
'@esbuild/linux-ia32': 0.18.20
'@esbuild/linux-loong64': 0.18.20
'@esbuild/linux-mips64el': 0.18.20
'@esbuild/linux-ppc64': 0.18.20
'@esbuild/linux-riscv64': 0.18.20
'@esbuild/linux-s390x': 0.18.20
'@esbuild/linux-x64': 0.18.20
'@esbuild/netbsd-x64': 0.18.20
'@esbuild/openbsd-x64': 0.18.20
'@esbuild/sunos-x64': 0.18.20
'@esbuild/win32-arm64': 0.18.20
'@esbuild/win32-ia32': 0.18.20
'@esbuild/win32-x64': 0.18.20
fsevents@2.3.3:
optional: true
nanoid@3.3.6: {}
picocolors@1.0.0: {}
postcss@8.4.31:
dependencies:
nanoid: 3.3.6
picocolors: 1.0.0
source-map-js: 1.0.2
rollup@3.29.4:
optionalDependencies:
fsevents: 2.3.3
source-map-js@1.0.2: {}
vite@4.5.0:
dependencies:
esbuild: 0.18.20
postcss: 8.4.31
rollup: 3.29.4
optionalDependencies:
fsevents: 2.3.3
+15
View File
@@ -0,0 +1,15 @@
{
"include": ["./**/*"],
"compilerOptions": {
"moduleResolution": "node",
"target": "es2016",
"module": "ESNext",
"esModuleInterop": true, /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */
// "preserveSymlinks": true, /* Disable resolving symlinks to their realpath. This correlates to the same flag in node. */
"forceConsistentCasingInFileNames": true, /* Ensure that casing is correct in imports. */
/* Type Checking */
"strict": true,
"skipLibCheck": true /* Skip type checking all .d.ts files. */
}
}
+72
View File
@@ -0,0 +1,72 @@
/**
* Time:2025/1/18 11:05 56
* Name:fileUtils.ts
* Path:docs/.vitepress/theme/utils
* ProjectName:github.io
* Author:charlatans
*
* Il n'ya qu'un héroïsme au monde :
* c'est de voir le monde tel qu'il est et de l'aimer.
*/
export class FileUtils {
/**
* 获取指定路径的文件名
* @param url
*/
static getFileName (url: string) {
const parsedUrl = new URL(url)
let pathname = parsedUrl.pathname
pathname = pathname.replace(/\\/g, '/')
const segments = pathname.split('/')
return segments[segments.length - 1]
}
/**
* 获取指定路径最后一个文件夹
* @param url
*/
static getLastFolderName (url: string): string {
const parsedUrl = new URL(url)
let pathname = parsedUrl.pathname
// 统一路径分隔符为 '/'
pathname = pathname.replace(/\\/g, '/')
const segments = pathname.split('/')
if (segments[segments.length - 1].includes('.')) {
return segments[segments.length - 2]
}
return segments[segments.length - 1]
}
/**
* 截断指定路径
*/
static getRelativePath (fullPath: string, rootPath: string): string {
// 使用 replace 去掉根路径部分,返回相对路径
const normalizedRootPath = rootPath.replace(/\\/g, '/')
const normalizedFullPath = fullPath.replace(/\\/g, '/')
return normalizedFullPath.replace(normalizedRootPath + '/', '')
}
/**
* 按照指定的规则截断路径 【如果是正数,返回前 n 个文件夹路径,如果是负数,返回倒数第 n 个到第 0 个
* @param url
* @param n
*/
static getRoleFolderName (url: string,n:number): string {
url = url.replace(/\\/g, '/')
const segments = url.split('/')
if (n > 0) {
return segments.slice(0, n).join('/');
} else if (n < 0) {
return segments.slice(0, segments.length + n).join('/');
} else {
return '';
}
}
}
+14
View File
@@ -0,0 +1,14 @@
import { resolve } from 'path'
import { defineConfig } from 'vite'
export default defineConfig({
build: {
lib: {
// Could also be a dictionary or array of multiple entry points
entry: resolve(__dirname, './index.ts'),
name: 'autoSidebar',
// the proper extensions will be added
fileName: 'autoSidebar',
},
},
})