feat: init live preview sdk
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import { notFound } from "next/navigation"
|
||||
|
||||
import { request } from "@/lib/request"
|
||||
import { GetCurrentBlockPage } from "@/lib/graphql/Query/CurrentBlockPage.graphql"
|
||||
import { request } from "@/lib/request";
|
||||
import { GetCurrentBlockPage } from "@/lib/graphql/Query/CurrentBlockPage.graphql";
|
||||
|
||||
import Aside from "@/components/Current/Aside"
|
||||
import Blocks from "@/components/Current/Blocks"
|
||||
@@ -19,6 +19,7 @@ export default async function CurrentContentPage({
|
||||
searchParams,
|
||||
}: PageArgs<LangParams, UriParams>) {
|
||||
try {
|
||||
console.log({ searchParams });
|
||||
if (!searchParams.uri) {
|
||||
throw new Error("Bad URI")
|
||||
}
|
||||
17
app/[lang]/(live)/current-content-page/template.tsx
Normal file
17
app/[lang]/(live)/current-content-page/template.tsx
Normal file
@@ -0,0 +1,17 @@
|
||||
import Header from "@/components/Current/Header";
|
||||
|
||||
import type { LangParams, PageArgs, UriParams } from "@/types/params";
|
||||
|
||||
export default function CurrentContentpageTemplate({ children, params, searchParams }: React.PropsWithChildren<PageArgs<LangParams, UriParams>>) {
|
||||
// if (!searchParams.uri) {
|
||||
// throw new Error("Bad URI");
|
||||
// }
|
||||
|
||||
return (
|
||||
<>
|
||||
{/* <Header lang={params.lang} pathname={searchParams.uri} /> */}
|
||||
{children}
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import "../core.css";
|
||||
import "../scandic.css";
|
||||
import "../../core.css";
|
||||
import "../../scandic.css";
|
||||
|
||||
import Footer from "@/components/Current/Footer";
|
||||
import LangPopup from "@/components/Current/LangPopup";
|
||||
65
app/[lang]/(preview)/layout.tsx
Normal file
65
app/[lang]/(preview)/layout.tsx
Normal file
@@ -0,0 +1,65 @@
|
||||
import "../../core.css";
|
||||
import "../../scandic.css";
|
||||
|
||||
import Footer from "@/components/Current/Footer";
|
||||
import LangPopup from "@/components/Current/LangPopup";
|
||||
import Script from "next/script";
|
||||
import SkipToMainContent from "@/components/SkipToMainContent";
|
||||
|
||||
import type { Metadata } from "next";
|
||||
import type { LangParams, LayoutArgs } from "@/types/params";
|
||||
import ContentstackLivePreview from "@contentstack/live-preview-utils";
|
||||
|
||||
export const metadata: Metadata = {
|
||||
description: "New web",
|
||||
title: "Scandic Hotels New Web",
|
||||
};
|
||||
|
||||
ContentstackLivePreview.init();
|
||||
|
||||
export default function RootLayout({
|
||||
children,
|
||||
params,
|
||||
}: React.PropsWithChildren<LayoutArgs<LangParams>>) {
|
||||
return (
|
||||
<html lang={params.lang}>
|
||||
<head>
|
||||
<Script
|
||||
data-cookieconsent="ignore"
|
||||
src="/Static/dist/js/head.js?85c84c9e24ae8da3e7af"
|
||||
/>
|
||||
<Script
|
||||
data-cookieconsent="ignore"
|
||||
src="/Static/dist/js/inline.js?00133e5a37de35c51a5d"
|
||||
/>
|
||||
<Script
|
||||
data-cookieconsent="ignore"
|
||||
src="/Static/dist/js/main.js?89d0030e1a04b3b46d0b"
|
||||
/>
|
||||
<Script
|
||||
data-cookieconsent="ignore"
|
||||
src="/Static/dist/js/ng/polyfills.js?1705409330990"
|
||||
/>
|
||||
<Script
|
||||
data-cookieconsent="ignore"
|
||||
src="/Static/dist/js/ng/runtime.js?1705409330990"
|
||||
/>
|
||||
<Script
|
||||
data-cookieconsent="ignore"
|
||||
src="/Static/dist/js/ng/main.js?1705409330990"
|
||||
/>
|
||||
<Script
|
||||
data-cookieconsent="ignore"
|
||||
src="/Static/dist/js/main-ng.js?336b801d6b38eff10884"
|
||||
strategy="lazyOnload"
|
||||
/>
|
||||
</head>
|
||||
<body>
|
||||
<LangPopup lang={params.lang} />
|
||||
<SkipToMainContent lang={params.lang} />
|
||||
{children}
|
||||
<Footer lang={params.lang} />
|
||||
</body>
|
||||
</html>
|
||||
);
|
||||
}
|
||||
62
app/[lang]/(preview)/preview/page.tsx
Normal file
62
app/[lang]/(preview)/preview/page.tsx
Normal file
@@ -0,0 +1,62 @@
|
||||
import { notFound } from "next/navigation";
|
||||
import fs from "node:fs/promises";
|
||||
import path from "node:path";
|
||||
|
||||
import { request } from "@/lib/request";
|
||||
import { GetCurrentBlockPage } from "@/lib/graphql/Query/CurrentBlockPage.graphql";
|
||||
|
||||
import type { PageArgs, LangParams, UriParams } from "@/types/params";
|
||||
import type { GetCurrentBlockPageData } from "@/types/requests/currentBlockPage";
|
||||
|
||||
export default async function CurrentContentPage({
|
||||
params,
|
||||
searchParams,
|
||||
}: PageArgs<LangParams, UriParams>) {
|
||||
try {
|
||||
console.log({ searchParams });
|
||||
if (!searchParams.uri) {
|
||||
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 data = await fs.readFile(filePath, { encoding: "utf-8" });
|
||||
|
||||
if (!data) {
|
||||
throw new Error("No data");
|
||||
}
|
||||
|
||||
const json = JSON.parse(data);
|
||||
|
||||
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}
|
||||
</>
|
||||
);
|
||||
} catch (err) {
|
||||
return notFound();
|
||||
}
|
||||
}
|
||||
@@ -1,7 +0,0 @@
|
||||
export default async function Home() {
|
||||
return (
|
||||
<main>
|
||||
<h1>Hello world!</h1>
|
||||
</main>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user