Merge pull request 'dev' (#22) from dev into main

Reviewed-on: #22
This commit is contained in:
RizqiSyahrendra 2025-03-14 16:26:42 +00:00
commit 78f8e88cf7
5 changed files with 51 additions and 7 deletions

View File

@ -24,7 +24,7 @@ export async function generateMetadata({ params }: { params: Promise<{ slug: str
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}`;
description = `${!!blog.data?.meta?.description ? blog.data?.meta?.description : blog.data.title}`;
imgUrl = blog.imgUrl;
publishedAt = blog.data.createdAt;
updatedAt = blog.data.updatedAt;
@ -39,7 +39,7 @@ export async function generateMetadata({ params }: { params: Promise<{ slug: str
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}`;
description = `${!!page?.meta?.description ? page?.meta?.description : page.title}`;
imgUrl = page.heroImg?.url;
publishedAt = page.createdAt;
updatedAt = page.updatedAt;

View File

@ -12,28 +12,37 @@ import { Suspense } from "react";
export async function generateMetadata({ params }: { params: Promise<{ slug: string }> }): Promise<Metadata> {
const defaultMetadata = await getDefaultMetadata();
const name = defaultMetadata.openGraph?.siteName ?? "";
let title = "Page";
let title = defaultMetadata.title as string;
let description = defaultMetadata.description as string;
let imgUrl = "";
let canonicalUrl = "";
const slug = (await params).slug;
const team = await fetchTeamDetail(decodeURIComponent(slug));
// check for blog data
if (!!team) {
title = `${team.data.name} - ${name}`;
title = `${!!team.data?.meta?.title ? team.data?.meta?.title : team.data.name} - ${name}`;
description = !!team.data.meta?.description ? team.data.meta?.description : team.data.name;
imgUrl = team.imgUrl;
if (!!team?.data?.meta?.canonical_url) {
canonicalUrl = team.data.meta.canonical_url;
}
}
defaultMetadata.title = title;
defaultMetadata.description = undefined;
defaultMetadata.description = description;
if (!!defaultMetadata.openGraph) {
// @ts-ignore
defaultMetadata.openGraph.type = "article";
defaultMetadata.openGraph.title = title;
defaultMetadata.openGraph.description = undefined;
defaultMetadata.openGraph.description = description;
defaultMetadata.openGraph.images = !!imgUrl ? [imgUrl] : undefined;
}
if (!!defaultMetadata.alternates && !!canonicalUrl) {
defaultMetadata.alternates.canonical = canonicalUrl;
}
defaultMetadata.twitter = {
card: "summary_large_image",
title: title,

View File

@ -34,6 +34,28 @@ export const Teams: CollectionConfig = {
type: "richText",
editor: lexicalEditor({}),
},
{
name: "meta",
label: "Page Meta",
type: "group",
fields: [
{
name: "title",
label: "Title",
type: "text",
},
{
name: "description",
label: "Description",
type: "textarea",
},
{
name: "canonical_url",
label: "Canonical Url",
type: "text",
},
],
},
],
admin: {
hideAPIURL: true,

View File

@ -21,7 +21,8 @@ export function middleware(request: NextRequest) {
// redirect for /blog/<slug>/ path
const blogPathRegex = /^\/blog\/([^\/]+)(\/[^\/]*)*\/?$/;
if (blogPathRegex.test(path)) {
console.log("path", blogPathRegex.test(path) && !path.includes("/blog/?"));
if (blogPathRegex.test(path) && !path.includes("/blog/?")) {
const newBlogPath = path.replace(/^\/blog/, "") || "/";
return NextResponse.redirect(`${mainUrl}${newBlogPath}`, 301);
}

View File

@ -392,6 +392,11 @@ export interface Team {
};
[k: string]: unknown;
} | null;
meta?: {
title?: string | null;
description?: string | null;
canonical_url?: string | null;
};
updatedAt: string;
createdAt: string;
}
@ -822,6 +827,13 @@ export interface TeamsSelect<T extends boolean = true> {
role?: T;
img?: T;
biography?: T;
meta?:
| T
| {
title?: T;
description?: T;
canonical_url?: T;
};
updatedAt?: T;
createdAt?: T;
}