feat: improve archive frontend and open-source docs
This commit is contained in:
@@ -2,7 +2,6 @@ import React from "react";
|
||||
import AchievementsPageClient from "@/components/achievements/AchievementsPageClient";
|
||||
import { Achievement } from "@/components/achievements/CertificateCard";
|
||||
import { getAchievementsList, getAchievementMetasList } from "@/api/achievements";
|
||||
import { getPublicConfig } from "@/api/config";
|
||||
|
||||
export interface AchievementMeta {
|
||||
id: number;
|
||||
@@ -38,34 +37,14 @@ async function getAchievementMetas(): Promise<AchievementMeta[]> {
|
||||
return [];
|
||||
}
|
||||
|
||||
async function getPublicConfigs(): Promise<Record<string, string>> {
|
||||
try {
|
||||
const res = await getPublicConfig();
|
||||
const data = res.data;
|
||||
if (data && data.code === 200 && Array.isArray(data.data)) {
|
||||
const configMap: Record<string, string> = {};
|
||||
data.data.forEach((item: any) => {
|
||||
configMap[item.configKey] = item.configValue;
|
||||
});
|
||||
return configMap;
|
||||
}
|
||||
} catch (err) {
|
||||
console.warn("Achievements Page SSR configs: API offline, using empty configuration.", err);
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
|
||||
export default async function AchievementsPage() {
|
||||
const achievements = await getAchievements();
|
||||
const metas = await getAchievementMetas();
|
||||
const configs = await getPublicConfigs();
|
||||
|
||||
return (
|
||||
<AchievementsPageClient
|
||||
initialItems={achievements}
|
||||
initialMetas={metas}
|
||||
configs={configs}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
+10
-12
@@ -9,6 +9,7 @@ import StyleConsole from "@/components/ui/StyleConsole";
|
||||
import BackToTop from "@/components/ui/BackToTop";
|
||||
import TapeStation from "@/components/ui/TapeStation";
|
||||
import ThemeApplier from "@/components/ui/ThemeApplier";
|
||||
import { fetchPublicConfigForServer } from "@/api/config";
|
||||
|
||||
const inter = Inter({
|
||||
variable: "--font-inter",
|
||||
@@ -65,18 +66,15 @@ export async function generateMetadata(): Promise<Metadata> {
|
||||
let title = "春风不解别离 | 个人生活档案馆";
|
||||
let faviconUrl = "/icon.png";
|
||||
try {
|
||||
const res = await fetch("http://localhost:8080/api/config/public", { next: { revalidate: 10 } });
|
||||
if (res.ok) {
|
||||
const data = await res.json();
|
||||
if (data.code === 200 && Array.isArray(data.data)) {
|
||||
const titleItem = data.data.find((c: any) => c.configKey === "site.title.default");
|
||||
if (titleItem?.configValue) {
|
||||
title = titleItem.configValue;
|
||||
}
|
||||
const favItem = data.data.find((c: any) => c.configKey === "site.favicon.url");
|
||||
if (favItem?.configValue) {
|
||||
faviconUrl = favItem.configValue;
|
||||
}
|
||||
const data = await fetchPublicConfigForServer({ next: { revalidate: 10 } });
|
||||
if (data.code === 200 && Array.isArray(data.data)) {
|
||||
const titleItem = data.data.find((c: any) => c.configKey === "site.title.default");
|
||||
if (titleItem?.configValue) {
|
||||
title = titleItem.configValue;
|
||||
}
|
||||
const favItem = data.data.find((c: any) => c.configKey === "site.favicon.url");
|
||||
if (favItem?.configValue) {
|
||||
faviconUrl = favItem.configValue;
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
|
||||
@@ -2,11 +2,6 @@ import { notFound } from "next/navigation";
|
||||
import LovePageClient from "@/components/love/LovePageClient";
|
||||
import { getPublicConfig } from "@/api/config";
|
||||
|
||||
interface PublicConfig {
|
||||
configKey: string;
|
||||
configValue: string;
|
||||
}
|
||||
|
||||
async function getPublicConfigs(): Promise<Record<string, string>> {
|
||||
try {
|
||||
const response = await getPublicConfig();
|
||||
|
||||
@@ -7,7 +7,6 @@ import gsap from "gsap";
|
||||
import {
|
||||
Fish,
|
||||
Heart,
|
||||
Clock,
|
||||
Lightbulb,
|
||||
Sparkle,
|
||||
Bug,
|
||||
@@ -164,7 +163,7 @@ const FeedbackCard = ({ fb, onLike, dbTypes }: { fb: PondFeedback; onLike: (id:
|
||||
};
|
||||
}, []);
|
||||
|
||||
const handleLocalLike = (e: React.MouseEvent) => {
|
||||
const handleLocalLike = () => {
|
||||
if (liked) return;
|
||||
setLiked(true);
|
||||
onLike(fb.id);
|
||||
@@ -521,7 +520,6 @@ export default function PondPage() {
|
||||
|
||||
useEffect(() => {
|
||||
fetchFeedbacks(true);
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [activePool]);
|
||||
|
||||
// 水面心情融合流体背景 GSAP 缓动逻辑
|
||||
|
||||
@@ -30,10 +30,21 @@ export default function PostPage() {
|
||||
const res = response.data;
|
||||
if (res && res.code === 200) {
|
||||
const item = res.data;
|
||||
let formattedDate = new Date().toISOString().split("T")[0];
|
||||
if (item.createTime) {
|
||||
if (item.createTime.includes("T")) {
|
||||
formattedDate = item.createTime.split("T")[0];
|
||||
} else if (item.createTime.includes(" ")) {
|
||||
formattedDate = item.createTime.split(" ")[0];
|
||||
} else {
|
||||
formattedDate = item.createTime;
|
||||
}
|
||||
}
|
||||
|
||||
const formatted: Post = {
|
||||
slug: item.slug || `post-${item.id}`,
|
||||
title: item.title,
|
||||
date: item.createTime ? item.createTime.split("T")[0] : new Date().toISOString().split("T")[0],
|
||||
date: formattedDate,
|
||||
category: item.category || "Thoughts",
|
||||
mood: item.mood || "quiet",
|
||||
visibility: (item.visibility as any) || "public",
|
||||
@@ -46,6 +57,7 @@ export default function PostPage() {
|
||||
throw new Error("Post not found in API");
|
||||
}
|
||||
} catch (err) {
|
||||
console.error("Detail page fetch error detail:", err);
|
||||
console.warn("Detail page: API unavailable, using local writingData static fallback.", err);
|
||||
const local = writingData.find((p) => p.slug === slug);
|
||||
setPost(local || null);
|
||||
@@ -56,6 +68,15 @@ export default function PostPage() {
|
||||
fetchPost();
|
||||
}, [slug]);
|
||||
|
||||
// 种子为 42 的伪随机发生器 (Linear Congruential Generator)
|
||||
const seededRandom = (seed: number) => {
|
||||
let s = seed;
|
||||
return () => {
|
||||
s = (s * 9301 + 49297) % 233280;
|
||||
return s / 233280;
|
||||
};
|
||||
};
|
||||
|
||||
// 解析并生成大纲 (TOC)
|
||||
useEffect(() => {
|
||||
if (!post || (post.visibility === "private" && !unlocked)) return;
|
||||
@@ -65,7 +86,7 @@ export default function PostPage() {
|
||||
const items: { id: string; text: string; level: number }[] = [];
|
||||
headings.forEach((heading) => {
|
||||
const id = heading.id;
|
||||
if (id && id.startsWith("heading-")) {
|
||||
if (id) {
|
||||
const text = heading.textContent || "";
|
||||
const level = parseInt(heading.tagName.substring(1), 10);
|
||||
items.push({ id, text, level });
|
||||
@@ -106,11 +127,17 @@ export default function PostPage() {
|
||||
return () => window.removeEventListener("scroll", handleScroll);
|
||||
}, [toc]);
|
||||
|
||||
// 挑选当前文章之外的 3 篇推荐文章
|
||||
// 使用 seed = 42 进行伪随机算法推荐 3 篇文章
|
||||
useEffect(() => {
|
||||
if (!post) return;
|
||||
const filtered = writingData.filter((p) => p.slug !== slug);
|
||||
setRecommendations(filtered.slice(0, 3));
|
||||
const rng = seededRandom(42);
|
||||
const shuffled = [...filtered];
|
||||
for (let i = shuffled.length - 1; i > 0; i--) {
|
||||
const j = Math.floor(rng() * (i + 1));
|
||||
[shuffled[i], shuffled[j]] = [shuffled[j], shuffled[i]];
|
||||
}
|
||||
setRecommendations(shuffled.slice(0, 3));
|
||||
}, [post, slug]);
|
||||
|
||||
if (loading) {
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
import { useState, useEffect, useRef } from "react";
|
||||
import { Search, Lock, ArrowRight, ArrowLeft, Calendar, Tag, Smile } from "lucide-react";
|
||||
import Link from "next/link";
|
||||
import { writingData } from "@/data/writing";
|
||||
import { useArticles } from "@/hooks/useArticles";
|
||||
import Image from "next/image";
|
||||
import gsap from "gsap";
|
||||
@@ -346,4 +345,3 @@ export default function WritingPage() {
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user