Skip to content

Commit 9f78ff5

Browse files
committed
refactor(build): 移除一些依赖替换为自实现
1 parent 5d7e0a2 commit 9f78ff5

7 files changed

Lines changed: 84 additions & 13 deletions

File tree

package.json

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
"less": "4.5.1",
2020
"marked": "17.0.3",
2121
"mermaid": "11.12.3",
22-
"nprogress": "0.2.0",
2322
"prismjs": "1.30.0",
2423
"svg-pan-zoom": "3.6.2",
2524
"tiny-pinyin": "1.3.2",
@@ -33,10 +32,8 @@
3332
"@types/jsdom": "27.0.0",
3433
"@types/katex": "0.16.8",
3534
"@types/node": "24.10.13",
36-
"@types/nprogress": "0.2.3",
3735
"@types/prismjs": "1.26.6",
3836
"@vitejs/plugin-vue": "6.0.4",
39-
"front-matter": "4.0.2",
4037
"jsdom": "27.4.0",
4138
"nodejieba": "3.5.2",
4239
"rollup-plugin-visualizer": "7.0.0",

src/build/DocService.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import { getMidString } from '../util/StringUtils';
99
import {KnowledgeNode, KnowledgeLinkNode} from "../dto/KnowledgeNode";
1010
import DocUtils from "../util/DocUtils";
1111
import yaml from 'js-yaml'
12-
import fm from 'front-matter';
1312
import {DocMetadata} from "@/dto/doc/DocMetadata";
1413
import Cacheable from "@/decorator/Cacheable";
1514
import ArrayUtils from "../util/ArrayUtils";
@@ -48,7 +47,11 @@ class DocService extends BaseService implements Cacheable {
4847
@cache
4948
public async getFileInfo(path: string): Promise<DocFileInfo> {
5049
const callResult = await Promise.all([GitService.getFileCommitList(path), fs.promises.readFile(path)])
51-
const { body, frontmatter } = fm(callResult[1].toString())
50+
const rawContent = callResult[1].toString()
51+
const frontmatter = this.resolveMetadata(rawContent)
52+
const body = frontmatter
53+
? rawContent.replace(/^---[\s\S]+?^---\s*/m, '')
54+
: rawContent
5255
return {
5356
name: path.split('/')[path.split('/').length-1].replace('.md', ''),
5457
id: DocUtils.docUrl2Id(path),

src/main.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@ import App from './Main.vue'
33
import createRouter from './route'
44
import 'element-plus/theme-chalk/dark/css-vars.css'
55
import './style.less'
6-
import NProgress from 'nprogress'
7-
import 'nprogress/nprogress.css'
6+
import NProgress from '@/util/NProgress'
87
import createStore from '@/store'
98
import { SysUtils } from './util/SysUtils'
109
import { registerSW } from 'virtual:pwa-register';

src/pages/home/statistic/HeatMapUtils.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
1-
import dayjs from 'dayjs'
1+
function formatDate(time: number): string {
2+
return new Date(time).toISOString().slice(0, 10)
3+
}
24

35
export default {
46
fillTimeRange(data: [string, number][]){
57
const map = new Map<string, number>(data);
68
const range = [data[0][0], data[data.length - 1][0]];
7-
const start = +dayjs(range[0]);
8-
const end = +dayjs(range[1]);
9+
const start = new Date(range[0]).getTime();
10+
const end = new Date(range[1]).getTime();
911
const dayTime = 3600 * 24 * 1000;
1012
const results: [string, number][] = [];
1113
for (let time = start; time < end; time += dayTime) {
12-
const date = dayjs(time).format("YYYY-MM-DD");
14+
const date = formatDate(time);
1315
results.push([date, map.get(date) || 0]);
1416
}
1517
return results;

src/util/MermaidUtils.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import mermaid from "mermaid"
2-
import svgPanZoom from 'svg-pan-zoom'
32
import { SysUtils } from "./SysUtils"
43

54
function initWithDark() {

src/util/NProgress.ts

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
let hideTimer: ReturnType<typeof setTimeout> | null = null
2+
let trickleTimer: ReturnType<typeof setInterval> | null = null
3+
let el: HTMLDivElement | null = null
4+
let pending = 0
5+
let progress = 0
6+
7+
function getEl(): HTMLDivElement {
8+
if (!el) {
9+
el = document.createElement('div')
10+
el.style.cssText = [
11+
'position:fixed',
12+
'top:0',
13+
'left:0',
14+
'width:0',
15+
'height:2px',
16+
'background:var(--el-color-primary,#409eff)',
17+
'z-index:9999',
18+
'transition:width 0.3s ease,opacity 0.4s ease',
19+
'opacity:0',
20+
].join(';')
21+
document.body.appendChild(el)
22+
}
23+
return el
24+
}
25+
26+
// 越接近 100% 每次前进越少,模拟真实加载感
27+
function trickleAmount(): number {
28+
if (progress < 0.2) return 0.08
29+
if (progress < 0.5) return 0.05
30+
if (progress < 0.8) return 0.02
31+
if (progress < 0.95) return 0.005
32+
return 0
33+
}
34+
35+
function setProgress(n: number) {
36+
progress = Math.min(n, 0.994)
37+
getEl().style.width = (progress * 100) + '%'
38+
}
39+
40+
function startTrickle() {
41+
if (trickleTimer) return
42+
trickleTimer = setInterval(() => setProgress(progress + trickleAmount()), 800)
43+
}
44+
45+
function stopTrickle() {
46+
if (trickleTimer) { clearInterval(trickleTimer); trickleTimer = null }
47+
}
48+
49+
export default {
50+
start() {
51+
pending++
52+
if (hideTimer) { clearTimeout(hideTimer); hideTimer = null }
53+
const bar = getEl()
54+
bar.style.opacity = '1'
55+
if (progress === 0) setProgress(0.02)
56+
startTrickle()
57+
},
58+
done() {
59+
if (pending > 0) pending--
60+
if (pending > 0) return
61+
stopTrickle()
62+
setProgress(1)
63+
hideTimer = setTimeout(() => {
64+
getEl().style.opacity = '0'
65+
hideTimer = setTimeout(() => {
66+
getEl().style.width = '0'
67+
progress = 0
68+
}, 400)
69+
}, 200)
70+
}
71+
}

src/util/http.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import NProgress from 'nprogress'
1+
import NProgress from '@/util/NProgress'
22

33
export async function http(input: RequestInfo | URL, init?: RequestInit): Promise<Response> {
44
NProgress.start()

0 commit comments

Comments
 (0)