feat(page): merge pages and blogs into one screen
This commit is contained in:
parent
5603e9a3a2
commit
5b401b7b6e
@ -2,6 +2,7 @@ import { withPayload } from "@payloadcms/next/withPayload";
|
|||||||
import type { NextConfig } from "next";
|
import type { NextConfig } from "next";
|
||||||
|
|
||||||
const nextConfig: NextConfig = {
|
const nextConfig: NextConfig = {
|
||||||
|
trailingSlash: true,
|
||||||
images: {
|
images: {
|
||||||
remotePatterns: [
|
remotePatterns: [
|
||||||
{
|
{
|
||||||
|
@ -1,35 +0,0 @@
|
|||||||
import { BlogDetailContentSkeleton } from "@/components/Blogs/BlogDetail";
|
|
||||||
import Page from "@/components/Pages/Page";
|
|
||||||
import Image from "next/image";
|
|
||||||
import { Suspense } from "react";
|
|
||||||
|
|
||||||
export const metadata = {
|
|
||||||
title: "Cochise Oncology",
|
|
||||||
description: "Cochise Oncology",
|
|
||||||
};
|
|
||||||
|
|
||||||
export default async function CustomPage({ params }: { params?: Promise<{ pageslug?: string }> }) {
|
|
||||||
const slug = (await params)?.pageslug;
|
|
||||||
|
|
||||||
return (
|
|
||||||
<>
|
|
||||||
<Suspense fallback={<Loading />}>
|
|
||||||
<Page slug={slug} />
|
|
||||||
</Suspense>
|
|
||||||
</>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
function Loading() {
|
|
||||||
return (
|
|
||||||
<>
|
|
||||||
<section className="page-section bg-dark-1 bg-gradient-gray-dark-1 light-content bg-scroll overflow-hidden">
|
|
||||||
<div className="bg-shape-1 opacity-003">
|
|
||||||
<Image src="/assets/images/demo-fancy/bg-shape-1.svg" width={1443} height={844} alt="" />
|
|
||||||
</div>
|
|
||||||
</section>
|
|
||||||
|
|
||||||
<BlogDetailContentSkeleton />
|
|
||||||
</>
|
|
||||||
);
|
|
||||||
}
|
|
@ -1,28 +1,36 @@
|
|||||||
import { BeforeFooterBlock } from "@/components/Blocks/BeforeFooter";
|
import { BlogDetailContentSkeleton } from "@/components/Blogs/BlogDetail";
|
||||||
import BlogDetail, { BlogDetailContentSkeleton } from "@/components/Blogs/BlogDetail";
|
import Page from "@/components/Pages/Page";
|
||||||
import { fetchBlogDetail } from "@/services/payload/blog";
|
import { fetchBlogDetail } from "@/services/payload/blog";
|
||||||
|
import { fetchPageBySlug } from "@/services/payload/page";
|
||||||
import { Metadata } from "next";
|
import { Metadata } from "next";
|
||||||
import Image from "next/image";
|
import Image from "next/image";
|
||||||
import { Suspense } from "react";
|
import { Suspense } from "react";
|
||||||
|
|
||||||
export async function generateMetadata({ params }: { params: Promise<{ slug: string }> }): Promise<Metadata> {
|
export async function generateMetadata({ params }: { params: Promise<{ slug: string }> }): Promise<Metadata> {
|
||||||
const name = "Cochise Oncology";
|
const name = "Cochise Oncology";
|
||||||
|
let title = "Page";
|
||||||
|
let description = "Page";
|
||||||
|
let imgUrl = "";
|
||||||
|
|
||||||
const slug = (await params).slug;
|
const slug = (await params).slug;
|
||||||
const blog = await fetchBlogDetail(slug);
|
const blog = await fetchBlogDetail(slug);
|
||||||
|
|
||||||
if (!blog) {
|
// check for blog data
|
||||||
return {
|
if (!!blog) {
|
||||||
title: name,
|
title = `${!!blog.data?.meta?.title ? blog.data?.meta?.title : blog.data.title} - ${name}`;
|
||||||
description: name,
|
description = `${!!blog.data?.meta?.description ? blog.data?.meta?.description : blog.data.title} - ${name}`;
|
||||||
openGraph: {
|
imgUrl = blog.imgUrl;
|
||||||
title: name,
|
|
||||||
description: name,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const title = `${!!blog.data?.meta?.title ? blog.data?.meta?.title : blog.data.title} - ${name}`;
|
// check for page data when blog is not found
|
||||||
const description = `${!!blog.data?.meta?.description ? blog.data?.meta?.description : blog.data.title} - ${name}`;
|
if (!blog) {
|
||||||
|
const page = await fetchPageBySlug({ slug });
|
||||||
|
if (!!page) {
|
||||||
|
title = `${!!page?.meta?.title ? page?.meta?.title : page.title} - ${name}`;
|
||||||
|
description = `${!!page?.meta?.description ? page?.meta?.description : page.title} - ${name}`;
|
||||||
|
imgUrl = page.heroImg?.url;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
title: title,
|
title: title,
|
||||||
@ -30,19 +38,18 @@ export async function generateMetadata({ params }: { params: Promise<{ slug: str
|
|||||||
openGraph: {
|
openGraph: {
|
||||||
title: title,
|
title: title,
|
||||||
description: description,
|
description: description,
|
||||||
images: [{ url: blog.imgUrl }],
|
images: !!imgUrl ? { url: imgUrl } : undefined,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export default async function SingleBlogPage({ params }: { params: Promise<{ slug: string }> }) {
|
export default async function SinglePage({ params }: { params: Promise<{ slug: string }> }) {
|
||||||
const slug = (await params).slug;
|
const slug = (await params).slug;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<Suspense fallback={<Loading />}>
|
<Suspense fallback={<Loading />}>
|
||||||
<BlogDetail slug={slug} />
|
<Page slug={slug} />
|
||||||
<BeforeFooterBlock />
|
|
||||||
</Suspense>
|
</Suspense>
|
||||||
</>
|
</>
|
||||||
);
|
);
|
@ -22,13 +22,13 @@ export function BlogCardItem({ data }: BlogCardItemProps) {
|
|||||||
<div className="post-prev-3 col-12 col-lg-10 offset-lg-1 col-xl-6 offset-xl-0 mt-50">
|
<div className="post-prev-3 col-12 col-lg-10 offset-lg-1 col-xl-6 offset-xl-0 mt-50">
|
||||||
<div className="post-prev-3-container d-block d-sm-flex">
|
<div className="post-prev-3-container d-block d-sm-flex">
|
||||||
<div className="post-prev-3-img">
|
<div className="post-prev-3-img">
|
||||||
<a href={`/blog/${data.slug}`}>
|
<a href={`/${data.slug}`}>
|
||||||
<Image width={400} height={488} src={data?.img?.url ?? ""} alt={data?.img?.alt ?? ""} />
|
<Image width={400} height={488} src={data?.img?.url ?? ""} alt={data?.img?.alt ?? ""} />
|
||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
<div className="post-prev-3-intro">
|
<div className="post-prev-3-intro">
|
||||||
<h4 className="post-prev-3-title">
|
<h4 className="post-prev-3-title">
|
||||||
<a href={`/blog/${data.slug}`}>{data.title}</a>
|
<a href={`/${data.slug}`}>{data.title}</a>
|
||||||
</h4>
|
</h4>
|
||||||
<div className="post-prev-3-text">{data.contentPreview}</div>
|
<div className="post-prev-3-text">{data.contentPreview}</div>
|
||||||
<div className="post-prev-3-info clearfix">
|
<div className="post-prev-3-info clearfix">
|
||||||
|
@ -5,7 +5,7 @@ import Image from "next/image";
|
|||||||
import { FaFacebook, FaLinkedin, FaTwitter } from "react-icons/fa";
|
import { FaFacebook, FaLinkedin, FaTwitter } from "react-icons/fa";
|
||||||
|
|
||||||
export interface BlogDetailProps {
|
export interface BlogDetailProps {
|
||||||
slug: string;
|
slug: string | undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
export default async function BlogDetail({ slug }: BlogDetailProps) {
|
export default async function BlogDetail({ slug }: BlogDetailProps) {
|
||||||
|
@ -1,7 +1,8 @@
|
|||||||
|
import { BeforeFooterBlock } from "@/components/Blocks/BeforeFooter";
|
||||||
import { RenderBlocks } from "@/components/Blocks/RenderBlocks";
|
import { RenderBlocks } from "@/components/Blocks/RenderBlocks";
|
||||||
|
import BlogDetail from "@/components/Blogs/BlogDetail";
|
||||||
import { fetchPageBySlug } from "@/services/payload/page";
|
import { fetchPageBySlug } from "@/services/payload/page";
|
||||||
import Image from "next/image";
|
import Image from "next/image";
|
||||||
import { notFound } from "next/navigation";
|
|
||||||
|
|
||||||
export interface PageProps {
|
export interface PageProps {
|
||||||
slug: string | undefined;
|
slug: string | undefined;
|
||||||
@ -11,7 +12,12 @@ export default async function Page({ slug }: PageProps) {
|
|||||||
const page = await fetchPageBySlug({ slug });
|
const page = await fetchPageBySlug({ slug });
|
||||||
|
|
||||||
if (!page) {
|
if (!page) {
|
||||||
return notFound();
|
return (
|
||||||
|
<>
|
||||||
|
<BlogDetail slug={slug} />;
|
||||||
|
<BeforeFooterBlock />
|
||||||
|
</>
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
@ -7,6 +7,7 @@ import path from "path";
|
|||||||
import { buildConfig } from "payload";
|
import { buildConfig } from "payload";
|
||||||
import sharp from "sharp";
|
import sharp from "sharp";
|
||||||
import { fileURLToPath } from "url";
|
import { fileURLToPath } from "url";
|
||||||
|
import { migrations } from "./migrations";
|
||||||
|
|
||||||
import { BlogCategories } from "@/collections/BlogCategories";
|
import { BlogCategories } from "@/collections/BlogCategories";
|
||||||
import { Blogs } from "@/collections/Blogs";
|
import { Blogs } from "@/collections/Blogs";
|
||||||
@ -58,6 +59,7 @@ export default buildConfig({
|
|||||||
pool: {
|
pool: {
|
||||||
connectionString: process.env.DATABASE_URI || "",
|
connectionString: process.env.DATABASE_URI || "",
|
||||||
},
|
},
|
||||||
|
prodMigrations: migrations,
|
||||||
}),
|
}),
|
||||||
editor: lexicalEditor({
|
editor: lexicalEditor({
|
||||||
features: () => {
|
features: () => {
|
||||||
|
@ -30,7 +30,7 @@ export async function fetchBlog(page: number | undefined) {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function fetchBlogDetail(slug: string) {
|
export async function fetchBlogDetail(slug: string | undefined) {
|
||||||
const payload = await getPayload({ config: payloadConfig });
|
const payload = await getPayload({ config: payloadConfig });
|
||||||
const blogDataQuery = await payload.find({
|
const blogDataQuery = await payload.find({
|
||||||
collection: "blogs",
|
collection: "blogs",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user