diff --git a/repos/.vitepress/theme/components/ArticleMetadata.vue b/repos/.vitepress/theme/components/ArticleMetadata.vue
index 5a6b31b66..ce2946ef7 100644
--- a/repos/.vitepress/theme/components/ArticleMetadata.vue
+++ b/repos/.vitepress/theme/components/ArticleMetadata.vue
@@ -20,6 +20,23 @@
+
+
diff --git a/repos/.vitepress/theme/components/dynamic/Tag.vue b/repos/.vitepress/theme/components/dynamic/Tag.vue
index 1aa40d1d1..d7435efb2 100644
--- a/repos/.vitepress/theme/components/dynamic/Tag.vue
+++ b/repos/.vitepress/theme/components/dynamic/Tag.vue
@@ -36,12 +36,6 @@
-
- {{ tag }}
-
@@ -86,7 +97,7 @@
import { computed, ref } from 'vue'
import { useData } from 'vitepress'
import articleData from '../../../../../article-data.json'
-import { formatDate } from '../../utils.ts'
+import { formatDate, getQueryParam } from '../../utils.ts'
import '../../styles/article-meta-data.css'
const { theme } = useData()
@@ -100,6 +111,12 @@ const toggleTag = (tagTitle: string) => {
selectTag.value = tagTitle
}
+// 如果URL路径有tag参数, 默认选中指定Tag, 例如: /tags?tag=Git
+let tag = getQueryParam('tag')
+if (tag && tag.trim() != '') {
+ toggleTag(tag)
+}
+
/**
* 初始化Tag数据(感谢https://github.com/clark-cui/vitepress-blog-zaun)
* {tagTitle1: [article1, article2, ...}
diff --git a/repos/.vitepress/theme/utils.ts b/repos/.vitepress/theme/utils.ts
index 91a0c733d..4612a6df7 100644
--- a/repos/.vitepress/theme/utils.ts
+++ b/repos/.vitepress/theme/utils.ts
@@ -6,4 +6,18 @@
export function formatDate(date) {
const formatDate = new Date(date)
return formatDate.toLocaleString('zh', {year: 'numeric', month: 'numeric', day: 'numeric', hour: 'numeric', minute: 'numeric'})
+}
+
+/**
+ * 获取URL路径中的指定参数
+ * @param paramName 参数名
+ * @returns 参数值
+ */
+export function getQueryParam(paramName) {
+ const reg = new RegExp("(^|&)"+ paramName +"=([^&]*)(&|$)")
+ let value = window.location.search.substr(1).match(reg)
+ if (value != null) {
+ return unescape(value[2])
+ }
+ return null
}
\ No newline at end of file