diff --git a/public/js/umami-share.js b/public/js/umami-share.js index 5aefc823c..08900a14c 100644 --- a/public/js/umami-share.js +++ b/public/js/umami-share.js @@ -44,4 +44,48 @@ localStorage.removeItem(cacheKey); delete global.__umamiSharePromise; }; + + /** + * 获取 Umami 统计数据 + * 自动处理 token 获取和过期重试 + * @param {string} baseUrl + * @param {string} shareId + * @param {object} queryParams + * @returns {Promise} + */ + global.fetchUmamiStats = async function (baseUrl, shareId, queryParams) { + async function doFetch(isRetry = false) { + const { websiteId, token } = await global.getUmamiShareData(baseUrl, shareId); + const currentTimestamp = Date.now(); + const params = new URLSearchParams({ + startAt: 0, + endAt: currentTimestamp, + unit: 'hour', + timezone: queryParams.timezone || 'Asia/Shanghai', + compare: false, + ...queryParams + }); + + const statsUrl = `${baseUrl}/api/websites/${websiteId}/stats?${params.toString()}`; + + const res = await fetch(statsUrl, { + headers: { + 'x-umami-share-token': token + } + }); + + if (!res.ok) { + if (res.status === 401 && !isRetry) { + global.clearUmamiShareCache(); + return doFetch(true); + } + throw new Error('获取统计数据失败'); + } + + return await res.json(); + } + + return doFetch(); + }; + })(window); \ No newline at end of file diff --git a/src/components/ArchivePanel.astro b/src/components/ArchivePanel.astro index 0fb37d498..2a95f480a 100644 --- a/src/components/ArchivePanel.astro +++ b/src/components/ArchivePanel.astro @@ -5,22 +5,10 @@ import { getPostUrlBySlug } from "../utils/url-utils"; interface Props { keyword?: string; - tags?: string[]; } -const { tags } = Astro.props; let posts = await getSortedPosts(); -if (Array.isArray(tags) && tags.length > 0) { - posts = posts.filter( - (post) => - Array.isArray(post.data.tags) && - post.data.tags.some((tag) => tags.includes(tag)), - ); -} - - - const groups: { year: number; posts: typeof posts }[] = (() => { const groupedPosts = posts.reduce( (grouped: { [year: number]: typeof posts }, post) => { @@ -50,10 +38,6 @@ function formatDate(date: Date) { const day = date.getDate().toString().padStart(2, "0"); return `${month}-${day}`; } - -function formatTag(tag: string[]) { - return tag.map((t) => `#${t}`).join(" "); -} ---
@@ -99,7 +83,7 @@ function formatTag(tag: string[]) { + >
))} diff --git a/src/components/GlobalStyles.astro b/src/components/GlobalStyles.astro deleted file mode 100644 index 853d812bb..000000000 --- a/src/components/GlobalStyles.astro +++ /dev/null @@ -1,3 +0,0 @@ ---- - ---- diff --git a/src/components/PostCard.astro b/src/components/PostCard.astro index b281b61ae..d61897234 100644 --- a/src/components/PostCard.astro +++ b/src/components/PostCard.astro @@ -15,7 +15,6 @@ interface Props { url: string; published: Date; updated?: Date; - tags: string[]; image: string; description: string; draft: boolean; @@ -27,7 +26,6 @@ const { url, published, updated, - tags, image, description, style, @@ -57,7 +55,7 @@ const { remarkPluginFrontmatter } = await entry.render(); - +
diff --git a/src/components/PostMeta.astro b/src/components/PostMeta.astro index 82f9b41d0..a807cadae 100644 --- a/src/components/PostMeta.astro +++ b/src/components/PostMeta.astro @@ -9,16 +9,12 @@ interface Props { class: string; published: Date; updated?: Date; - tags: string[]; - hideTagsForMobile?: boolean; hideUpdateDate?: boolean; slug?: string; } const { published, updated, - tags, - hideTagsForMobile = false, hideUpdateDate = false, slug, } = Astro.props; @@ -46,25 +42,6 @@ const className = Astro.props.class;
)} - -
-
- -
-
- {(tags && tags.length > 0) && tags.map((tag, i) => ( -
/
- - {tag} - - ))} - {!(tags && tags.length > 0) &&
无标签
} -
-
- {slug && ( <> @@ -88,55 +65,27 @@ const className = Astro.props.class; - - diff --git a/src/components/widget/Profile.astro b/src/components/widget/Profile.astro index f56374e4d..9abedf65d 100644 --- a/src/components/widget/Profile.astro +++ b/src/components/widget/Profile.astro @@ -70,46 +70,19 @@ const config = profileConfig; diff --git a/src/pages/archive/tag/[tag].astro b/src/pages/archive/tag/[tag].astro deleted file mode 100644 index 81edbb93f..000000000 --- a/src/pages/archive/tag/[tag].astro +++ /dev/null @@ -1,31 +0,0 @@ ---- -import ArchivePanel from "@components/ArchivePanel.astro"; - -import MainGridLayout from "@layouts/MainGridLayout.astro"; -import { getSortedPosts } from "@utils/content-utils"; - -export async function getStaticPaths() { - const posts = await getSortedPosts(); - - // タグを集めるための Set の型を指定 - const allTags = posts.reduce>((acc, post) => { - // biome-ignore lint/complexity/noForEach: - post.data.tags.forEach((tag) => acc.add(tag)); - return acc; - }, new Set()); - - const allTagsArray = Array.from(allTags); - - return allTagsArray.map((tag) => ({ - params: { - tag: tag, - }, - })); -} - -const tag = Astro.params.tag as string; ---- - - - - \ No newline at end of file diff --git a/src/pages/posts/[...slug].astro b/src/pages/posts/[...slug].astro index 887712a59..d0ddf0935 100644 --- a/src/pages/posts/[...slug].astro +++ b/src/pages/posts/[...slug].astro @@ -31,10 +31,9 @@ const jsonLd = { "@type": "BlogPosting", headline: entry.data.title, description: entry.data.description || entry.data.title, - keywords: entry.data.tags, - author: { - "@type": "Person", - name: profileConfig.name, + author: { + "@type": "Person", + name: profileConfig.name, url: Astro.site, }, datePublished: formatDateToYYYYMMDD(entry.data.published), diff --git a/src/utils/content-utils.ts b/src/utils/content-utils.ts index 52c3e7711..9ae2c5b86 100644 --- a/src/utils/content-utils.ts +++ b/src/utils/content-utils.ts @@ -28,28 +28,3 @@ export async function getSortedPosts() { return sorted; } -export type Tag = { - name: string; - count: number; -}; - -export async function getTagList(): Promise { - const allBlogPosts = await getCollection<"posts">("posts", ({ data }) => { - return import.meta.env.PROD ? data.draft !== true : true; - }); - - const countMap: { [key: string]: number } = {}; - allBlogPosts.map((post: { data: { tags: string[] } }) => { - post.data.tags.map((tag: string) => { - if (!countMap[tag]) countMap[tag] = 0; - countMap[tag]++; - }); - }); - - // sort tags - const keys: string[] = Object.keys(countMap).sort((a, b) => { - return a.toLowerCase().localeCompare(b.toLowerCase()); - }); - - return keys.map((key) => ({ name: key, count: countMap[key] })); -}