@sugarat/theme 0.3.2 → 0.3.4

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.
package/node.d.ts CHANGED
@@ -91,7 +91,10 @@ declare namespace Theme {
91
91
  }
92
92
  interface activeTag {
93
93
  label: string;
94
- type: string;
94
+ /**
95
+ * @type {string}
96
+ */
97
+ type: any;
95
98
  }
96
99
  type CommentConfig = ((GiscusOption & CommentCommonConfig) | GiscusConfig | ArtalkConfig);
97
100
  interface CommentCommonConfig {
@@ -412,6 +415,10 @@ declare namespace Theme {
412
415
  * @default true
413
416
  */
414
417
  darkTransition?: boolean;
418
+ /**
419
+ * 渲染时替换图片地址
420
+ */
421
+ imageStyle?: ImageStyleConfig;
415
422
  }
416
423
  interface BackToTop {
417
424
  /**
@@ -507,6 +514,26 @@ declare namespace Theme {
507
514
  */
508
515
  expand?: boolean;
509
516
  }
517
+ interface ReplaceRule {
518
+ /**
519
+ * 匹配规则
520
+ */
521
+ rule: string | RegExp;
522
+ /**
523
+ * 直接追加后缀
524
+ */
525
+ suffix?: string;
526
+ /**
527
+ * 替换函数或字符串(优先级高于 suffix)
528
+ */
529
+ replace?: string | ((match: string) => string);
530
+ }
531
+ interface ImageStyleConfig {
532
+ /**
533
+ * 首页封面预览图
534
+ */
535
+ coverPreview?: ReplaceRule | ReplaceRule[];
536
+ }
510
537
  }
511
538
 
