chore: 调整代码执行细节

This commit is contained in:
ZiuChen 2024-04-02 14:24:17 +08:00
parent f0451e0a72
commit a89c4a8d31
5 changed files with 22 additions and 25 deletions

View File

@ -1,5 +1,5 @@
import { defineConfig } from 'vitepress' import { defineConfig } from 'vitepress'
import generateSideBar from './scripts/generateSideBar' import { indexArticleSidebar } from './scripts/indexArticleSidebar'
import { projects, works, notes, JUEJIN } from './const' import { projects, works, notes, JUEJIN } from './const'
export default defineConfig({ export default defineConfig({
@ -45,7 +45,7 @@ export default defineConfig({
{ {
text: '文章归档', text: '文章归档',
collapsed: true, collapsed: true,
items: [...generateSideBar()] items: [...indexArticleSidebar()]
}, },
{ {
text: '学习笔记', text: '学习笔记',
@ -66,7 +66,7 @@ export default defineConfig({
}, },
footer: { footer: {
message: 'Released under the MIT License.', message: 'Released under the MIT License.',
copyright: 'Copyright © 2019-present Ziu Chen' copyright: 'Copyright © 2022-PRESENT ZiuChen'
}, },
lastUpdatedText: 'Updated Date', lastUpdatedText: 'Updated Date',
search: { search: {

View File

@ -1,19 +0,0 @@
import fs from 'fs'
import path from 'path'
export default function generateSideBar() {
const articles = fs.readdirSync(path.resolve(__dirname, '../../article'))
const sidebar = articles
.filter((article) => article.endsWith('.md'))
.map((article) => {
// 移除后缀 `.md`
const title = article.replace(/\.md$/, '')
return {
text: title,
link: `/article/${title}`
}
})
return sidebar
}

View File

@ -0,0 +1,16 @@
import fs from 'fs'
import path from 'path'
/**
*
*/
export function indexArticleSidebar() {
const articles = fs.readdirSync(path.resolve(__dirname, '../../article'))
return articles
.filter((article) => article.endsWith('.md'))
.map((article) => ({
text: article.replace(/\.md$/, ''),
link: `/article/${article}`
}))
}

View File

@ -9,6 +9,6 @@ export function customComponents(app: App) {
const cpns = [Title, ImgSlider] const cpns = [Title, ImgSlider]
for (const c of cpns) { for (const c of cpns) {
app.component(c.__name, c) app.component(c.__name!, c)
} }
} }

View File

@ -7,8 +7,8 @@ let lastHashmap: any = null
* *
*/ */
export function refresh() { export function refresh() {
// SSR or SSG 模式不需要检查更新 // SSR or DEV 下不需要检查更新
if (import.meta.env.SSR) { if (import.meta.env.SSR || import.meta.env.DEV) {
return return
} }