mirror of
https://github.com/KivotosRailway/website.git
synced 2026-11-03 11:06:32 +09:00
修改页面标题路由
This commit is contained in:
@@ -1,11 +1,25 @@
|
||||
"use client";
|
||||
|
||||
import Link from "next/link";
|
||||
import { useState } from "react";
|
||||
import { useEffect, useState } from "react";
|
||||
import type { NewsItem } from "@/data/news";
|
||||
import { getInitialLocale, getLocaleMessages, type Locale } from "@/lib/i18n";
|
||||
|
||||
export function NewsList({ news }: { news: NewsItem[] }) {
|
||||
const [activeCategory, setActiveCategory] = useState<string | null>(null);
|
||||
const [locale, setLocale] = useState<Locale>("zh-CN");
|
||||
const messages = getLocaleMessages(locale);
|
||||
|
||||
useEffect(() => {
|
||||
const syncLocale = () => setLocale(getInitialLocale());
|
||||
syncLocale();
|
||||
window.addEventListener("kr-locale-change", syncLocale);
|
||||
window.addEventListener("storage", syncLocale);
|
||||
return () => {
|
||||
window.removeEventListener("kr-locale-change", syncLocale);
|
||||
window.removeEventListener("storage", syncLocale);
|
||||
};
|
||||
}, []);
|
||||
const categories = Array.from(new Set(news.map((item) => item.category).filter(Boolean)));
|
||||
const visibleNews = activeCategory
|
||||
? news.filter((item) => item.category === activeCategory)
|
||||
@@ -20,7 +34,7 @@ export function NewsList({ news }: { news: NewsItem[] }) {
|
||||
className={`news-filter-button${activeCategory === null ? " active" : ""}`}
|
||||
onClick={() => setActiveCategory(null)}
|
||||
>
|
||||
全部
|
||||
{messages.common.all}
|
||||
</button>
|
||||
{categories.map((category) => (
|
||||
<button
|
||||
@@ -34,7 +48,7 @@ export function NewsList({ news }: { news: NewsItem[] }) {
|
||||
))}
|
||||
</div>
|
||||
<div className="news-toolbar-right">
|
||||
<button type="button" className="news-view-toggle" aria-label="列表视图">☰</button>
|
||||
<button type="button" className="news-view-toggle" aria-label={messages.common.listView}>☰</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
@@ -1,9 +1,23 @@
|
||||
"use client";
|
||||
|
||||
import { useState } from "react";
|
||||
import { useEffect, useState } from "react";
|
||||
import { getInitialLocale, getLocaleMessages, type Locale } from "@/lib/i18n";
|
||||
|
||||
export function NewsShare({ title }: { title: string }) {
|
||||
const [copied, setCopied] = useState(false);
|
||||
const [locale, setLocale] = useState<Locale>("zh-CN");
|
||||
const messages = getLocaleMessages(locale);
|
||||
|
||||
useEffect(() => {
|
||||
const syncLocale = () => setLocale(getInitialLocale());
|
||||
syncLocale();
|
||||
window.addEventListener("kr-locale-change", syncLocale);
|
||||
window.addEventListener("storage", syncLocale);
|
||||
return () => {
|
||||
window.removeEventListener("kr-locale-change", syncLocale);
|
||||
window.removeEventListener("storage", syncLocale);
|
||||
};
|
||||
}, []);
|
||||
|
||||
const getPageUrl = () => window.location.href;
|
||||
|
||||
@@ -27,13 +41,13 @@ export function NewsShare({ title }: { title: string }) {
|
||||
|
||||
return (
|
||||
<section className="news-share" aria-labelledby="news-share-title">
|
||||
<h2 id="news-share-title">分享</h2>
|
||||
<h2 id="news-share-title">{messages.common.share}</h2>
|
||||
<div className="news-share-actions">
|
||||
<button type="button" className="news-share-button" onClick={copyLink} aria-label="复制链接">
|
||||
{copied ? "已复制" : "复制链接"}
|
||||
<button type="button" className="news-share-button" onClick={copyLink} aria-label={messages.common.copyLink}>
|
||||
{copied ? messages.common.copied : messages.common.copyLink}
|
||||
</button>
|
||||
<button type="button" className="news-share-button news-share-x" onClick={shareOnX} aria-label="分享到 X">X</button>
|
||||
<button type="button" className="news-share-button news-share-qq" onClick={shareOnQq} aria-label="分享到 QQ">QQ</button>
|
||||
<button type="button" className="news-share-button news-share-x" onClick={shareOnX} aria-label={messages.common.shareX}>X</button>
|
||||
<button type="button" className="news-share-button news-share-qq" onClick={shareOnQq} aria-label={messages.common.shareQq}>QQ</button>
|
||||
</div>
|
||||
</section>
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user