@sugarat/theme 0.1.49 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (37) hide show
  1. package/node.d.ts +41 -1
  2. package/node.js +24 -20
  3. package/package.json +24 -24
  4. package/src/components/BlogAlert.vue +17 -17
  5. package/src/components/BlogApp.vue +91 -50
  6. package/src/components/BlogArticleAnalyze.vue +56 -57
  7. package/src/components/BlogAuthor.vue +55 -0
  8. package/src/components/BlogComment.vue +53 -50
  9. package/src/components/BlogDocCover.vue +4 -4
  10. package/src/components/BlogFooter.vue +131 -0
  11. package/src/components/BlogFriendLink.vue +40 -31
  12. package/src/components/BlogHomeBanner.vue +22 -16
  13. package/src/components/BlogHomeInfo.vue +4 -0
  14. package/src/components/BlogHomeOverview.vue +20 -20
  15. package/src/components/BlogHomeTags.vue +49 -40
  16. package/src/components/BlogHotArticle.vue +43 -36
  17. package/src/components/BlogImagePreview.vue +7 -5
  18. package/src/components/BlogItem.vue +42 -43
  19. package/src/components/BlogList.vue +46 -42
  20. package/src/components/BlogPopover.vue +41 -39
  21. package/src/components/BlogRecommendArticle.vue +58 -48
  22. package/src/components/BlogSearch.vue +143 -145
  23. package/src/components/UserWorks.vue +214 -210
  24. package/src/composables/config/blog.ts +14 -5
  25. package/src/composables/config/index.ts +74 -31
  26. package/src/constants/svg.ts +11 -2
  27. package/src/index.ts +1 -2
  28. package/src/node.ts +2 -2
  29. package/src/styles/gongan.png +0 -0
  30. package/src/styles/scss/global.scss +0 -5
  31. package/src/utils/client/index.ts +9 -8
  32. package/src/utils/node/genFeed.ts +8 -7
  33. package/src/utils/node/index.ts +8 -6
  34. package/src/utils/node/mdPlugins.ts +29 -22
  35. package/src/utils/node/theme.ts +16 -13
  36. package/src/utils/node/vitePlugins.ts +7 -6
  37. package/types/vue-shim.d.ts +1 -1
@@ -1,8 +1,10 @@
1
+ /* eslint-disable ts/no-namespace */
1
2
  import type { ElButton } from 'element-plus'
2
3
  import type { DefaultTheme } from 'vitepress'
3
4
  import type { FeedOptions } from 'feed'
4
5
 
