fix: fetch preview content
This commit is contained in:
@@ -1,10 +1,13 @@
|
||||
import { notFound } from "next/navigation";
|
||||
import fs from "node:fs/promises";
|
||||
import path from "node:path";
|
||||
|
||||
import { request } from "@/lib/request";
|
||||
import { previewRequest } from "@/lib/previewRequest";
|
||||
import { GetCurrentBlockPage } from "@/lib/graphql/Query/CurrentBlockPage.graphql";
|
||||
|
||||
import Aside from "@/components/Current/Aside";
|
||||
import Blocks from "@/components/Current/Blocks";
|
||||
import Header from "@/components/Current/Header";
|
||||
import Hero from "@/components/Current/Hero";
|
||||
|
||||
import type { PageArgs, LangParams, UriParams } from "@/types/params";
|
||||
import type { GetCurrentBlockPageData } from "@/types/requests/currentBlockPage";
|
||||
|
||||
@@ -18,42 +21,29 @@ export default async function CurrentContentPage({
|
||||
throw new Error("Bad URI");
|
||||
}
|
||||
|
||||
// const response = await request<GetCurrentBlockPageData>(GetCurrentBlockPage, { locale: params.lang, url: searchParams.uri })
|
||||
|
||||
// console.log(response.data.all_current_blocks_page.items[0].blocks)
|
||||
|
||||
const filePath = path.join(
|
||||
process.cwd(),
|
||||
"mockCms",
|
||||
params.lang,
|
||||
searchParams.uri,
|
||||
"data.json"
|
||||
const response = await previewRequest<GetCurrentBlockPageData>(
|
||||
GetCurrentBlockPage,
|
||||
{ locale: params.lang, url: searchParams.uri }
|
||||
);
|
||||
|
||||
const data = await fs.readFile(filePath, { encoding: "utf-8" });
|
||||
|
||||
if (!data) {
|
||||
throw new Error("No data");
|
||||
if (!response.data?.all_current_blocks_page?.total) {
|
||||
console.log("#### DATA ####");
|
||||
console.log(response.data);
|
||||
console.log("SearchParams URI: ", searchParams.uri);
|
||||
throw new Error("Not found");
|
||||
}
|
||||
|
||||
const json = JSON.parse(data);
|
||||
const page = response.data.all_current_blocks_page.items[0];
|
||||
const images = page.hero?.imagesConnection;
|
||||
|
||||
return (
|
||||
<>
|
||||
{json.hero ? (
|
||||
<div
|
||||
dangerouslySetInnerHTML={{ __html: json.hero }}
|
||||
className="hero-content-overlay hero-content-widget"
|
||||
/>
|
||||
) : null}
|
||||
{json.content ? (
|
||||
<main
|
||||
className="main l-sections-wrapper"
|
||||
role="main"
|
||||
id="maincontent"
|
||||
dangerouslySetInnerHTML={{ __html: json.content }}
|
||||
/>
|
||||
) : null}
|
||||
<Header lang={params.lang} pathname={searchParams.uri} />
|
||||
{images?.totalCount ? <Hero images={images.edges} /> : null}
|
||||
<main className="main l-sections-wrapper" id="maincontent" role="main">
|
||||
<Blocks blocks={page.blocks} />
|
||||
<Aside blocks={page.aside} />
|
||||
</main>
|
||||
</>
|
||||
);
|
||||
} catch (err) {
|
||||
|
||||
Reference in New Issue
Block a user