Skip to content

Commit f117631

Browse files
committed
update
1 parent 73b94b8 commit f117631

File tree

6 files changed

+38
-12
lines changed

6 files changed

+38
-12
lines changed

src/components/react/HitsInfo.tsx

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,22 @@
11
import React from "react";
22

3-
export type Props = {};
3+
export type Props = {
4+
tag: string;
5+
label: string;
6+
today: string;
7+
total: string;
8+
};
49

510
type Data = {
611
today: string;
712
total: string;
813
};
914

10-
const HitsInfo: React.FC<Props> = ({}) => {
15+
const HitsInfo: React.FC<Props> = ({ tag, label, today: todayLabel, total: totalLabel }) => {
1116
const [data, setData] = React.useState<Data | null>(null);
1217
React.useEffect(() => {
1318
const hitsUrl = new URL("https://hits.zkitefly.eu.org");
14-
hitsUrl.searchParams.set("tag", window.location.origin + window.location.pathname);
19+
hitsUrl.searchParams.set("tag", tag);
1520

1621
fetch(hitsUrl)
1722
.then(async (response) => {
@@ -30,18 +35,16 @@ const HitsInfo: React.FC<Props> = ({}) => {
3035
const [total, today] = parts;
3136
setData({ total, today });
3237
})
33-
.catch(() => {
34-
// 与原逻辑一致:忽略错误
35-
});
38+
.catch(() => {});
3639
}, []);
3740

3841
if (!data) return <></>;
3942

4043
return (
4144
<div className="hits">
42-
<strong>访问量</strong> <span title="今日访问">{data.today}</span>
45+
<strong>{label}</strong> <span title={todayLabel}>{data.today}</span>
4346
{" / "}
44-
<span title="总访问">{data.total}</span>
47+
<span title={totalLabel}>{data.total}</span>
4548
</div>
4649
);
4750
};

src/components/starlight/PageTitle.astro

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22
import DefaultPageTitle from "@astrojs/starlight/components/PageTitle.astro";
33
import HitsInfo from "@components/react/HitsInfo";
44
5+
let tag = Astro.url.href;
6+
if (!tag.endsWith("/") && !tag.endsWith(".html")) {
7+
tag += ".html";
8+
}
9+
510
const { contributors } = Astro.locals.starlightRoute.entry.data;
611
const showContributors = Array.isArray(contributors) && contributors.length > 0;
712
---
@@ -16,5 +21,11 @@ const showContributors = Array.isArray(contributors) && contributors.length > 0;
1621
</div>
1722
)
1823
}
19-
<HitsInfo client:load />
24+
<HitsInfo
25+
tag={tag}
26+
label={Astro.locals.t("page.hits.label")}
27+
today={Astro.locals.t("page.hits.today")}
28+
total={Astro.locals.t("page.hits.total")}
29+
client:only="react"
30+
/>
2031
</div>

src/content.config.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ export const collections = {
2727
schema: i18nSchema({
2828
extend: z.object({
2929
"page.contributors": z.string(),
30+
"page.hits.label": z.string(),
31+
"page.hits.today": z.string(),
32+
"page.hits.total": z.string(),
3033
}),
3134
}),
3235
}),

src/content/i18n/en.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,8 @@
2727
"fileTree.directory": "Directory",
2828
"builtWithStarlight.label": "Built with Starlight",
2929
"heading.anchorLabel": "Section titled \"{{title}}\"",
30-
"page.contributors": "Contributors"
30+
"page.contributors": "Contributors",
31+
"page.hits.label": "Visits",
32+
"page.hits.today": "Today Visits",
33+
"page.hits.total": "Total Visits"
3134
}

src/content/i18n/zh-Hans.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,8 @@
2727
"fileTree.directory": "文件夹",
2828
"builtWithStarlight.label": "基于 Starlight 构建",
2929
"heading.anchorLabel": "标题为“{{title}}”的章节",
30-
"page.contributors": "贡献者"
30+
"page.contributors": "贡献者",
31+
"page.hits.label": "访问量",
32+
"page.hits.today": "今日访问",
33+
"page.hits.total": "总访问"
3134
}

src/content/i18n/zh-Hant.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,8 @@
2727
"fileTree.directory": "目錄",
2828
"builtWithStarlight.label": "基於 Starlight 構建",
2929
"heading.anchorLabel": "標題爲「{{title}}」的章節",
30-
"page.contributors": "貢獻者"
30+
"page.contributors": "貢獻者",
31+
"page.hits.label": "訪問量",
32+
"page.hits.today": "今日訪問",
33+
"page.hits.total": "總訪問"
3134
}

0 commit comments

Comments
 (0)