From 0d793fc3e93d5fb02bb19d0c1f2e986781d8cdc7 Mon Sep 17 00:00:00 2001 From: Charles7c Date: Thu, 4 Aug 2022 18:23:03 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=EF=BC=9A=E3=80=8A=E6=88=91?= =?UTF-8?q?=E7=9A=84=E5=BD=92=E6=A1=A3=E3=80=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- collect-article-data.mjs | 2 +- repos/.vitepress/config/nav.ts | 5 + .../theme/{components => }/MyLayout.vue | 4 +- repos/.vitepress/theme/components/Archive.vue | 118 ++++++++++++++++++ repos/.vitepress/theme/components/Tag.vue | 21 +--- repos/.vitepress/theme/index.ts | 4 +- repos/.vitepress/theme/utils.ts | 9 ++ repos/archives.md | 7 ++ 8 files changed, 151 insertions(+), 19 deletions(-) rename repos/.vitepress/theme/{components => }/MyLayout.vue (84%) create mode 100644 repos/.vitepress/theme/components/Archive.vue create mode 100644 repos/.vitepress/theme/utils.ts create mode 100644 repos/archives.md diff --git a/collect-article-data.mjs b/collect-article-data.mjs index 35af11b76..9b31e40c4 100644 --- a/collect-article-data.mjs +++ b/collect-article-data.mjs @@ -7,7 +7,7 @@ const articleData = await Promise.all( glob.sync('./repos/**/*.md', { onlyFiles: true, objectMode: true, - ignore: ['./repos/**/index.md', './repos/**/tags.md', './repos/**/me.md'], // without ! + ignore: ['./repos/**/index.md', './repos/**/tags.md', './repos/**/archives.md', './repos/**/me.md'], // without ! }).map(async (article) => { const file = matter.read(`${article.path}`) const { data, path } = file diff --git a/repos/.vitepress/config/nav.ts b/repos/.vitepress/config/nav.ts index cb35fd945..bf0648890 100644 --- a/repos/.vitepress/config/nav.ts +++ b/repos/.vitepress/config/nav.ts @@ -22,6 +22,11 @@ export const nav: DefaultTheme.Config['nav'] = [ link: '/tags', activeMatch: '/tags' }, + { + text: '我的归档', + link: '/archives', + activeMatch: '/archives' + }, { text: '关于', items: [ diff --git a/repos/.vitepress/theme/components/MyLayout.vue b/repos/.vitepress/theme/MyLayout.vue similarity index 84% rename from repos/.vitepress/theme/components/MyLayout.vue rename to repos/.vitepress/theme/MyLayout.vue index c4ef586c7..875e75c6b 100644 --- a/repos/.vitepress/theme/components/MyLayout.vue +++ b/repos/.vitepress/theme/MyLayout.vue @@ -12,8 +12,8 @@ + + \ No newline at end of file diff --git a/repos/.vitepress/theme/components/Tag.vue b/repos/.vitepress/theme/components/Tag.vue index c3cb1354e..633dc2bab 100644 --- a/repos/.vitepress/theme/components/Tag.vue +++ b/repos/.vitepress/theme/components/Tag.vue @@ -4,7 +4,7 @@ - 查尔斯的标签 + 我的标签
@@ -89,6 +89,7 @@ import { computed, ref } from 'vue' import { useData } from 'vitepress' import articleData from '../../../../article-data.json' +import { formatDate } from '../utils.ts' import '../styles/article-meta-data.css' const { theme } = useData() @@ -104,10 +105,10 @@ const toggleTag = (tagTitle: string) => { /** * 初始化Tag数据(感谢https://github.com/clark-cui/vitepress-blog-zaun) - * [{tagTitle: [article1, article2, ...], ...}] + * {tagTitle1: [article1, article2, ...} */ function initTags(articleData) { - const tags: any = {}; + const tags: any = {} for (let i = 0; i < articleData.length; i++) { const article = articleData[i] const articleTags = article.tags @@ -124,16 +125,6 @@ function initTags(articleData) { } return tags } - -/** - * 格式化时间 - */ -function formatDate(date) { - const formatDate = computed(() => new Date(date)) - const isoDatetime = computed(() => formatDate.value.toISOString()) - const datetime = formatDate.value.toLocaleString('zh', {year: 'numeric', month: 'numeric', day: 'numeric', hour: 'numeric', minute: 'numeric'}) - return datetime -}