5
- export namespace BlogPopover {
6
+ // TODO: 重构 lint 问题
7
+ export declare namespace BlogPopover {
6
8
  export interface Title {
7
9
  type: 'title'
8
10
  content: string
@@ -125,6 +127,8 @@ export namespace Theme {
125
127
  inspiring?: string | string[]
126
128
  inspiringTimeout?: number
127
129
  pageSize?: number
130
+ author?: string | boolean
131
+ logo?: string | boolean
128
132
  }
129
133
 
130
134
  export interface ArticleConfig {
@@ -174,32 +178,32 @@ export namespace Theme {
174
178
  title: string
175
179
  description: string
176
180
  time:
177
- | string
178
- | {
179
- start: string
180
- end?: string
181
- lastupdate?: string
182
- }
181
+ | string
182
+ | {
183
+ start: string
184
+ end?: string
185
+ lastupdate?: string
186
+ }
183
187
  status?: {
184
188
  text: string
185
189
  type?: 'tip' | 'warning' | 'danger'
186
190
  }
187
191
  url?: string
188
192
  github?:
189
- | string
190
- | {
191
- owner: string
192
- repo: string
193
- branch?: string
194
- path?: string
195
- }
193
+ | string
194
+ | {
195
+ owner: string
196
+ repo: string
197
+ branch?: string
198
+ path?: string
199
+ }
196
200
  cover?:
197
- | string
198
- | string[]
199
- | {
200
- urls: string[]
201
- layout?: 'swiper' | 'list'
202
- }
201
+ | string
202
+ | string[]
203
+ | {
204
+ urls: string[]
205
+ layout?: 'swiper' | 'list'
206
+ }
203
207
  links?: {
204
208
  title: string
205
209
  url: string
@@ -211,16 +215,16 @@ export namespace Theme {
211
215
  | boolean
212
216
  | 'pagefind'
213
217
  | {
214
- btnPlaceholder?: string
215
- placeholder?: string
216
- emptyText?: string
217
- /**
218
- * @example
219
- * 'Total: {{searchResult}} search results.'
220
- */
221
- heading?: string
222
- mode?: boolean | 'pagefind'
223
- }
218
+ btnPlaceholder?: string
219
+ placeholder?: string
220
+ emptyText?: string
221
+ /**
222
+ * @example
223
+ * 'Total: {{searchResult}} search results.'
224
+ */
225
+ heading?: string
226
+ mode?: boolean | 'pagefind'
227
+ }
224
228
 
225
229
  export interface UserWorks {
226
230
  title: string
@@ -288,12 +292,16 @@ export namespace Theme {
288
292
  /**
289
293
  * 设置解析 frontmatter 里 date 的时区
290
294
  * @default 8 => 'UTC+8'
291
- * */
295
+ */
292
296
  timeZone?: number
293
297
  /**
294
298
  * 启用RSS配置
295
299
  */
296
300
  RSS?: RSSOptions
301
+ /**
302
+ * 首页页脚
303
+ */
304
+ footer?: Footer
297
305
  }
298
306
 
299
307
  export type RSSOptions = Omit<FeedOptions, 'id'> & {
@@ -330,6 +338,41 @@ export namespace Theme {
330
338
  limit?: number
331
339
  ariaLabel?: string
332
340
  }
341
+
342
+ export interface Footer {
343
+ /**
344
+ * 自定义补充信息
345
+ */
346
+ message?: string
347
+ /**
348
+ * 是否展示主题版本信息
349
+ */
350
+ version?: boolean
351
+ /**
352
+ * copyright
353
+ */
354
+ copyright?: string | {
355
+ message: string
356
+ link?: string
357
+ icon?: boolean | string
358
+ }
359
+ /**
360
+ * ICP 备案信息
361
+ */
362
+ icpRecord?: {
363
+ name: string
364
+ link: string
365
+ icon?: boolean | string
366
+ }
367
+ /**
368
+ * 公安备案信息
369
+ */
370
+ securityRecord?: {
371
+ name: string
372
+ link: string
373
+ icon?: boolean | string
374
+ }
375
+ }
333
376
  export interface Config extends DefaultTheme.Config {
334
377
  blog?: BlogConfig
335
378
  }
@@ -19,7 +19,7 @@ export const fireSVG = `<svg viewBox="0 0 128 128" xmlns="http://www.w3.org/2000
19
19
  <path fill="url(#notoFire1)" d="M76.11 77.42c-9.09-11.7-5.02-25.05-2.79-30.37c.3-.7-.5-1.36-1.13-.93c-3.91 2.66-11.92 8.92-15.65 17.73c-5.05 11.91-4.69 17.74-1.7 24.86c1.8 4.29-.29 5.2-1.34 5.36c-1.02.16-1.96-.52-2.71-1.23a16.09 16.09 0 0 1-4.44-7.6c-.16-.62-.97-.79-1.34-.28c-2.8 3.87-4.25 10.08-4.32 14.47C40.47 113 51.68 124 65.24 124c17.09 0 29.54-18.9 19.72-34.7c-2.85-4.6-5.53-7.61-8.85-11.88z"/>
20
20
  </svg>`
21
21
 
22
- export const recommendSVG =`<svg width="512" height="512" viewBox="0 0 128 128" xmlns="http://www.w3.org/2000/svg">
22
+ export const recommendSVG = `<svg width="512" height="512" viewBox="0 0 128 128" xmlns="http://www.w3.org/2000/svg">
23
23
  <radialGradient id="notoFaceWithMonocle0" cx="63.6" cy="-2088.9" r="56.96" gradientTransform="matrix(1 0 0 -1 0 -2026)" gradientUnits="userSpaceOnUse">
24
24
  <stop offset=".5" stop-color="#FDE030"/>
25
25
  <stop offset=".919" stop-color="#F7C02B"/>
@@ -42,4 +42,13 @@ export const recommendSVG =`<svg width="512" height="512" viewBox="0 0 128 128"
42
42
  <circle cx="79.6" cy="53.7" r="20.6" fill="#CCC" fill-opacity=".5" stroke="#404040" stroke-miterlimit="10" stroke-width="3.5"/>
43
43
  <path fill="#FFF" d="M94.8 52.5c-.4-3.8-2.1-7.3-4.9-9.7s-6.4-3.7-10-3.7c-3.7 0-7.3 1.2-10.1 3.5s-4.6 5.8-4.9 9.6c0 .3-.3.5-.5.4c-.2 0-.4-.2-.4-.5c-.1-2 .3-4.1 1.1-6c.8-1.9 2-3.6 3.5-5.1c3-2.9 7.3-4.3 11.4-4.3c4.2 0 8.3 1.6 11.3 4.5c1.5 1.5 2.7 3.2 3.5 5.1c.8 1.9 1.1 4 1 6c0 .3-.2.5-.5.5c-.3.1-.5-.1-.5-.3z"/>
44
44
  <path fill="#896024" d="M37.01 49.35c-1.03-.72-2.58-.49-3.58.95s-.67 2.97.36 3.69c1.03.72 2.58.49 3.58-.95c1.01-1.45.68-2.98-.36-3.69z"/>
45
- </svg>`
45
+ </svg>`
46
+
47
+ export const themeSVG = `<svg width="128" height="128" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
48
+ <title>主题</title>
49
+ <path d="M12 2C6.49 2 2 6.49 2 12s4.49 10 10 10a2.5 2.5 0 0 0 2.5-2.5c0-.61-.23-1.2-.64-1.67a.528.528 0 0 1-.13-.33c0-.28.22-.5.5-.5H16c3.31 0 6-2.69 6-6c0-4.96-4.49-9-10-9zm5.5 11c-.83 0-1.5-.67-1.5-1.5s.67-1.5 1.5-1.5s1.5.67 1.5 1.5s-.67 1.5-1.5 1.5zm-3-4c-.83 0-1.5-.67-1.5-1.5S13.67 6 14.5 6s1.5.67 1.5 1.5S15.33 9 14.5 9zM5 11.5c0-.83.67-1.5 1.5-1.5s1.5.67 1.5 1.5S7.33 13 6.5 13S5 12.33 5 11.5zm6-4c0 .83-.67 1.5-1.5 1.5S8 8.33 8 7.5S8.67 6 9.5 6s1.5.67 1.5 1.5z"/>
50
+ </svg>`
51
+
52
+ export const icpSVG = '<svg viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" data-v-2f084f89=""><title data-v-2f084f89="">ICP备案号</title><path d="M778.24 163.84c-76.8-40.96-165.888-61.44-269.312-61.44s-192.512 20.48-269.312 61.44h-133.12l23.552 337.92c8.192 113.664 67.584 217.088 162.816 280.576l215.04 144.384 215.04-144.384c96.256-63.488 155.648-166.912 163.84-280.576l23.552-337.92H778.24z m47.104 333.824c-7.168 94.208-56.32 181.248-135.168 233.472l-181.248 120.832L327.68 731.136c-78.848-53.248-129.024-139.264-135.168-233.472L173.056 225.28h136.192v-26.624c58.368-23.552 124.928-34.816 199.68-34.816s141.312 12.288 199.68 34.816V225.28H844.8l-19.456 272.384z" data-v-2f084f89=""></path><path d="M685.056 328.704v-46.08H455.68c2.048-4.096 6.144-9.216 11.264-15.36 5.12-7.168 9.216-12.288 11.264-15.36L419.84 240.64c-31.744 46.08-75.776 87.04-133.12 123.904 4.096 4.096 10.24 11.264 18.432 21.504l17.408 17.408c23.552-15.36 45.056-31.744 63.488-50.176 26.624 25.6 49.152 43.008 67.584 51.2-46.08 15.36-104.448 27.648-175.104 35.84 2.048 5.12 6.144 13.312 9.216 24.576 4.096 11.264 6.144 19.456 7.168 24.576l39.936-7.168v218.112H389.12V680.96h238.592v19.456h54.272V481.28H348.16c60.416-12.288 114.688-27.648 163.84-46.08 49.152 19.456 118.784 34.816 210.944 46.08 5.12-17.408 10.24-34.816 17.408-51.2-62.464-4.096-116.736-12.288-161.792-24.576 38.912-20.48 74.752-46.08 106.496-76.8z m-150.528 194.56h94.208v41.984h-94.208v-41.984z m0 78.848h94.208v41.984h-94.208v-41.984z m-144.384-78.848h94.208v41.984H390.144v-41.984z m0 78.848h94.208v41.984H390.144v-41.984zM424.96 326.656h182.272c-26.624 22.528-57.344 41.984-94.208 57.344-31.744-15.36-61.44-34.816-88.064-57.344z" data-v-2f084f89=""></path></svg>'
53
+
54
+ export const copyrightSVG = '<svg t="1695543755857" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="89399" width="200" height="200"><path d="M512 16C238.066 16 16 238.066 16 512s222.066 496 496 496 496-222.066 496-496S785.934 16 512 16z m234.268 693.506c-3.184 3.734-79.552 91.462-219.702 91.462-169.384 0-288.968-126.52-288.968-291.134 0-162.606 124.008-286.802 287.524-286.802 133.914 0 203.93 74.63 206.844 77.808a24 24 0 0 1 2.476 29.246l-44.76 69.31c-8.098 12.534-25.548 14.702-36.468 4.59-0.466-0.428-53.058-47.76-123.76-47.76-92.232 0-147.832 67.15-147.832 152.164 0 79.204 51.028 159.384 148.554 159.384 77.394 0 130.56-56.676 131.088-57.25 10.264-11.13 28.118-10.066 37.016 2.106l49.094 67.144a24.002 24.002 0 0 1-1.106 29.732z" p-id="89400"></path></svg>'
package/src/index.ts CHANGED
@@ -5,7 +5,7 @@ import './styles/index.scss'
5
5
  import 'element-plus/dist/index.css'
6
6
  import 'element-plus/theme-chalk/dark/css-vars.css'
7
7
 
8
- import { Theme } from 'vitepress'
8
+ import type { Theme } from 'vitepress'
9
9
  import DefaultTheme from 'vitepress/theme'
10
10
  import BlogApp from './components/BlogApp.vue'
11
11
  import { withConfigProvider } from './composables/config/blog'
@@ -22,7 +22,6 @@ export const BlogTheme: Theme = {
22
22
  Layout: withConfigProvider(BlogApp),
23
23
  enhanceApp(ctx) {
24
24
  DefaultTheme.enhanceApp(ctx)
25
- // @ts-ignore
26
25
  ctx.app.component('TimelinePage', TimelinePage)
27
26
  ctx.app.component('UserWorksPage', UserWorksPage)
28
27
  }
package/src/node.ts CHANGED
@@ -5,8 +5,8 @@ import type { Theme } from './composables/config/index'
5
5
  import {
6
6
  getMarkdownPlugins,
7
7
  registerMdPlugins,
8
- wrapperCfgWithMermaid,
9
- supportRunExtendsPlugin
8
+ supportRunExtendsPlugin,
9
+ wrapperCfgWithMermaid
10
10
  } from './utils/node/mdPlugins'
11
11
  import { getArticles, patchVPThemeConfig } from './utils/node/theme'
12
12
  import { getVitePlugins, registerVitePlugins } from './utils/node/vitePlugins'
Binary file
@@ -1,10 +1,5 @@
1
1
  @import 'highlight.scss';
2
2
 
3
- html,
4
- body,
5
- #app {
6
- height: 100%;
7
- }
8
3
  body {
9
4
  margin: 0;
10
5
  padding: 0;
@@ -11,7 +11,7 @@ export function formatDate(d: any, fmt = 'yyyy-MM-dd hh:mm:ss') {
11
11
  'm+': d.getMinutes(), // 分
12
12
  's+': d.getSeconds(), // 秒
13
13
  'q+': Math.floor((d.getMonth() + 3) / 3), // 季度
14
- S: d.getMilliseconds() // 毫秒
14
+ 'S': d.getMilliseconds() // 毫秒
15
15
  }
16
16
  if (/(y+)/.test(fmt)) {
17
17
  fmt = fmt.replace(
@@ -65,8 +65,8 @@ export function formatShowDate(date: Date | string) {
65
65
  return formatDate(new Date(date), 'yyyy-MM-dd')
66
66
  }
67
67
 
68
- const pattern =
69
- /[a-zA-Z0-9_\u0392-\u03c9\u00c0-\u00ff\u0600-\u06ff\u0400-\u04ff]+|[\u4e00-\u9fff\u3400-\u4dbf\uf900-\ufaff\u3040-\u309f\uac00-\ud7af]+/g
68
+ const pattern
69
+ = /[a-zA-Z0-9_\u0392-\u03C9\u00C0-\u00FF\u0600-\u06FF\u0400-\u04FF]+|[\u4E00-\u9FFF\u3400-\u4DBF\uF900-\uFAFF\u3040-\u309F\uAC00-\uD7AF]+/g
70
70
 
71
71
  // copy from https://github.com/youngjuning/vscode-juejin-wordcount/blob/main/count-word.ts
72
72
  export default function countWord(data: string) {
@@ -76,9 +76,10 @@ export default function countWord(data: string) {
76
76
  return 0
77
77
  }
78
78
  for (let i = 0; i < m.length; i += 1) {
79
- if (m[i].charCodeAt(0) >= 0x4e00) {
79
+ if (m[i].charCodeAt(0) >= 0x4E00) {
80
80
  count += m[i].length
81
- } else {
81
+ }
82
+ else {
82
83
  count += 1
83
84
  }
84
85
  }
@@ -87,7 +88,7 @@ export default function countWord(data: string) {
87
88
 
88
89
  export function chineseSearchOptimize(input: string) {
89
90
  return input
90
- .replace(/[\u4e00-\u9fa5]/g, ' $& ')
91
+ .replace(/[\u4E00-\u9FA5]/g, ' $& ')
91
92
  .replace(/\s+/g, ' ')
92
93
  .trim()
93
94
  }
@@ -105,7 +106,7 @@ export function getGithubUpdateTime(url: string) {
105
106
  }
106
107
  const [owner, repo] = match[1].split('/')
107
108
  return fetch(`https://api.github.com/repos/${owner}/${repo}`)
108
- .then((res) => res.json())
109
+ .then(res => res.json())
109
110
  .then((res) => {
110
111
  return res.updated_at
111
112
  })
@@ -128,7 +129,7 @@ export function getGithubDirUpdateTime(
128
129
  baseUrl += `?path=${dir}`
129
130
  }
130
131
  return fetch(baseUrl)
131
- .then((res) => res.json())
132
+ .then(res => res.json())
132
133
  .then((res) => {
133
134
  return [res].flat()[0].commit.committer.date
134
135
  })
@@ -1,17 +1,18 @@
1
1
  /* eslint-disable no-console */
2
- import path from 'path'
3
- import fs, { writeFileSync } from 'fs'
2
+ import path from 'node:path'
3
+ import fs, { writeFileSync } from 'node:fs'
4
4
  import { Feed } from 'feed'
5
5
  import type { SiteConfig } from 'vitepress'
6
6
  import type { Theme } from '../../composables/config/index'
7
- import { withBase } from './index'
8
7
  import { pageMap } from './theme'
8
+ import { withBase } from './index'
9
9
 
10
10
  export async function genFeed(config: SiteConfig) {
11
11
  const blogCfg: Theme.BlogConfig = config.userConfig.themeConfig.blog
12
12
  let posts: Theme.PageData[] = blogCfg.pagesData
13
13
  const { RSS, authorList = [] } = blogCfg
14
- if (!RSS) return
14
+ if (!RSS)
15
+ return
15
16
  const { createMarkdownRenderer } = await import('vitepress')
16
17
 
17
18
  const mdRender = await createMarkdownRenderer(
@@ -38,9 +39,9 @@ export async function genFeed(config: SiteConfig) {
38
39
 
39
40
  posts = posts
40
41
  // 过滤掉 layout:home
41
- .filter((v) => v.meta.layout !== 'home')
42
+ .filter(v => v.meta.layout !== 'home')
42
43
  // 过滤掉不展示的
43
- .filter((v) => v.meta.hidden !== true)
44
+ .filter(v => v.meta.hidden !== true)
44
45
 
45
46
  if (undefined !== RSS?.limit && RSS?.limit > 0) {
46
47
  posts.splice(RSS.limit)
@@ -59,7 +60,7 @@ export async function genFeed(config: SiteConfig) {
59
60
  link = link.endsWith('/')
60
61
  ? link
61
62
  : `${link}${config?.cleanUrls ? '' : '.html'}`
62
- const authorLink = authorList.find((v) => v.nickname === author)?.url
63
+ const authorLink = authorList.find(v => v.nickname === author)?.url
63
64
  let html
64
65
  const filepath = pageMap.get(route)
65
66
  if (filepath) {
@@ -1,6 +1,6 @@
1
1
  /* eslint-disable global-require */
2
2
  /* eslint-disable prefer-rest-params */
3
- import { spawn, spawnSync } from 'child_process'
3
+ import { spawn, spawnSync } from 'node:child_process'
4
4
  import { formatDate } from '../client'
5
5
 
6
6
  export function clearMatterContent(content: string) {
@@ -15,7 +15,8 @@ export function clearMatterContent(content: string) {
15
15
  if (line.trim() === '---') {
16
16
  if (first___ === undefined) {
17
17
  first___ = pre.length
18
- } else if (second___ === undefined) {
18
+ }
19
+ else if (second___ === undefined) {
19
20
  second___ = pre.length
20
21
  }
21
22
  }
@@ -30,8 +31,8 @@ export function clearMatterContent(content: string) {
30
31
  )
31
32
  }
32
33
  export function getDefaultTitle(content: string) {
33
- const title =
34
- clearMatterContent(content)
34
+ const title
35
+ = clearMatterContent(content)
35
36
  .split('\n')
36
37
  ?.find((str) => {
37
38
  return str.startsWith('# ')
@@ -53,7 +54,8 @@ export function getFileBirthTime(url: string) {
53
54
  if (infoStr) {
54
55
  date = new Date(infoStr)
55
56
  }
56
- } catch (error) {
57
+ }
58
+ catch (error) {
57
59
  return formatDate(date)
58
60
  }
59
61
 
@@ -87,7 +89,7 @@ export function getTextSummary(text: string, count = 100) {
87
89
  // 除去加粗
88
90
  ?.replace(/\*\*(.*?)\*\*/g, '$1')
89
91
  ?.split('\n')
90
- ?.filter((v) => !!v)
92
+ ?.filter(v => !!v)
91
93
  ?.slice(1)
92
94
  ?.join('\n')
93
95
  ?.replace(/>(.*)/, '')
@@ -1,8 +1,8 @@
1
1
  /* eslint-disable global-require */
2
2
  import { tabsMarkdownPlugin } from 'vitepress-plugin-tabs'
3
3
  import type { UserConfig } from 'vitepress'
4
- import { aliasObjectToArray } from './index'
5
4
  import type { Theme } from '../../composables/config/index'
5
+ import { aliasObjectToArray } from './index'
6
6
 
7
7
  export function getMarkdownPlugins(cfg?: Partial<Theme.BlogConfig>) {
8
8
  const markdownPlugin: any[] = []
@@ -38,33 +38,39 @@ export function registerMdPlugins(vpCfg: any, plugins: any[]) {
38
38
  * 流程图支持,配置mermaid
39
39
  */
40
40
  export function assignMermaid(config: any) {
41
- if (!config?.mermaid) return
41
+ if (!config?.mermaid)
42
+ return
42
43
 
43
- if (!config.vite) config.vite = {}
44
- if (!config.vite.plugins) config.vite.plugins = []
44
+ if (!config.vite)
45
+ config.vite = {}
46
+ if (!config.vite.plugins)
47
+ config.vite.plugins = []
45
48
  const { MermaidPlugin } = require('vitepress-plugin-mermaid')
46
49
  config.vite.plugins.push(MermaidPlugin(config.mermaid))
47
- if (!config.vite.resolve) config.vite.resolve = {}
48
- if (!config.vite.resolve.alias) config.vite.resolve.alias = {}
50
+ if (!config.vite.resolve)
51
+ config.vite.resolve = {}
52
+ if (!config.vite.resolve.alias)
53
+ config.vite.resolve.alias = {}
49
54
 
50
55
  config.vite.resolve.alias = [
51
56
  ...aliasObjectToArray({
52
57
  ...config.vite.resolve.alias,
53
58
  'cytoscape/dist/cytoscape.umd.js': 'cytoscape/dist/cytoscape.esm.js',
54
- mermaid: 'mermaid/dist/mermaid.esm.mjs'
59
+ 'mermaid': 'mermaid/dist/mermaid.esm.mjs'
55
60
  }),
56
61
  { find: /^dayjs\/(.*).js/, replacement: 'dayjs/esm/$1' }
57
62
  ]
58
63
  }
59
64
 
60
65
  export function wrapperCfgWithMermaid(config: UserConfig<Theme.Config>): any {
61
- // @ts-ignore
62
- const extendThemeConfig = (config.extends?.themeConfig?.blog ||
63
- {}) as Theme.BlogConfig
66
+ // eslint-disable-next-line ts/ban-ts-comment
67
+ // @ts-expect-error
68
+ const extendThemeConfig = (config.extends?.themeConfig?.blog
69
+ || {}) as Theme.BlogConfig
64
70
 
65
71
  // 开关支持Mermaid
66
- const resultConfig =
67
- extendThemeConfig.mermaid === false
72
+ const resultConfig
73
+ = extendThemeConfig.mermaid === false
68
74
  ? config
69
75
  : {
70
76
  ...config,
@@ -77,17 +83,18 @@ export function wrapperCfgWithMermaid(config: UserConfig<Theme.Config>): any {
77
83
 
78
84
  export function supportRunExtendsPlugin(config: UserConfig<Theme.Config>) {
79
85
  // 处理markdown插件
80
- if (!config.markdown) config.markdown = {}
86
+ if (!config.markdown)
87
+ config.markdown = {}
81
88
  // 支持运行继承的markdown插件
82
- // @ts-ignore
89
+ // @ts-expect-error
83
90
  if (config.extends?.markdown?.config) {
84
- const markdownExtendsConfigOriginal =
85
- // @ts-ignore
86
- config.extends?.markdown?.config
91
+ const markdownExtendsConfigOriginal
92
+ // @ts-expect-error
93
+ = config.extends?.markdown?.config
87
94
  const selfMarkdownConfig = config.markdown?.config
88
95
 
89
96
  config.markdown.config = (...rest: any[]) => {
90
- // @ts-ignore
97
+ // @ts-expect-error
91
98
  selfMarkdownConfig?.(...rest)
92
99
  markdownExtendsConfigOriginal?.(...rest)
93
100
  }
@@ -97,10 +104,10 @@ export function supportRunExtendsPlugin(config: UserConfig<Theme.Config>) {
97
104
  const inlineConfig = config.extends as UserConfig<Theme.Config>
98
105
 
99
106
  if (
100
- inlineConfig.themeConfig?.blog?.RSS &&
101
- inlineConfig.themeConfig?.blog?.RSS?.icon !== false &&
102
- inlineConfig.themeConfig?.socialLinks?.length &&
103
- !inlineConfig.themeConfig?.socialLinks?.[0].link
107
+ inlineConfig.themeConfig?.blog?.RSS
108
+ && inlineConfig.themeConfig?.blog?.RSS?.icon !== false
109
+ && inlineConfig.themeConfig?.socialLinks?.length
110
+ && !inlineConfig.themeConfig?.socialLinks?.[0].link
104
111
  ) {
105
112
  const { RSS } = inlineConfig.themeConfig?.blog
106
113
  inlineConfig.themeConfig.socialLinks[0].link = `${RSS.baseUrl}${
@@ -1,11 +1,12 @@
1
1
  /* eslint-disable prefer-rest-params */
2
+ import fs from 'node:fs'
3
+ import path from 'node:path'
4
+ import process from 'node:process'
2
5
  import glob from 'fast-glob'
3
6
  import matter from 'gray-matter'
4
- import fs from 'fs'
5
- import path from 'path'
6
7
  import type { Theme } from '../../composables/config/index'
7
- import { getDefaultTitle, getFileBirthTime, getTextSummary } from './index'
8
8
  import { formatDate } from '../client'
9
+ import { getDefaultTitle, getFileBirthTime, getTextSummary } from './index'
9
10
 
10
11
  export function patchDefaultThemeSideBar(cfg?: Partial<Theme.BlogConfig>) {
11
12
  return cfg?.blog !== false && cfg?.recommend !== false
@@ -44,7 +45,8 @@ export function getArticles(cfg?: Partial<Theme.BlogConfig>) {
44
45
  ),
45
46
  ''
46
47
  )
47
- } else {
48
+ }
49
+ else {
48
50
  route = route.replace(
49
51
  new RegExp(
50
52
  `^${path
@@ -75,7 +77,8 @@ export function getArticles(cfg?: Partial<Theme.BlogConfig>) {
75
77
  // meta.date = formatDate(v)
76
78
  // })
77
79
  meta.date = getFileBirthTime(v)
78
- } else {
80
+ }
81
+ else {
79
82
  const timeZone = cfg?.timeZone ?? 8
80
83
  meta.date = formatDate(
81
84
  new Date(`${new Date(meta.date).toUTCString()}+${timeZone}`)
@@ -83,8 +86,8 @@ export function getArticles(cfg?: Partial<Theme.BlogConfig>) {
83
86
  }
84
87
 
85
88
  // 处理tags和categories,兼容历史文章
86
- meta.categories =
87
- typeof meta.categories === 'string'
89
+ meta.categories
90
+ = typeof meta.categories === 'string'
88
91
  ? [meta.categories]
89
92
  : meta.categories
90
93
  meta.tags = typeof meta.tags === 'string' ? [meta.tags] : meta.tags
@@ -96,13 +99,13 @@ export function getArticles(cfg?: Partial<Theme.BlogConfig>) {
96
99
 
97
100
  // 获取摘要信息
98
101
  const wordCount = 100
99
- meta.description =
100
- meta.description || getTextSummary(fileContent, wordCount)
102
+ meta.description
103
+ = meta.description || getTextSummary(fileContent, wordCount)
101
104
 
102
105
  // 获取封面图
103
- meta.cover =
104
- meta.cover ??
105
- (fileContent.match(/[!]\[.*?\]\((https:\/\/.+)\)/)?.[1] || '')
106
+ meta.cover
107
+ = meta.cover
108
+ ?? (fileContent.match(/[!]\[.*?\]\((https:\/\/.+)\)/)?.[1] || '')
106
109
 
107
110
  // 是否发布 默认发布
108
111
  if (meta.publish === false) {
@@ -115,7 +118,7 @@ export function getArticles(cfg?: Partial<Theme.BlogConfig>) {
115
118
  meta
116
119
  }
117
120
  })
118
- .filter((v) => v.meta.layout !== 'home')
121
+ .filter(v => v.meta.layout !== 'home')
119
122
  return data as Theme.PageData[]
120
123
  }
121
124
 
@@ -1,9 +1,10 @@
1
+ import path from 'node:path'
2
+ import { execSync } from 'node:child_process'
3
+ import process from 'node:process'
1
4
  import type { SiteConfig } from 'vitepress'
2
- import path from 'path'
3
- import { execSync } from 'child_process'
4
5
  import {
5
- pagefindPlugin,
6
- chineseSearchOptimize
6
+ chineseSearchOptimize,
7
+ pagefindPlugin
7
8
  } from 'vitepress-plugin-pagefind'
8
9
  import type { Theme } from '../../composables/config/index'
9
10
  import { genFeed } from './genFeed'
@@ -101,8 +102,8 @@ export function inlineBuildEndPlugin(buildEndFn: any[]) {
101
102
  vitepressConfig.buildEnd = (siteCfg) => {
102
103
  selfBuildEnd?.(siteCfg)
103
104
  buildEndFn
104
- .filter((fn) => typeof fn === 'function')
105
- .forEach((fn) => fn(siteCfg))
105
+ .filter(fn => typeof fn === 'function')
106
+ .forEach(fn => fn(siteCfg))
106
107
  }
107
108
  }
108
109
  }
@@ -1,5 +1,5 @@
1
1
  declare module '*.vue' {
2
- import { ComponentOptions } from 'vue'
2
+ import type { ComponentOptions } from 'vue'
3
3
 
4
4
  const comp: ComponentOptions
5
5
  export default comp