512
539
  /**
package/node.js CHANGED
@@ -40,7 +40,7 @@ module.exports = __toCommonJS(node_exports);
40
40
  // src/utils/node/mdPlugins.ts
41
41
  var import_module = require("module");
42
42
 
43
- // ../../node_modules/.pnpm/vitepress-plugin-tabs@0.2.0_vitepress@1.1.4_@algolia+client-search@4.19.1_@types+node@20.6.3__ee2wap4ljxfukruj47sfuqlmqq/node_modules/vitepress-plugin-tabs/dist/index.js
43
+ // ../../node_modules/.pnpm/vitepress-plugin-tabs@0.2.0_vitepress@1.1.4_@algolia+client-search@4.19.1_@types+node@20.6.3__scid7oqqpyg2qxcz73ypk7jzz4/node_modules/vitepress-plugin-tabs/dist/index.js
44
44
  var tabsMarker = "=tabs";
45
45
  var tabsMarkerLen = tabsMarker.length;
46
46
  var ruleBlockTabs = (state, startLine, endLine, silent) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sugarat/theme",
3
- "version": "0.3.2",
3
+ "version": "0.3.4",
4
4
  "description": "简约风的 Vitepress 博客主题,sugarat vitepress blog theme",
5
5
  "author": "sugar",
6
6
  "license": "MIT",
@@ -32,35 +32,38 @@
32
32
  "src",
33
33
  "types"
34
34
  ],
35
+ "peerDependencies": {
36
+ "@element-plus/icons-vue": "^2.3.1",
37
+ "element-plus": "^2.7"
38
+ },
35
39
  "dependencies": {
36
- "@giscus/vue": "^2.3.0",
37
- "@mdit-vue/shared": "^0.12.0",
40
+ "@giscus/vue": "^2.4.0",
41
+ "@mdit-vue/shared": "^0.12.1",
38
42
  "@mermaid-js/mermaid-mindmap": "^9.3.0",
39
- "@vue/shared": "^3.2.45",
40
- "@vueuse/core": "^9.6.0",
41
- "fast-glob": "^3.2.12",
43
+ "@vue/shared": "^3.4.26",
44
+ "@vueuse/core": "^9.13.0",
45
+ "fast-glob": "^3.3.2",
42
46
  "gray-matter": "^4.0.3",
43
47
  "markdown-it-task-checkbox": "^1.0.6",
44
- "mermaid": "^10.2.4",
45
- "oh-my-live2d": "^0.15.2",
46
- "swiper": "^11.0.5",
48
+ "mermaid": "^10.9.0",
49
+ "oh-my-live2d": "^0.17.0",
50
+ "swiper": "^11.1.1",
47
51
  "vitepress-markdown-timeline": "^1.2.1",
48
52
  "vitepress-plugin-mermaid": "2.0.13",
53
+ "vitepress-plugin-tabs": "0.2.0",
49
54
  "vitepress-plugin-pagefind": "0.2.14",
50
- "vitepress-plugin-rss": "0.2.2",
51
- "vitepress-plugin-tabs": "0.2.0"
55
+ "vitepress-plugin-rss": "0.2.4"
52
56
  },
53
57
  "devDependencies": {
54
- "@element-plus/icons-vue": "^2.1.0",
55
- "artalk": "^2.8.3",
56
- "element-plus": "^2.3.4",
57
- "javascript-stringify": "^2.1.0",
58
- "pagefind": "1.0.3",
59
- "sass": "^1.56.1",
60
- "typescript": "^4.8.2",
61
- "vite": "^5",
58
+ "@element-plus/icons-vue": "^2.3.1",
59
+ "artalk": "^2.8.5",
60
+ "element-plus": "^2.7.2",
61
+ "pagefind": "1.1.0",
62
+ "sass": "^1.76.0",
63
+ "typescript": "^5.4.5",
64
+ "vite": "^5.2.11",
62
65
  "vitepress": "1.1.4",
63
- "vue": "^3.4.21"
66
+ "vue": "^3.4.26"
64
67
  },
65
68
  "scripts": {
66
69
  "dev": "npm run build:node && npm run dev:docs",
@@ -102,7 +102,7 @@ watch(
102
102
  fill="#D3D3D3" p-id="4294"
103
103
  />
104
104
  </svg> 标签</span>
105
- <ElTag v-if="activeTag.label" :type="activeTag.type as any" :effect="colorMode" closable @close="handleCloseTag">
105
+ <ElTag v-if="activeTag.label" :type="activeTag.type || 'primary'" :effect="colorMode" closable @close="handleCloseTag">
106
106
  {{ activeTag.label }}
107
107
  </ElTag>
108
108
  </div>
@@ -110,7 +110,7 @@ watch(
110
110
  <ul class="tag-list">
111
111
  <li v-for="(tag, idx) in tags" :key="tag">
112
112
  <ElTag
113
- :type="tagType[idx % tagType.length]" :effect="colorMode"
113
+ :type="tagType[idx % tagType.length] || 'primary'" :effect="colorMode"
114
114
  @click="handleTagClick(tag, tagType[idx % tagType.length])"
115
115
  >
116
116
  {{ tag }}
@@ -2,7 +2,7 @@
2
2
  import { useRouter, withBase } from 'vitepress'
3
3
  import { computed } from 'vue'
4
4
  import { formatShowDate, wrapperCleanUrls } from '../utils/client'
5
- import { useCleanUrls } from '../composables/config/blog'
5
+ import { useCleanUrls, useImageStyle } from '../composables/config/blog'
6
6
 
7
7
  const props = defineProps<{
8
8
  route: string
@@ -13,7 +13,7 @@ const props = defineProps<{
13
13
  descriptionHTML?: string
14
14
  tag?: string[]
15
15
  author?: string
16
- cover?: string | boolean
16
+ cover?: string | false
17
17
  pin?: number
18
18
  }>()
19
19
  const showTime = computed(() => {
@@ -26,6 +26,40 @@ const router = useRouter()
26
26
  function handleSkipDoc() {
27
27
  router.go(link.value)
28
28
  }
29
+
30
+ const { coverPreview } = useImageStyle()
31
+
32
+ const resultCover = computed(() => {
33
+ if (!props.cover) {
34
+ return ''
35
+ }
36
+ const baseCover = withBase(props.cover)
37
+ const coverRule = [coverPreview]
38
+ .flat()
39
+ .filter(v => !!v)
40
+ .find((coverRule) => {
41
+ if (!coverRule) {
42
+ return false
43
+ }
44
+ return coverRule.rule instanceof RegExp ? coverRule.rule.test(baseCover) : baseCover.includes(coverRule.rule)
45
+ })
46
+
47
+ if (!coverRule) {
48
+ return baseCover
49
+ }
50
+ const { suffix, replace, rule } = coverRule
51
+ if (!replace && suffix) {
52
+ return `${baseCover}${suffix}`
53
+ }
54
+ if (typeof replace === 'function') {
55
+ return replace(baseCover)
56
+ }
57
+ if (typeof replace === 'string') {
58
+ return baseCover.replace(rule, replace)
59
+ }
60
+
61
+ return baseCover
62
+ })
29
63
  </script>
30
64
 
31
65
  <template>
@@ -62,7 +96,7 @@ function handleSkipDoc() {
62
96
  </div>
63
97
  </div>
64
98
  <!-- 右侧封面图 -->
65
- <div v-show="cover" class="cover-img" :style="`background-image: url(${withBase(`${cover}`)});`" />
99
+ <div v-show="cover" class="cover-img" :style="`background-image: url(${resultCover});`" />
66
100
  </div>
67
101
  <!-- 底部补充描述 -->
68
102
  <div class="badge-list mobile-visible">
@@ -1,5 +1,5 @@
1
1
  <script setup lang="ts">
2
- import { computed, watch } from 'vue'
2
+ import { computed, onMounted } from 'vue'
3
3
  import { ElPagination } from 'element-plus'
4
4
  import { useData, useRouter } from 'vitepress'
5
5
  import { useBrowserLocation } from '@vueuse/core'
@@ -60,32 +60,34 @@ function handleUpdatePageNum(current: number) {
60
60
  if (currentPage.value === current) {
61
61
  return
62
62
  }
63
- currentPage.value = current
64
63
  const { searchParams } = new URL(window.location.href!)
65
64
  searchParams.delete(queryPageNumKey)
66
65
  searchParams.append(queryPageNumKey, String(current))
66
+ window.scrollTo({ top: 0, behavior: 'auto' })
67
67
  router.go(
68
- `${location.value.origin}${router.route.path}?${searchParams.toString()}`
68
+ `${router.route.path}?${searchParams.toString()}`
69
69
  )
70
70
  }
71
71
 
72
- watch(
73
- location,
74
- () => {
75
- if (location.value.href) {
76
- const { searchParams } = new URL(location.value.href)
77
- if (searchParams.has(queryPageNumKey)) {
78
- currentPage.value = Number(searchParams.get(queryPageNumKey))
79
- }
80
- else {
81
- currentPage.value = 1
82
- }
72
+ function refreshCurrentPage(search?: string) {
73
+ if (location.value?.href) {
74
+ const searchParams = new URLSearchParams(search || location.value.search)
75
+ const pageNum = Number(searchParams.get(queryPageNumKey)) || 1
76
+ if (pageNum !== currentPage.value) {
77
+ currentPage.value = pageNum
83
78
  }
84
- },
85
- {
86
- immediate: true
87
79
  }
88
- )
80
+ }
81
+ router.onBeforeRouteChange = (to) => {
82
+ refreshCurrentPage(to.slice(to.indexOf('?') + 1))
83
+ }
84
+ // 未覆盖的场景处理
85
+ router.onAfterRouteChanged = (to) => {
86
+ refreshCurrentPage(to.slice(to.indexOf('?') + 1))
87
+ }
88
+ onMounted(() => {
89
+ refreshCurrentPage()
90
+ })
89
91
  </script>
90
92
 
91
93
  <template>
@@ -229,3 +229,7 @@ export function useCleanUrls() {
229
229
  const { site } = useData()
230
230
  return !!site.value.cleanUrls
231
231
  }
232
+
233
+ export function useImageStyle() {
234
+ return inject(configSymbol)?.value?.blog?.imageStyle || {} as Theme.ImageStyleConfig
235
+ }
@@ -97,7 +97,10 @@ export namespace Theme {
97
97
  }
98
98
  export interface activeTag {
99
99
  label: string
100
- type: string
100
+ /**
101
+ * @type {string}
102
+ */
103
+ type: any
101
104
  }
