@sugarat/theme 0.5.15 → 0.5.17

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
@@ -1,4 +1,5 @@
1
1
  import { DefaultTheme, UserConfig } from 'vitepress';
2
+ import { BackToTopPluginOptions } from 'vitepress-plugin-back2top';
2
3
  import { RSSOptions } from 'vitepress-plugin-rss';
3
4
  import { Repo, Mapping } from '@giscus/vue';
4
5
  import { Options } from 'oh-my-live2d';
@@ -106,6 +107,7 @@ declare namespace Theme {
106
107
  inputPosition?: 'top' | 'bottom';
107
108
  lang?: string;
108
109
  loading?: 'lazy' | 'eager';
110
+ showCommentBtn?: boolean;
109
111
  }
110
112
  interface ArtalkOption {
111
113
  site: string;
@@ -498,17 +500,7 @@ declare namespace Theme {
498
500
  */
499
501
  weeksAgo?: string;
500
502
  } | ((date: Date | string) => string);
501
- interface BackToTop {
502
- /**
503
- * 距离顶部多少距离出现
504
- * @default 450
505
- */
506
- top?: number;
507
- /**
508
- * 设置展示图标,svg
509
- * @recommend https://iconbuddy.app/search?q=fire
510
- */
511
- icon?: string;
503
+ interface BackToTop extends BackToTopPluginOptions {
512
504
  }
513
505
  interface TaskCheckbox {
514
506
  disabled?: boolean;
@@ -627,6 +619,19 @@ declare namespace Theme {
627
619
  * @default 999
628
620
  */
629
621
  limit?: number;
622
+ /**
623
+ * 标签排序方式
624
+ * desc: 降序
625
+ * asc: 升序
626
+ * normal: 不排序 (默认)
627
+ * @default 'normal'
628
+ */
629
+ sort?: 'desc' | 'asc' | 'normal';
630
+ /**
631
+ * 是否显示文章数量
632
+ * @default false
633
+ */
634
+ showCount?: boolean;
630
635
  }
631
636
  }
632
637
 
package/node.js CHANGED
@@ -463,13 +463,6 @@ async function getArticles(cfg, vpConfig) {
463
463
  }
464
464
  function patchVPConfig(vpConfig, cfg) {
465
465
  vpConfig.head = vpConfig.head || [];
466
- if (cfg?.comment && "type" in cfg.comment && cfg?.comment?.type === "artalk") {
467
- const server = cfg.comment?.options?.server;
468
- if (server) {
469
- vpConfig.head.push(["link", { href: `${server} /dist/Artalk.css`, rel: "stylesheet" }]);
470
- vpConfig.head.push(["script", { src: `${server} /dist/Artalk.js`, id: "artalk-script" }]);
471
- }
472
- }
473
466
  }
474
467
  function patchVPThemeConfig(cfg, vpThemeConfig = {}) {
475
468
  vpThemeConfig.sidebar = patchDefaultThemeSideBar(cfg)?.sidebar;
@@ -487,6 +480,9 @@ var import_vitepress_plugin_pagefind = require("vitepress-plugin-pagefind");
487
480
  var import_vitepress_plugin_rss = require("vitepress-plugin-rss");
488
481
  var import_theme_shared4 = require("@sugarat/theme-shared");
489
482
  var import_vitepress_plugin_announcement = require("vitepress-plugin-announcement");
483
+ var import_vitepress_plugin_artalk = require("vitepress-plugin-artalk");
484
+ var import_vitepress_plugin_back2top = require("vitepress-plugin-back2top");
485
+ var import_vitepress_plugin_giscus = require("vitepress-plugin-giscus");
490
486
  var import_vitepress_plugin_group_icons2 = require("vitepress-plugin-group-icons");
491
487
  var import_vitepress_plugin_image_preview = require("vitepress-plugin-image-preview");
492
488
 
@@ -595,6 +591,25 @@ function getVitePlugins(cfg = {}) {
595
591
  ;
596
592
  [cfg?.RSS].flat().forEach((rssConfig) => plugins.push((0, import_vitepress_plugin_rss.RssPlugin)(rssConfig)));
597
593
  }
594
+ if (cfg?.comment && typeof cfg.comment !== "boolean") {
595
+ const commentConfig = cfg.comment;
596
+ const isArtalk = commentConfig.type === "artalk";
597
+ if (isArtalk) {
598
+ plugins.push((0, import_vitepress_plugin_artalk.artalkPlugin)(commentConfig.options));
599
+ }
600
+ const isGiscus = commentConfig.type === "giscus" || commentConfig.repo;
601
+ if (isGiscus) {
602
+ const { mobileMinify, label, icon } = commentConfig;
603
+ const options = {
604
+ ...commentConfig.options,
605
+ ...commentConfig,
606
+ mobileMinify,
607
+ label,
608
+ icon
609
+ };
610
+ plugins.push((0, import_vitepress_plugin_giscus.giscusPlugin)(options));
611
+ }
612
+ }
598
613
  if (cfg?.popover) {
599
614
  plugins.push((0, import_vitepress_plugin_announcement.AnnouncementPlugin)(cfg.popover));
600
615
  }
@@ -608,6 +623,10 @@ function getVitePlugins(cfg = {}) {
608
623
  if (cfg?.timeline !== false) {
609
624
  plugins.push(patchTimelinePlugin());
610
625
  }
626
+ if (cfg?.backToTop !== false) {
627
+ const options = typeof cfg.backToTop === "object" ? cfg.backToTop : {};
628
+ plugins.push((0, import_vitepress_plugin_back2top.back2topPlugin)(options));
629
+ }
611
630
  return plugins;
612
631
  }
613
632
  function patchGroupIconPlugin() {
package/node.mjs CHANGED
@@ -430,13 +430,6 @@ async function getArticles(cfg, vpConfig) {
430
430
  }
431
431
  function patchVPConfig(vpConfig, cfg) {
432
432
  vpConfig.head = vpConfig.head || [];
433
- if (cfg?.comment && "type" in cfg.comment && cfg?.comment?.type === "artalk") {
434
- const server = cfg.comment?.options?.server;
435
- if (server) {
436
- vpConfig.head.push(["link", { href: `${server} /dist/Artalk.css`, rel: "stylesheet" }]);
437
- vpConfig.head.push(["script", { src: `${server} /dist/Artalk.js`, id: "artalk-script" }]);
438
- }
439
- }
440
433
  }
441
434
  function patchVPThemeConfig(cfg, vpThemeConfig = {}) {
442
435
  vpThemeConfig.sidebar = patchDefaultThemeSideBar(cfg)?.sidebar;
@@ -456,6 +449,9 @@ import {
456
449
  import { RssPlugin } from "vitepress-plugin-rss";
457
450
  import { cacheAllGitTimestamps, joinPath as joinPath2 } from "@sugarat/theme-shared";
458
451
  import { AnnouncementPlugin } from "vitepress-plugin-announcement";
452
+ import { artalkPlugin } from "vitepress-plugin-artalk";
453
+ import { back2topPlugin } from "vitepress-plugin-back2top";
454
+ import { giscusPlugin } from "vitepress-plugin-giscus";
459
455
  import { groupIconVitePlugin } from "vitepress-plugin-group-icons";
460
456
  import { ImagePreviewPlugin } from "vitepress-plugin-image-preview";
461
457
 
@@ -564,6 +560,25 @@ function getVitePlugins(cfg = {}) {
564
560
  ;
565
561
  [cfg?.RSS].flat().forEach((rssConfig) => plugins.push(RssPlugin(rssConfig)));
566
562
  }
563
+ if (cfg?.comment && typeof cfg.comment !== "boolean") {
564
+ const commentConfig = cfg.comment;
565
+ const isArtalk = commentConfig.type === "artalk";
566
+ if (isArtalk) {
567
+ plugins.push(artalkPlugin(commentConfig.options));
568
+ }
569
+ const isGiscus = commentConfig.type === "giscus" || commentConfig.repo;
570
+ if (isGiscus) {
571
+ const { mobileMinify, label, icon } = commentConfig;
572
+ const options = {
573
+ ...commentConfig.options,
574
+ ...commentConfig,
575
+ mobileMinify,
576
+ label,
577
+ icon
578
+ };
579
+ plugins.push(giscusPlugin(options));
580
+ }
581
+ }
567
582
  if (cfg?.popover) {
568
583
  plugins.push(AnnouncementPlugin(cfg.popover));
569
584
  }
@@ -577,6 +592,10 @@ function getVitePlugins(cfg = {}) {
577
592
  if (cfg?.timeline !== false) {
578
593
  plugins.push(patchTimelinePlugin());
579
594
  }
595
+ if (cfg?.backToTop !== false) {
596
+ const options = typeof cfg.backToTop === "object" ? cfg.backToTop : {};
597
+ plugins.push(back2topPlugin(options));
598
+ }
580
599
  return plugins;
581
600
  }
582
601
  function patchGroupIconPlugin() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sugarat/theme",
3
- "version": "0.5.15",
3
+ "version": "0.5.17",
4
4
  "description": "简约风的 Vitepress 博客主题,sugarat vitepress blog theme",
5
5
  "author": "sugar",
6
6
  "license": "MIT",
@@ -51,11 +51,14 @@
51
51
  "vitepress-plugin-group-icons": "1.6.5",
52
52
  "vitepress-plugin-mermaid": "2.0.13",
53
53
  "vitepress-plugin-tabs": "0.7.3",
54
- "@sugarat/theme-shared": "0.0.7",
55
54
  "vitepress-plugin-announcement": "0.1.7",
55
+ "@sugarat/theme-shared": "0.0.7",
56
+ "vitepress-plugin-giscus": "0.1.0",
56
57
  "vitepress-plugin-image-preview": "0.1.1",
58
+ "vitepress-plugin-rss": "0.4.3",
59
+ "vitepress-plugin-artalk": "0.1.0",
57
60
  "vitepress-plugin-pagefind": "0.4.19",
58
- "vitepress-plugin-rss": "0.4.3"
61
+ "vitepress-plugin-back2top": "0.1.0"
59
62
  },
60
63
  "devDependencies": {
61
64
  "artalk": "^2.8.5",
@@ -13,13 +13,8 @@ import BlogArticleAnalyze from './BlogArticleAnalyze.vue'
13
13
  import BlogAlert from './BlogAlert.vue'
14
14
  import BlogFooter from './BlogFooter.vue'
15
15
  import BlogHomeHeaderAvatar from './BlogHomeHeaderAvatar.vue'
16
- import BlogBackToTop from './BlogBackToTop.vue'
17
- import CommentGiscus from './CommentGiscus.vue'
18
16
  import BlogOml2d from './BlogOml2d.vue'
19
-
20
- import CommentArtalk from './CommentArtalk.vue'
21
17
  import BlogButtonAfterArticle from './BlogButtonAfterArticle.vue'
22
- import BlogCommentWrapper from './BlogCommentWrapper.vue'
23
18
 
24
19
  const { frontmatter } = useData()
25
20
  const layout = computed(() => frontmatter.value.layout)
@@ -86,11 +81,6 @@ const openTransition = useDarkTransitionConfig()
86
81
  <!-- 评论 -->
87
82
  <ClientOnly>
88
83
  <BlogButtonAfterArticle />
89
- <BlogBackToTop />
90
- <BlogCommentWrapper>
91
- <CommentArtalk />
92
- <CommentGiscus />
93
- </BlogCommentWrapper>
94
84
  </ClientOnly>
95
85
  </template>
96
86
  <template #layout-bottom>
@@ -31,13 +31,18 @@ const tagsWithCount = computed(() => {
31
31
  })
32
32
  })
33
33
  // 按文章数量降序排序
34
- return [...tagCountMap.entries()]
35
- .sort((a, b) => b[1] - a[1])
36
- .map(([tag, count]) => ({ tag, count }))
34
+ const data = [...tagCountMap.entries()]
35
+ const sort = (typeof homeTagsConfig.value === 'object' && homeTagsConfig.value?.sort) ? homeTagsConfig.value.sort : 'normal'
36
+ if (sort !== 'normal') {
37
+ data.sort((a, b) => {
38
+ return sort === 'asc' ? a[1] - b[1] : b[1] - a[1]
39
+ })
40
+ }
41
+ return data.map(([tag, count]) => ({ tag, count }))
37
42
  })
38
43
 
39
44
  // 折叠/展开功能,从配置中读取 limit,默认 10
40
- const showCount = computed(() => {
45
+ const limit = computed(() => {
41
46
  if (typeof homeTagsConfig.value === 'object' && homeTagsConfig.value?.limit) {
42
47
  return homeTagsConfig.value.limit
43
48
  }
@@ -45,12 +50,12 @@ const showCount = computed(() => {
45
50
  })
46
51
  const isExpanded = ref(false)
47
52
  const displayTags = computed(() => {
48
- if (isExpanded.value || tagsWithCount.value.length <= showCount.value) {
53
+ if (isExpanded.value || tagsWithCount.value.length <= limit.value) {
49
54
  return tagsWithCount.value
50
55
  }
51
- return tagsWithCount.value.slice(0, showCount.value)
56
+ return tagsWithCount.value.slice(0, limit.value)
52
57
  })
53
- const hasMore = computed(() => tagsWithCount.value.length > showCount.value)
58
+ const hasMore = computed(() => tagsWithCount.value.length > limit.value)
54
59
 
55
60
  function toggleExpand() {
56
61
  isExpanded.value = !isExpanded.value
@@ -130,7 +135,7 @@ watch(
130
135
  @click="handleTagClick(item.tag, tagType[idx % tagType.length])"
131
136
  >
132
137
  {{ item.tag }}
133
- <span class="tag-count">{{ item.count }}</span>
138
+ <span v-if="typeof homeTagsConfig === 'object' && homeTagsConfig?.showCount" class="tag-count">{{ item.count }}</span>
134
139
  </Tag>
135
140
  </li>
136
141
  </ul>
@@ -1,5 +1,6 @@
1
1
  /* eslint-disable ts/no-namespace */
2
2
  import type { DefaultTheme } from 'vitepress'
3
+ import type { BackToTopPluginOptions } from 'vitepress-plugin-back2top'
3
4
  import type { RSSOptions } from 'vitepress-plugin-rss'
4
5
  import type { Mapping, Repo } from '@giscus/vue'
5
6
  import type { Options as Oml2dOptions } from 'oh-my-live2d'
@@ -109,6 +110,7 @@ export namespace Theme {
109
110
  inputPosition?: 'top' | 'bottom'
110
111
  lang?: string
111
112
  loading?: 'lazy' | 'eager'
113
+ showCommentBtn?: boolean
112
114
  }
113
115
  export interface ArtalkOption {
114
116
  site: string
@@ -528,18 +530,7 @@ export namespace Theme {
528
530
  */
529
531
  weeksAgo?: string
530
532
  } | ((date: Date | string) => string)
531
- export interface BackToTop {
532
- /**
533
- * 距离顶部多少距离出现
534
- * @default 450
535
- */
536
- top?: number
537
-
538
- /**
539
- * 设置展示图标,svg
540
- * @recommend https://iconbuddy.app/search?q=fire
541
- */
542
- icon?: string
533
+ export interface BackToTop extends BackToTopPluginOptions {
543
534
  }
544
535
 
545
536
  export interface TaskCheckbox {
@@ -664,5 +655,18 @@ export namespace Theme {
664
655
  * @default 999
665
656
  */
666
657
  limit?: number
658
+ /**
659
+ * 标签排序方式
660
+ * desc: 降序
661
+ * asc: 升序
662
+ * normal: 不排序 (默认)
663
+ * @default 'normal'
664
+ */
665
+ sort?: 'desc' | 'asc' | 'normal'
666
+ /**
667
+ * 是否显示文章数量
668
+ * @default false
669
+ */
670
+ showCount?: boolean
667
671
  }
668
672
  }
@@ -128,14 +128,14 @@ export async function getArticles(cfg: Partial<Theme.BlogConfig>, vpConfig: Site
128
128
 
129
129
  export function patchVPConfig(vpConfig: any, cfg?: Partial<Theme.BlogConfig>) {
130
130
  vpConfig.head = vpConfig.head || []
131
- // Artalk 资源地址
132
- if (cfg?.comment && 'type' in cfg.comment && cfg?.comment?.type === 'artalk') {
133
- const server = cfg.comment?.options?.server
134
- if (server) {
135
- vpConfig.head.push(['link', { href: `${server} /dist/Artalk.css`, rel: 'stylesheet' }])
136
- vpConfig.head.push(['script', { src: `${server} /dist/Artalk.js`, id: 'artalk-script' }])
137
- }
138
- }
131
+ // // Artalk 资源地址
132
+ // if (cfg?.comment && 'type' in cfg.comment && cfg?.comment?.type === 'artalk') {
133
+ // const server = cfg.comment?.options?.server
134
+ // if (server) {
135
+ // vpConfig.head.push(['link', { href: `${server}/dist/Artalk.css`, rel: 'stylesheet' }])
136
+ // vpConfig.head.push(['script', { src: `${server}/dist/Artalk.js`, id: 'artalk-script' }])
137
+ // }
138
+ // }
139
139
  }
140
140
 
141
141
  export function patchVPThemeConfig(
@@ -6,6 +6,9 @@ import { RssPlugin } from 'vitepress-plugin-rss'
6
6
  import type { PluginOption } from 'vite'
7
7
  import { cacheAllGitTimestamps, joinPath } from '@sugarat/theme-shared'
8
8
  import { AnnouncementPlugin } from 'vitepress-plugin-announcement'
9
+ import { artalkPlugin } from 'vitepress-plugin-artalk'
10
+ import { back2topPlugin } from 'vitepress-plugin-back2top'
11
+ import { giscusPlugin } from 'vitepress-plugin-giscus'
9
12
  import { groupIconVitePlugin } from 'vitepress-plugin-group-icons'
10
13
  import { ImagePreviewPlugin } from 'vitepress-plugin-image-preview'
11
14
  import type { Theme } from '../../composables/config/index'
@@ -56,6 +59,27 @@ export function getVitePlugins(cfg: Partial<Theme.BlogConfig> = {}) {
56
59
  ;[cfg?.RSS].flat().forEach(rssConfig => plugins.push(RssPlugin(rssConfig)))
57
60
  }
58
61
 
62
+ // 内置支持 giscus 评论
63
+ if (cfg?.comment && typeof cfg.comment !== 'boolean') {
64
+ const commentConfig = cfg.comment
65
+ const isArtalk = (commentConfig as any).type === 'artalk'
66
+ if (isArtalk) {
67
+ plugins.push(artalkPlugin((commentConfig as any).options))
68
+ }
69
+ const isGiscus = (commentConfig as any).type === 'giscus' || (commentConfig as any).repo
70
+ if (isGiscus) {
71
+ const { mobileMinify, label, icon } = commentConfig
72
+ const options = {
73
+ ...(commentConfig as any).options,
74
+ ...commentConfig,
75
+ mobileMinify,
76
+ label,
77
+ icon
78
+ }
79
+ plugins.push(giscusPlugin(options))
80
+ }
81
+ }
82
+
59
83
  // 内置支持 全局公告
60
84
  if (cfg?.popover) {
61
85
  plugins.push(AnnouncementPlugin(cfg.popover))
@@ -76,6 +100,11 @@ export function getVitePlugins(cfg: Partial<Theme.BlogConfig> = {}) {
76
100
  if (cfg?.timeline !== false) {
77
101
  plugins.push(patchTimelinePlugin())
78
102
  }
103
+ // 内置支持 back-to-top
104
+ if (cfg?.backToTop !== false) {
105
+ const options = typeof cfg.backToTop === 'object' ? cfg.backToTop : {}
106
+ plugins.push(back2topPlugin(options))
107
+ }
79
108
  return plugins
80
109
  }
81
110