dev #10
@ -3,44 +3,57 @@ import HeroOther from "@/components/HeroOther";
|
||||
import Page from "@/components/Pages/Page";
|
||||
import { fetchBlogDetail } from "@/services/payload/blog";
|
||||
import { fetchPageBySlug } from "@/services/payload/page";
|
||||
import { getDefaultMetadata } from "@/utils/metadata";
|
||||
import { Metadata } from "next";
|
||||
import { Suspense } from "react";
|
||||
|
||||
export async function generateMetadata({ params }: { params: Promise<{ slug: string }> }): Promise<Metadata> {
|
||||
const name = "Cochise Oncology";
|
||||
const defaultMetadata = await getDefaultMetadata();
|
||||
const name = defaultMetadata.openGraph?.siteName ?? "";
|
||||
let title = "Page";
|
||||
let description = "Page";
|
||||
let publishedAt = "";
|
||||
let updatedAt = "";
|
||||
let imgUrl = "";
|
||||
|
||||
const slug = (await params).slug;
|
||||
const blog = await fetchBlogDetail(slug);
|
||||
|
||||
// check for blog data
|
||||
if (!!blog) {
|
||||
// check for blog data
|
||||
title = `${!!blog.data?.meta?.title ? blog.data?.meta?.title : blog.data.title} - ${name}`;
|
||||
description = `${!!blog.data?.meta?.description ? blog.data?.meta?.description : blog.data.title} - ${name}`;
|
||||
imgUrl = blog.imgUrl;
|
||||
}
|
||||
|
||||
publishedAt = blog.data.createdAt;
|
||||
updatedAt = blog.data.updatedAt;
|
||||
} else {
|
||||
// check for page data when blog is not found
|
||||
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;
|
||||
publishedAt = page.createdAt;
|
||||
updatedAt = page.updatedAt;
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
title: title,
|
||||
description: description,
|
||||
openGraph: {
|
||||
title: title,
|
||||
description: description,
|
||||
images: !!imgUrl ? { url: imgUrl } : undefined,
|
||||
},
|
||||
defaultMetadata.title = title;
|
||||
defaultMetadata.description = description;
|
||||
if (!!defaultMetadata.openGraph) {
|
||||
defaultMetadata.openGraph.title = title;
|
||||
// @ts-ignore
|
||||
defaultMetadata.openGraph.type = "article";
|
||||
defaultMetadata.openGraph.description = description;
|
||||
defaultMetadata.openGraph.title = title;
|
||||
defaultMetadata.openGraph.images = !!imgUrl ? { url: imgUrl } : undefined;
|
||||
}
|
||||
defaultMetadata.other = {
|
||||
"article:published_time": publishedAt,
|
||||
"article:modified_time": updatedAt,
|
||||
};
|
||||
|
||||
return defaultMetadata;
|
||||
}
|
||||
|
||||
export default async function SinglePage({ params }: { params: Promise<{ slug: string }> }) {
|
||||
|
@ -3,9 +3,11 @@ import Footer from "@/components/Footer";
|
||||
import Header from "@/components/Header";
|
||||
import InitialScript from "@/components/InitialScript";
|
||||
import { navMenuData } from "@/data/menu";
|
||||
import { getDefaultMetadata } from "@/utils/metadata";
|
||||
|
||||
import "@public/assets/css/styles.css";
|
||||
import "jarallax/dist/jarallax.min.css";
|
||||
import { Metadata } from "next";
|
||||
import { Roboto } from "next/font/google";
|
||||
import "photoswipe/dist/photoswipe.css";
|
||||
import "react-modal-video/css/modal-video.css";
|
||||
@ -15,6 +17,11 @@ import "tippy.js/dist/tippy.css";
|
||||
|
||||
const roboto = Roboto({ subsets: ["latin"] });
|
||||
|
||||
export async function generateMetadata(): Promise<Metadata> {
|
||||
const metadata = await getDefaultMetadata();
|
||||
return metadata;
|
||||
}
|
||||
|
||||
export default function MainLayout({
|
||||
children,
|
||||
}: Readonly<{
|
||||
|
@ -1,4 +1,4 @@
|
||||
import formatSlug from "@/utils/formatSlug";
|
||||
import formatSlug from "@/utils/payload/formatSlug";
|
||||
import type { CollectionConfig } from "payload";
|
||||
|
||||
export const BlogCategories: CollectionConfig = {
|
||||
|
@ -1,4 +1,4 @@
|
||||
import formatSlug from "@/utils/formatSlug";
|
||||
import formatSlug from "@/utils/payload/formatSlug";
|
||||
import type { CollectionConfig } from "payload";
|
||||
|
||||
export const BlogTags: CollectionConfig = {
|
||||
|
@ -1,6 +1,6 @@
|
||||
import type { CollectionConfig } from "payload";
|
||||
import formatSlug from "@/utils/payload/formatSlug";
|
||||
import { lexicalEditor } from "@payloadcms/richtext-lexical";
|
||||
import formatSlug from "@/utils/formatSlug";
|
||||
import type { CollectionConfig } from "payload";
|
||||
|
||||
export const Blogs: CollectionConfig = {
|
||||
slug: "blogs",
|
||||
@ -59,8 +59,8 @@ export const Blogs: CollectionConfig = {
|
||||
type: "textarea",
|
||||
},
|
||||
{
|
||||
name: "cannonical_url",
|
||||
label: "Cannonical Url",
|
||||
name: "canonical_url",
|
||||
label: "Canonical Url",
|
||||
type: "text",
|
||||
},
|
||||
],
|
||||
@ -74,6 +74,24 @@ export const Blogs: CollectionConfig = {
|
||||
position: "sidebar",
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "createdBy",
|
||||
type: "relationship",
|
||||
relationTo: "users",
|
||||
hidden: true,
|
||||
// hooks: {
|
||||
// beforeChange: [setAuthor],
|
||||
// },
|
||||
},
|
||||
{
|
||||
name: "updatedBy",
|
||||
type: "relationship",
|
||||
relationTo: "users",
|
||||
hidden: true,
|
||||
// hooks: {
|
||||
// beforeChange: [setAuthor],
|
||||
// },
|
||||
},
|
||||
],
|
||||
admin: {
|
||||
hideAPIURL: true,
|
||||
|
@ -7,7 +7,7 @@ import { GoogleReviewBlock } from "@/blocks/GoogleReview";
|
||||
import { HorizontalImageContentBlock } from "@/blocks/HorizontalImageContent";
|
||||
import { ImageSliderBlock } from "@/blocks/ImageSlider";
|
||||
import { OurTeamBlock } from "@/blocks/OurTeam";
|
||||
import formatSlug from "@/utils/formatSlug";
|
||||
import formatSlug from "@/utils/payload/formatSlug";
|
||||
import { CollectionConfig } from "payload";
|
||||
|
||||
export const Pages: CollectionConfig = {
|
||||
|
@ -11,5 +11,10 @@ export const Users: CollectionConfig = {
|
||||
fields: [
|
||||
// Email added by default
|
||||
// Add more fields as needed
|
||||
{
|
||||
name: "name",
|
||||
label: "Name",
|
||||
type: "text",
|
||||
},
|
||||
],
|
||||
};
|
||||
|
@ -8,7 +8,10 @@ export function middleware(request: NextRequest) {
|
||||
const host = request.headers.get("x-forwarded-host") || request.nextUrl.hostname;
|
||||
const path = request.nextUrl.pathname + request.nextUrl.search;
|
||||
// Construct the full URL
|
||||
const fullUrl = `${protocol}://${host}${path}`;
|
||||
const mainUrl = `${protocol}://${host}`;
|
||||
const fullUrl = `${mainUrl}${path}`;
|
||||
|
||||
request.headers.set("x-main-url", mainUrl);
|
||||
request.headers.set("x-full-url", fullUrl);
|
||||
|
||||
return NextResponse.next({
|
||||
|
@ -83,6 +83,7 @@ export interface UserAuthOperations {
|
||||
*/
|
||||
export interface User {
|
||||
id: number;
|
||||
name?: string | null;
|
||||
updatedAt: string;
|
||||
createdAt: string;
|
||||
email: string;
|
||||
@ -143,9 +144,11 @@ export interface Blog {
|
||||
meta?: {
|
||||
title?: string | null;
|
||||
description?: string | null;
|
||||
cannonical_url?: string | null;
|
||||
canonical_url?: string | null;
|
||||
};
|
||||
is_published?: boolean | null;
|
||||
createdBy?: (number | null) | User;
|
||||
updatedBy?: (number | null) | User;
|
||||
updatedAt: string;
|
||||
createdAt: string;
|
||||
}
|
||||
@ -593,6 +596,7 @@ export interface PayloadMigration {
|
||||
* via the `definition` "users_select".
|
||||
*/
|
||||
export interface UsersSelect<T extends boolean = true> {
|
||||
name?: T;
|
||||
updatedAt?: T;
|
||||
createdAt?: T;
|
||||
email?: T;
|
||||
@ -638,9 +642,11 @@ export interface BlogsSelect<T extends boolean = true> {
|
||||
| {
|
||||
title?: T;
|
||||
description?: T;
|
||||
cannonical_url?: T;
|
||||
canonical_url?: T;
|
||||
};
|
||||
is_published?: T;
|
||||
createdBy?: T;
|
||||
updatedBy?: T;
|
||||
updatedAt?: T;
|
||||
createdAt?: T;
|
||||
}
|
||||
|
21
src/utils/metadata.ts
Normal file
21
src/utils/metadata.ts
Normal file
@ -0,0 +1,21 @@
|
||||
import { Metadata } from "next";
|
||||
import { headers } from "next/headers";
|
||||
|
||||
export async function getDefaultMetadata(): Promise<Metadata> {
|
||||
const headersList = await headers();
|
||||
const mainUrl = headersList.get("x-main-url") ?? "";
|
||||
const fullUrl = headersList.get("x-full-url") ?? "";
|
||||
|
||||
return {
|
||||
metadataBase: new URL(mainUrl),
|
||||
openGraph: {
|
||||
type: "website",
|
||||
locale: "en_US",
|
||||
url: fullUrl,
|
||||
siteName: "Cochise Oncology",
|
||||
},
|
||||
alternates: {
|
||||
canonical: "./",
|
||||
},
|
||||
};
|
||||
}
|
14
src/utils/payload/setAuthor.ts
Normal file
14
src/utils/payload/setAuthor.ts
Normal file
@ -0,0 +1,14 @@
|
||||
import { FieldHook } from "payload";
|
||||
|
||||
const setAuthor: FieldHook = ({ req, operation, data, value }) => {
|
||||
// if (req.user && !!data) {
|
||||
// if (operation === "create") {
|
||||
// data.createdBy = req.user.id;
|
||||
// }
|
||||
// data.updatedBy = req.user.id;
|
||||
// }
|
||||
|
||||
return data;
|
||||
};
|
||||
|
||||
export default setAuthor;
|
Loading…
x
Reference in New Issue
Block a user