feat: BlogPage fetches posts from dashboard API with fallback

- Fetch published posts from /api/public/blog (10-min sessionStorage cache)
- Fall back to PORTFOLIO_DATA.blogArticles if API is unavailable or empty
- Preserves all existing display logic unchanged

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
khondokartowsif171
2026-05-26 03:05:01 +06:00
parent 151e91fb99
commit 3af4ebfa29
+25 -2
View File
@@ -670,7 +670,30 @@ const BLOG_COLORS = {
const BlogPage = () => {
const D = PORTFOLIO_DATA;
const [active, setActive] = React.useState(null);
const article = active ? D.blogArticles.find(a => a.slug === active) : null;
const [articles, setArticles] = React.useState(D.blogArticles || []);
React.useEffect(() => {
const CACHE_KEY = 'aura_blog_v1';
const CACHE_TTL = 10 * 60 * 1000;
try {
const cached = sessionStorage.getItem(CACHE_KEY);
if (cached) {
const { data, ts } = JSON.parse(cached);
if (Date.now() - ts < CACHE_TTL && data.length) { setArticles(data); return; }
}
} catch {}
fetch(`${DASHBOARD_API}/api/public/blog`, { signal: AbortSignal.timeout(3000) })
.then(r => r.ok ? r.json() : null)
.then(data => {
if (Array.isArray(data) && data.length) {
setArticles(data);
sessionStorage.setItem(CACHE_KEY, JSON.stringify({ data, ts: Date.now() }));
}
})
.catch(() => {});
}, []);
const article = active ? articles.find(a => a.slug === active) : null;
if (article) {
const c = BLOG_COLORS[article.color] || BLOG_COLORS.violet;
@@ -755,7 +778,7 @@ const BlogPage = () => {
<section style={{ padding: "80px 0 120px" }}>
<div className="container">
<div style={{ display: "grid", gap: 20 }}>
{D.blogArticles.map((post, i) => {
{articles.map((post, i) => {
const c = BLOG_COLORS[post.color] || BLOG_COLORS.violet;
return (
<div