102
105
 
103
106
  export type CommentConfig = ((GiscusOption & CommentCommonConfig) | GiscusConfig | ArtalkConfig)
@@ -446,6 +449,10 @@ export namespace Theme {
446
449
  * @default true
447
450
  */
448
451
  darkTransition?: boolean
452
+ /**
453
+ * 渲染时替换图片地址
454
+ */
455
+ imageStyle?: ImageStyleConfig
449
456
  }
450
457
 
451
458
  export interface BackToTop {
@@ -547,4 +554,25 @@ export namespace Theme {
547
554
  */
548
555
  expand?: boolean
549
556
  }
557
+
558
+ export interface ReplaceRule {
559
+ /**
560
+ * 匹配规则
561
+ */
562
+ rule: string | RegExp
563
+ /**
564
+ * 直接追加后缀
565
+ */
566
+ suffix?: string
567
+ /**
568
+ * 替换函数或字符串(优先级高于 suffix)
569
+ */
570
+ replace?: string | ((match: string) => string)
571
+ }
572
+ export interface ImageStyleConfig {
573
+ /**
574
+ * 首页封面预览图
575
+ */
576
+ coverPreview?: ReplaceRule | ReplaceRule[]
577
+ }
550
578
  }
package/src/index.ts CHANGED
@@ -2,7 +2,18 @@
2
2
  import './styles/index.scss'
