updated widgets
This commit is contained in:
15
src/app/(client)/[slug]/error.tsx
Normal file
15
src/app/(client)/[slug]/error.tsx
Normal file
@@ -0,0 +1,15 @@
|
||||
'use client';
|
||||
|
||||
export default function Error() {
|
||||
return (
|
||||
<div className="container mx-auto py-16 max-w-3xl text-center">
|
||||
<h1 className="text-2xl font-semibold mb-4">
|
||||
500 — Сервер временно недоступен
|
||||
</h1>
|
||||
<p className="text-gray-600">
|
||||
Страница не может быть загружена прямо сейчас.
|
||||
Пожалуйста, попробуйте позже.
|
||||
</p>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
34
src/app/(client)/[slug]/page.tsx
Normal file
34
src/app/(client)/[slug]/page.tsx
Normal file
@@ -0,0 +1,34 @@
|
||||
// app/[slug]/page.tsx
|
||||
import Post from '@/components/Post/Post';
|
||||
import { renderPostContent } from '@/components/WPRenderer/WPRenderer';
|
||||
|
||||
// ISR: regenerate every 60 seconds
|
||||
export const revalidate = 60;
|
||||
|
||||
export interface PageProps {
|
||||
params: {
|
||||
slug: string;
|
||||
};
|
||||
}
|
||||
|
||||
export default async function PostPage({ params }: PageProps) {
|
||||
const { slug } = await params;
|
||||
const baseUrl =
|
||||
process.env.NEXT_PUBLIC_API_URL || 'http://localhost:3000';
|
||||
|
||||
const res = await fetch(`${baseUrl}/api/posts/${slug}`, {
|
||||
next: { revalidate: 60 },
|
||||
});
|
||||
|
||||
if (!res.ok) {
|
||||
console.log(`${baseUrl}/api/posts/${slug}`)
|
||||
// 🚨 THROW — this is critical
|
||||
throw new Error('Failed to fetch post');
|
||||
}
|
||||
|
||||
const post = await res.json();
|
||||
|
||||
return (
|
||||
<Post post={post} />
|
||||
);
|
||||
}
|
||||
71
src/app/(client)/[slug]/page/[page]/page.tsx
Normal file
71
src/app/(client)/[slug]/page/[page]/page.tsx
Normal file
@@ -0,0 +1,71 @@
|
||||
import PostGrid from "@/components/WP/PostGrid/PostGrid.server";
|
||||
import { renderPostContent } from "@/components/WPRenderer/WPRenderer";
|
||||
import parse, { DOMNode } from 'html-react-parser'
|
||||
|
||||
interface PageProps {
|
||||
params: { slug: string; page: string };
|
||||
}
|
||||
|
||||
export function extractPostGridId(content: string): number | null {
|
||||
let gridId: number | null = null;
|
||||
|
||||
parse(content, {
|
||||
replace: (domNode: DOMNode) => {
|
||||
// Only check text nodes
|
||||
if ("data" in domNode && typeof domNode.data === "string") {
|
||||
const match = domNode.data.match(/\[the-post-grid\s+id="(\d+)"/);
|
||||
if (match) {
|
||||
gridId = Number(match[1]);
|
||||
return; // stop parsing
|
||||
}
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
return gridId;
|
||||
}
|
||||
|
||||
|
||||
export default async function PostPage({ params }: PageProps) {
|
||||
const { slug, page } = await params;
|
||||
const pageNum = Number(page) || 1;
|
||||
|
||||
// 1. Fetch the WP page content (same as page 1)
|
||||
const res = await fetch(`${process.env.NEXT_PUBLIC_API_URL}/api/pages/${slug}`, {
|
||||
next: { revalidate: 60 },
|
||||
});
|
||||
const pageData = await res.json();
|
||||
|
||||
if (!pageData) return <p>Page not found</p>;
|
||||
|
||||
// 2. Extract grid ID from shortcode
|
||||
const gridId = extractPostGridId(pageData.post_content);
|
||||
|
||||
return (
|
||||
<div className="container mx-auto py-8 max-w-5xl">
|
||||
<article className="prose lg:prose-xl max-w-none">
|
||||
<h1>{pageData.post_title}</h1>
|
||||
|
||||
{pageData.post_type === 'post' && (
|
||||
<div className="text-gray-600 mb-6">
|
||||
<time>
|
||||
{pageData.post_date}
|
||||
</time>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{renderPostContent(pageData.post_content, { page: pageNum })}
|
||||
</article>
|
||||
</div>
|
||||
)
|
||||
|
||||
return (
|
||||
<article>
|
||||
<h1>{pageData.title}</h1>
|
||||
|
||||
{/* {gridId && <PostGrid id={gridId} page={pageNum} />} */}
|
||||
{renderPostContent(pageData.post_content, { page: pageNum })}
|
||||
|
||||
</article>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user