@sugarat/theme 0.5.15 → 0.5.16

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
@@ -627,6 +627,19 @@ declare namespace Theme {
627
627
  * @default 999
628
628
  */
629
629
  limit?: number;
630
+ /**
631
+ * 标签排序方式
632
+ * desc: 降序
633
+ * asc: 升序
634
+ * normal: 不排序 (默认)
635
+ * @default 'normal'
636
+ */
637
+ sort?: 'desc' | 'asc' | 'normal';
638
+ /**
639
+ * 是否显示文章数量
640
+ * @default false
641
+ */
642
+ showCount?: boolean;
630
643
  }
631
644
  }
632
645
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sugarat/theme",
3
- "version": "0.5.15",
3
+ "version": "0.5.16",
4
4
  "description": "简约风的 Vitepress 博客主题,sugarat vitepress blog theme",
5
5
  "author": "sugar",
6
6
  "license": "MIT",
@@ -52,10 +52,10 @@
52
52
  "vitepress-plugin-mermaid": "2.0.13",
53
53
  "vitepress-plugin-tabs": "0.7.3",
54
54
  "@sugarat/theme-shared": "0.0.7",
55
- "vitepress-plugin-announcement": "0.1.7",
56
55
  "vitepress-plugin-image-preview": "0.1.1",
56
+ "vitepress-plugin-rss": "0.4.3",
57
57
  "vitepress-plugin-pagefind": "0.4.19",
58
- "vitepress-plugin-rss": "0.4.3"
58
+ "vitepress-plugin-announcement": "0.1.7"
59
59
  },
60
60
  "devDependencies": {
61
61
  "artalk": "^2.8.5",
@@ -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>
@@ -664,5 +664,18 @@ export namespace Theme {
664
664
  * @default 999
665
665
  */
666
666
  limit?: number
667
+ /**
668
+ * 标签排序方式
669
+ * desc: 降序
670
+ * asc: 升序
671
+ * normal: 不排序 (默认)
672
+ * @default 'normal'
673
+ */
674
+ sort?: 'desc' | 'asc' | 'normal'
675
+ /**
676
+ * 是否显示文章数量
677
+ * @default false
678
+ */
679
+ showCount?: boolean
667
680
  }
668
681
  }