From a4b4d7138572252c89affdb2f2ca6a15ed523fbd Mon Sep 17 00:00:00 2001 From: Charles7c Date: Tue, 9 Aug 2022 21:25:55 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=EF=BC=9A=E6=96=87=E7=AB=A0?= =?UTF-8?q?=E5=85=83=E6=95=B0=E6=8D=AE=E4=BF=A1=E6=81=AF=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E6=89=80=E5=B1=9E=E5=88=86=E7=B1=BB=E5=92=8C=E6=A0=87=E7=AD=BE?= =?UTF-8?q?=E5=88=97=E8=A1=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../theme/components/ArticleMetadata.vue | 17 ++++++++++ .../theme/components/dynamic/Tag.vue | 33 ++++++++++++++----- repos/.vitepress/theme/utils.ts | 14 ++++++++ 3 files changed, 56 insertions(+), 8 deletions(-) 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 @@ +
+ + 所属分类 + + {{ frontmatter.categories.join(", ") }} +
+
+ + 标签列表 + + + + {{ tag }} + , + + +
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 @@

{{ article.title }}

- - {{ tag }} -

@@ -64,6 +58,23 @@
+
+ + 所属分类 + + {{ article.categories.join(",") }} +
+
+ + 标签列表 + + + + {{ 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