3
3
 
4
4
  // element-ui
5
- import 'element-plus/dist/index.css'
5
+ // import 'element-plus/dist/index.css'
6
+ import 'element-plus/theme-chalk/base.css'
7
+ import 'element-plus/theme-chalk/el-button.css'
8
+ import 'element-plus/theme-chalk/el-tag.css'
9
+ import 'element-plus/theme-chalk/el-icon.css'
10
+ import 'element-plus/theme-chalk/el-avatar.css'
11
+ import 'element-plus/theme-chalk/el-image.css'
12
+ import 'element-plus/theme-chalk/el-image-viewer.css'
13
+ import 'element-plus/theme-chalk/el-pagination.css'
14
+ import 'element-plus/theme-chalk/el-carousel.css'
15
+ import 'element-plus/theme-chalk/el-carousel-item.css'
16
+ import 'element-plus/theme-chalk/el-alert.css'
6
17
  import 'element-plus/theme-chalk/dark/css-vars.css'
7
18
 
8
19
  // 引入时间线组件样式
@@ -12,6 +23,7 @@ import DefaultTheme from 'vitepress/theme'
12
23
  import { enhanceAppWithTabs } from 'vitepress-plugin-tabs/client'
13
24
 
14
25
  // 图表渲染组件
26
+ // @ts-expect-error
15
27
  import Mermaid from 'vitepress-plugin-mermaid/Mermaid.vue'
16
28
  import BlogApp from './components/BlogApp.vue'
17
29
  import { withConfigProvider } from './composables/config/blog'
@@ -192,4 +192,9 @@ span.svg-icon {
192
192
  font-weight: bold;
193
193
  background-color: var(--vp-c-brand-1);
194
194
  }
195
+ }
196
+
197
+ .VPImage.logo{
198
+ width: 24px;
199
+ height: 24px;
195
200
  }