From 8f004a995926e8b93906f93046f6527c38bf9ec3 Mon Sep 17 00:00:00 2001 From: Ad-closeNN <1709301095@qq.com> Date: Mon, 20 Apr 2026 01:16:10 +0800 Subject: [PATCH] =?UTF-8?q?feat(component):=20=E5=8A=A0=E5=85=A5=E6=80=BB?= =?UTF-8?q?=E5=AD=97=E6=95=B0=E7=BB=9F=E8=AE=A1=E6=A8=A1=E5=9D=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/widget/Profile.astro | 94 ++++++++++++++++---------- src/components/widget/TotalWords.astro | 15 ++++ src/content/spec/about.md | 4 +- src/pages/posts/[...slug].astro | 3 +- src/utils/content-utils.ts | 20 +++++- 5 files changed, 96 insertions(+), 40 deletions(-) create mode 100644 src/components/widget/TotalWords.astro diff --git a/src/components/widget/Profile.astro b/src/components/widget/Profile.astro index dabe5ba..26e7dc3 100644 --- a/src/components/widget/Profile.astro +++ b/src/components/widget/Profile.astro @@ -3,6 +3,7 @@ import { Icon } from "astro-icon/components"; import { profileConfig } from "../../config"; import { url } from "../../utils/url-utils"; import ImageWrapper from "../misc/ImageWrapper.astro"; +import TotalWords from "./TotalWords.astro"; const config = profileConfig; --- @@ -45,6 +46,8 @@ const config = profileConfig; } + +
@@ -74,18 +77,37 @@ const config = profileConfig; fetch("https://v1.hitokoto.cn") .then(response => response.json()) .then(data => { - // API 返回的字段是 data.text - document.getElementById("hitokoto").innerText = data.hitokoto; + const hitokotoElement = document.getElementById("hitokoto"); + if (hitokotoElement) { + hitokotoElement.innerText = data.hitokoto; + } }) .catch(error => { console.error("获取一言失败:", error); - //document.getElementById("hitokoto").innerText = "获取失败,请稍后再试。"; - //失败后用内置的,成功了用别人的。 - document.getElementById("hitokoto").innerText = "再热情的心也经不起冷漠,再爱你的人也经不起冷落。"; + const hitokotoElement = document.getElementById("hitokoto"); + if (hitokotoElement) { + hitokotoElement.innerText = "再热情的心也经不起冷漠,再爱你的人也经不起冷落。"; + } });