Complete SEO metadata, JSON-LD, real tag/projects pages, OG fallback fixes
Deploy Frontend / deploy (push) Successful in 1m11s
Deploy Frontend / deploy (push) Successful in 1m11s
This commit is contained in:
1 parent
88703ae4ea
commit
32a7481ef6
13 files changed
+397
-40
No files matched your search
@@ -7,6 +7,7 @@ import Hero from "../components/hero/hero";
|
||||
import { getDictionary } from "@/app/lib/functions/dictionaries";
|
||||
import { getDefaultLocale } from "@/app/lib/functions/utils";
|
||||
import { Metadata } from "next";
|
||||
import { SITE_URL, ogImageUrl } from "@/app/lib/site-config";
|
||||
|
||||
const description =
|
||||
"Hi, I am Parsa Aghayi, a Frontend & Backend Developer. Here's my personal website to know more about me and contact me if you want! ;)";
|
||||
@@ -17,7 +18,13 @@ export const metadata: Metadata = {
|
||||
openGraph: {
|
||||
title: "Parsa Aghayi's Personal Website",
|
||||
description,
|
||||
images: [`${process.env.NEXT_PUBLIC_FRONT_URL}/images/profile.png`],
|
||||
images: [`${SITE_URL}/images/profile.png`],
|
||||
},
|
||||
twitter: {
|
||||
card: "summary_large_image",
|
||||
title: "Parsa Aghayi's Personal Website",
|
||||
description,
|
||||
images: [ogImageUrl("Parsa Aghayi")],
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
@@ -16,14 +16,16 @@ export default function BurgerButton({ dict }: BurgerButtonProps) {
|
||||
<button
|
||||
className="flex select-none items-center justify-center whitespace-nowrap rounded-md bg-[#FD6F00] px-4 py-2 text-[16px] font-[600] text-[#fff] lg:hidden xl:text-[20px]"
|
||||
onClick={() => setClicked(!clicked)}
|
||||
aria-label="Toggle navigation menu"
|
||||
aria-expanded={clicked}
|
||||
>
|
||||
<Image
|
||||
src={"/images/icons/burger-menu.svg"}
|
||||
width={25}
|
||||
height={25}
|
||||
alt="burger-menu svg"
|
||||
alt=""
|
||||
className="burger-menu"
|
||||
onClick={() => setClicked(!clicked)}
|
||||
aria-hidden
|
||||
/>
|
||||
</button>
|
||||
<MobileMenu clicked={clicked} setClicked={setClicked} dict={dict} />
|
||||
|
||||
@@ -1,15 +1,44 @@
|
||||
import { Metadata } from "next";
|
||||
import { getDictionary } from "@/app/lib/functions/dictionaries";
|
||||
import { getDefaultLocale } from "@/app/lib/functions/utils";
|
||||
import { ogImageUrl } from "@/app/lib/site-config";
|
||||
import Projects from "../components/projects/projects";
|
||||
|
||||
export const metadata: Metadata = {
|
||||
title: "projects",
|
||||
description: "parsa aghayi personal website projects description",
|
||||
title: "Projects | Parsa Aghayi",
|
||||
description:
|
||||
"Explore a selection of Parsa Aghayi's web development projects: high-performance React and Next.js applications, custom interfaces and full-stack builds.",
|
||||
openGraph: {
|
||||
title: "parsa aghayi personal website projects page title",
|
||||
description: "parsa aghayi personal website projects description",
|
||||
images: [`${process.env.NEXT_PUBLIC_FRONT_URL}/og-image?text=parsa aghayi's projects`],
|
||||
title: "Parsa Aghayi's Projects",
|
||||
description:
|
||||
"A selection of high-performance React and Next.js projects built by Parsa Aghayi.",
|
||||
images: [ogImageUrl("Parsa Aghayi's Projects")],
|
||||
},
|
||||
twitter: {
|
||||
card: "summary_large_image",
|
||||
title: "Parsa Aghayi's Projects",
|
||||
description:
|
||||
"A selection of high-performance React and Next.js projects built by Parsa Aghayi.",
|
||||
images: [ogImageUrl("Parsa Aghayi's Projects")],
|
||||
},
|
||||
};
|
||||
|
||||
export default function Projects() {
|
||||
return <div>Projects</div>;
|
||||
}
|
||||
export default async function ProjectsPage() {
|
||||
const dict = await getDictionary(await getDefaultLocale());
|
||||
|
||||
return (
|
||||
<div className="mesh-gradient flex min-h-screen w-full flex-col items-center">
|
||||
<div className="flex w-full max-w-[1420px] flex-col items-center gap-16 px-6 py-28">
|
||||
<div className="flex max-w-[720px] flex-col items-center gap-4 text-center">
|
||||
<h1 className="text-3xl font-bold tracking-tight text-foreground md:text-5xl">
|
||||
{dict.website.homePage.projects.title}
|
||||
</h1>
|
||||
<p className="text-lg font-medium leading-relaxed text-muted-foreground">
|
||||
{dict.website.homePage.projects.description}
|
||||
</p>
|
||||
</div>
|
||||
<Projects dict={dict} />
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -10,6 +10,7 @@ import NoDataFounded from "../components/no-data-founded/noDataFounded";
|
||||
import { Metadata } from "next";
|
||||
import { getDictionary } from "@/app/lib/functions/dictionaries";
|
||||
import { getDefaultLocale } from "@/app/lib/functions/utils";
|
||||
import { ogImageUrl } from "@/app/lib/site-config";
|
||||
|
||||
export const metadata: Metadata = {
|
||||
title: "All Categories List",
|
||||
@@ -19,9 +20,7 @@ export const metadata: Metadata = {
|
||||
title: "All Categories List",
|
||||
description:
|
||||
"Browse through our collection of categories to find posts on your favorite topics. Whether you`re looking for insightful articles, how-tos, or the latest trends, our categories make it easy to discover content tailored to your interests.",
|
||||
images: [
|
||||
`${process.env.NEXT_PUBLIC_FRONT_URL}/og-image?text=All Categories List`,
|
||||
],
|
||||
images: [ogImageUrl("All Categories List")],
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
@@ -10,14 +10,16 @@ export default function BurgerButton() {
|
||||
<button
|
||||
className="flex select-none items-center justify-center whitespace-nowrap rounded-md bg-blog-purple px-2 py-1 text-[16px] font-[600] text-[#fff] sm:px-2 sm:py-2 md:hidden"
|
||||
onClick={() => setClicked(!clicked)}
|
||||
aria-label="Toggle navigation menu"
|
||||
aria-expanded={clicked}
|
||||
>
|
||||
<Image
|
||||
src={"/images/icons/burger-menu.svg"}
|
||||
width={25}
|
||||
height={25}
|
||||
alt="burger-menu svg"
|
||||
alt=""
|
||||
className="burger-menu"
|
||||
onClick={() => setClicked(!clicked)}
|
||||
aria-hidden
|
||||
/>
|
||||
</button>
|
||||
<MobileMenu clicked={clicked} setClicked={setClicked} />
|
||||
|
||||
@@ -10,6 +10,7 @@ import Pagination from "../../components/pagination/pagination";
|
||||
import { Metadata } from "next";
|
||||
import { getDictionary } from "@/app/lib/functions/dictionaries";
|
||||
import { getDefaultLocale } from "@/app/lib/functions/utils";
|
||||
import { ogImageUrl } from "@/app/lib/site-config";
|
||||
|
||||
type FilterKey = "new" | "popular";
|
||||
|
||||
@@ -53,8 +54,7 @@ const getFilterKey = (filter: string): FilterKey | null => {
|
||||
return normalized in FILTERS ? (normalized as FilterKey) : null;
|
||||
};
|
||||
|
||||
const ogImage = (text: string) =>
|
||||
`${process.env.NEXT_PUBLIC_FRONT_URL}/og-image?text=${encodeURIComponent(text)}`;
|
||||
const ogImage = (text: string) => ogImageUrl(text);
|
||||
|
||||
export async function generateMetadata(
|
||||
props: FilteredPostsPagepropsType,
|
||||
|
||||
@@ -2,23 +2,55 @@ import type { Metadata } from "next";
|
||||
import Header from "./components/header/header";
|
||||
import Footer from "./components/footer/footer";
|
||||
import NextTopLoader from "nextjs-toploader";
|
||||
import { SITE_NAME, SITE_NAME_EN, SITE_URL, ogImageUrl } from "@/app/lib/site-config";
|
||||
|
||||
const BLOG_TITLE = `${SITE_NAME_EN}'s Blog`;
|
||||
|
||||
export const metadata: Metadata = {
|
||||
metadataBase: new URL(SITE_URL),
|
||||
title: {
|
||||
template: "%s | parsa aghayi's blog",
|
||||
default: "parsa aghayi's blog",
|
||||
template: `%s | ${BLOG_TITLE}`,
|
||||
default: BLOG_TITLE,
|
||||
},
|
||||
description: "parsa aghayi personal blog",
|
||||
openGraph: {
|
||||
title: {
|
||||
template: "%s | parsa aghayi's blog",
|
||||
default: "parsa aghayi's blog",
|
||||
description:
|
||||
`${SITE_NAME_EN}'s blog: practical articles about React, Next.js, TypeScript, web performance and frontend engineering, written in English and Persian.`,
|
||||
alternates: {
|
||||
canonical: "/blog",
|
||||
languages: {
|
||||
en: "/blog",
|
||||
fa: "/blog",
|
||||
"x-default": "/blog",
|
||||
},
|
||||
description: "parsa aghayi personal blog",
|
||||
},
|
||||
openGraph: {
|
||||
type: "website",
|
||||
url: `${SITE_URL}/blog`,
|
||||
siteName: SITE_NAME,
|
||||
title: {
|
||||
template: `%s | ${BLOG_TITLE}`,
|
||||
default: BLOG_TITLE,
|
||||
},
|
||||
description: `${SITE_NAME_EN}'s blog: practical frontend engineering articles in English and Persian.`,
|
||||
locale: "en_US",
|
||||
alternateLocale: ["fa_IR"],
|
||||
images: [
|
||||
`${process.env.NEXT_PUBLIC_FRONT_URL}/og-image?text=parsa aghayi's personal blog`,
|
||||
{
|
||||
url: ogImageUrl(`${SITE_NAME_EN}'s Blog`),
|
||||
width: 1200,
|
||||
height: 630,
|
||||
alt: BLOG_TITLE,
|
||||
},
|
||||
],
|
||||
},
|
||||
twitter: {
|
||||
card: "summary_large_image",
|
||||
title: {
|
||||
template: `%s | ${BLOG_TITLE}`,
|
||||
default: BLOG_TITLE,
|
||||
},
|
||||
description: `${SITE_NAME_EN}'s blog: practical frontend engineering articles.`,
|
||||
images: [ogImageUrl(`${SITE_NAME_EN}'s Blog`)],
|
||||
},
|
||||
};
|
||||
|
||||
export default function RootLayout({
|
||||
|
||||
@@ -12,6 +12,7 @@ import { redirect } from "next/navigation";
|
||||
import { renderBody } from "./body";
|
||||
import { getCoverImageSrc } from "./coverImage";
|
||||
import { AUTHOR_PROFILE_URL } from "@/app/lib/social-links";
|
||||
import { SITE_NAME, SITE_NAME_EN, SITE_URL } from "@/app/lib/site-config";
|
||||
|
||||
async function fetchPostData(postSlug: string): Promise<PostSlugPagePostType> {
|
||||
const res = await fetch(
|
||||
@@ -48,14 +49,44 @@ export async function generateMetadata(props: PostSlugPagepropsType): Promise<Me
|
||||
const params = await props.params;
|
||||
const post: PostSlugPagePostType = await fetchPostData(params.postSlug);
|
||||
const coverImage = getCoverImageSrc(post.post.featured_image);
|
||||
const pageUrl = `${SITE_URL}/blog/posts/${params.postSlug}`;
|
||||
|
||||
const ogImage = coverImage
|
||||
? {
|
||||
url: coverImage,
|
||||
width: 1200,
|
||||
height: 630,
|
||||
alt: `${post.post.title} featured image`,
|
||||
}
|
||||
: { url: `${SITE_URL}/og-image?text=${encodeURIComponent(post.post.title)}`, width: 1200, height: 630, alt: post.post.title };
|
||||
|
||||
return {
|
||||
title: post.post.title,
|
||||
description: post.post.excerpt,
|
||||
alternates: {
|
||||
canonical: pageUrl,
|
||||
},
|
||||
openGraph: {
|
||||
title: post.post.title,
|
||||
description: post.post.excerpt,
|
||||
...(coverImage ? { images: [coverImage] } : {}),
|
||||
url: pageUrl,
|
||||
type: "article",
|
||||
siteName: SITE_NAME,
|
||||
locale: "en_US",
|
||||
alternateLocale: ["fa_IR"],
|
||||
images: [ogImage],
|
||||
publishedTime: post.post.published_at ?? undefined,
|
||||
modifiedTime: post.post.updated_at ?? undefined,
|
||||
authors: [AUTHOR_PROFILE_URL],
|
||||
...(post.post.tags && post.post.tags.length > 0
|
||||
? { tags: post.post.tags.map((t) => t.name ?? String(t)) }
|
||||
: {}),
|
||||
},
|
||||
twitter: {
|
||||
card: "summary_large_image",
|
||||
title: post.post.title,
|
||||
description: post.post.excerpt,
|
||||
images: [ogImage.url],
|
||||
},
|
||||
};
|
||||
}
|
||||
@@ -75,8 +106,69 @@ export default async function SinglePost(props: PostSlugPagepropsType) {
|
||||
? postData.related_posts
|
||||
: [];
|
||||
|
||||
const pageUrl = `${SITE_URL}/blog/posts/${post.slug ?? params.postSlug}`;
|
||||
const articleJsonLd: Record<string, unknown> = {
|
||||
"@context": "https://schema.org",
|
||||
"@type": "Article",
|
||||
headline: post.title,
|
||||
description: post.excerpt ?? undefined,
|
||||
...(coverImage ? { image: coverImage } : {}),
|
||||
datePublished: post.published_at ?? undefined,
|
||||
dateModified: post.updated_at ?? post.published_at ?? undefined,
|
||||
author: {
|
||||
"@type": "Person",
|
||||
name: authorName || SITE_NAME_EN,
|
||||
url: AUTHOR_PROFILE_URL,
|
||||
},
|
||||
publisher: {
|
||||
"@type": "Person",
|
||||
name: SITE_NAME_EN,
|
||||
url: SITE_URL,
|
||||
},
|
||||
mainEntityOfPage: pageUrl,
|
||||
};
|
||||
const breadcrumbJsonLd: Record<string, unknown> = {
|
||||
"@context": "https://schema.org",
|
||||
"@type": "BreadcrumbList",
|
||||
itemListElement: [
|
||||
{
|
||||
"@type": "ListItem",
|
||||
position: 1,
|
||||
name: "Blog",
|
||||
item: `${SITE_URL}/blog`,
|
||||
},
|
||||
...(categoryName && categorySlug
|
||||
? [
|
||||
{
|
||||
"@type": "ListItem",
|
||||
position: 2,
|
||||
name: categoryName,
|
||||
item: `${SITE_URL}/blog/categories/${categorySlug}`,
|
||||
},
|
||||
]
|
||||
: []),
|
||||
{
|
||||
"@type": "ListItem",
|
||||
position: categoryName && categorySlug ? 3 : 2,
|
||||
name: post.title,
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="flex w-full max-w-[1280px] flex-wrap justify-center sm:my-10">
|
||||
<script
|
||||
type="application/ld+json"
|
||||
dangerouslySetInnerHTML={{
|
||||
__html: JSON.stringify(articleJsonLd),
|
||||
}}
|
||||
/>
|
||||
<script
|
||||
type="application/ld+json"
|
||||
dangerouslySetInnerHTML={{
|
||||
__html: JSON.stringify(breadcrumbJsonLd),
|
||||
}}
|
||||
/>
|
||||
<div className="mt-5 flex w-full max-w-[90%] flex-col gap-5">
|
||||
<h1 className="text-[36px] font-[700] capitalize text-blog-text-default">
|
||||
{post.title}
|
||||
@@ -93,7 +185,9 @@ export default async function SinglePost(props: PostSlugPagepropsType) {
|
||||
{dict.blog.homePage.by}
|
||||
</p>
|
||||
<Link
|
||||
href={"/"}
|
||||
href={AUTHOR_PROFILE_URL}
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
className="whitespace-nowrap text-[14px] font-[400] capitalize text-blog-text-default hover:underline md:text-[16px]"
|
||||
>
|
||||
{authorName}
|
||||
|
||||
@@ -1,8 +1,148 @@
|
||||
type propsType = {
|
||||
params: Promise<{ slug: string }>;
|
||||
};
|
||||
import {
|
||||
tagSlugPropsType,
|
||||
TagDataType,
|
||||
} from "@/app/types/types";
|
||||
import { Metadata } from "next";
|
||||
import Image from "next/image";
|
||||
import Link from "next/link";
|
||||
import { redirect } from "next/navigation";
|
||||
import NoDataFounded from "../../components/no-data-founded/noDataFounded";
|
||||
import Pagination from "../../components/pagination/pagination";
|
||||
import { getDictionary } from "@/app/lib/functions/dictionaries";
|
||||
import { getDefaultLocale } from "@/app/lib/functions/utils";
|
||||
|
||||
export default async function SingleTag(props: propsType) {
|
||||
const params = await props.params;
|
||||
return <div>{params.slug}</div>;
|
||||
async function fetchTagData(
|
||||
slug: string,
|
||||
searchParams: URLSearchParams,
|
||||
): Promise<TagDataType> {
|
||||
const res = await fetch(
|
||||
`${process.env.NEXT_PUBLIC_BLOG_API_URL}/tags/by-slug/${slug}/posts?per_page=${searchParams.get("per_page") || process.env.NEXT_PUBLIC_POSTS_PER_CATEGORY_PAGE}${searchParams.get("page") ? `&page=${searchParams.get("page")}` : ""}`,
|
||||
{
|
||||
cache: process.env.NEXT_PUBLIC_BLOG_CACHE ? "force-cache" : "no-store",
|
||||
},
|
||||
);
|
||||
|
||||
if (res.status === 404) {
|
||||
redirect("/blog/404");
|
||||
}
|
||||
|
||||
return res.json();
|
||||
}
|
||||
|
||||
export async function generateMetadata(props: tagSlugPropsType): Promise<Metadata> {
|
||||
const params = await props.params;
|
||||
const tagData: TagDataType = await fetchTagData(
|
||||
params.slug,
|
||||
new URLSearchParams(),
|
||||
);
|
||||
|
||||
return {
|
||||
title: tagData.tag.name,
|
||||
description: `Posts tagged with "${tagData.tag.name}" on Parsa Aghayi's blog.`,
|
||||
};
|
||||
}
|
||||
|
||||
export default async function SingleTag(props: tagSlugPropsType) {
|
||||
const searchParams = await props.searchParams;
|
||||
const params = await props.params;
|
||||
const dict = await getDictionary(await getDefaultLocale());
|
||||
|
||||
const tagData: TagDataType = await fetchTagData(
|
||||
params.slug,
|
||||
new URLSearchParams(searchParams as Record<string, string>),
|
||||
);
|
||||
|
||||
const tagName = tagData.tag.name || params.slug.replaceAll(/%20|-|_/g, " ");
|
||||
|
||||
return (
|
||||
<div className="flex w-full max-w-[1280px] flex-wrap justify-center sm:my-10">
|
||||
<div className="mt-5 flex w-full max-w-[90%] flex-col gap-5">
|
||||
<h1 className="text-[36px] font-[700] capitalize text-blog-text-default">
|
||||
{tagName}
|
||||
</h1>
|
||||
<div className="flex w-full flex-wrap gap-2">
|
||||
<div className="flex gap-2">
|
||||
<p className="text-[14px] font-[600] text-blog-text-passive md:text-[16px]">
|
||||
{dict.blog.categoriySinglePage.total}
|
||||
{tagName}
|
||||
</p>
|
||||
<span className="text-[14px] font-[400] text-blog-text-default md:text-[16px]">
|
||||
{tagData.meta.total}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div className="my-10 flex w-full max-w-[90%] flex-wrap justify-center gap-5">
|
||||
<ul className="my-10 flex w-full flex-wrap gap-2">
|
||||
<li className="flex items-center gap-2">
|
||||
<Link
|
||||
href={"/blog"}
|
||||
className="text-[12px] font-[400] capitalize text-blog-text-passive hover:underline"
|
||||
>
|
||||
{dict.blog.header.Home}
|
||||
</Link>
|
||||
<span className="mt-[-2px] -rotate-45 scale-[3] select-none text-[12px] font-[400] text-blog-text-passive">
|
||||
-
|
||||
</span>
|
||||
</li>
|
||||
<li className="flex items-center gap-2">
|
||||
<p className="text-[12px] font-[600] capitalize text-blog-text-default">
|
||||
{tagName}
|
||||
</p>
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
<div className="mb-10 flex w-full flex-wrap justify-center gap-10">
|
||||
{tagData.posts.length > 0 ? (
|
||||
tagData.posts.map((post) => (
|
||||
<div
|
||||
key={post.id}
|
||||
className="flex w-full flex-col items-center justify-start gap-1 sm:w-[45%]"
|
||||
>
|
||||
<Image
|
||||
className="mb-3 rounded-md"
|
||||
src={post.featured_image}
|
||||
alt={`${post.title} post featured image`}
|
||||
loading="lazy"
|
||||
width={600}
|
||||
height={500}
|
||||
/>
|
||||
<div className="mb-2 flex w-full flex-wrap gap-2">
|
||||
<div className="flex gap-2">
|
||||
<p className="text-[14px] font-[600] text-blog-text-passive md:text-[16px]">
|
||||
{dict.blog.homePage.by}
|
||||
</p>
|
||||
<Link
|
||||
href={"/"}
|
||||
className="whitespace-nowrap text-[14px] font-[400] capitalize text-blog-text-default hover:underline md:text-[16px]"
|
||||
>
|
||||
{post.author.name}
|
||||
</Link>
|
||||
</div>
|
||||
</div>
|
||||
<Link
|
||||
className="w-full text-start text-[24px] font-[600] text-blog-text-default hover:underline"
|
||||
href={`/blog/posts/${post.slug}`}
|
||||
>
|
||||
{post.title}
|
||||
</Link>
|
||||
<p className="w-full text-start text-[16px] font-[400] text-blog-text-default">
|
||||
{post.excerpt}
|
||||
</p>
|
||||
</div>
|
||||
))
|
||||
) : (
|
||||
<NoDataFounded seed={params.slug} />
|
||||
)}
|
||||
</div>
|
||||
{tagData.posts.length > 0 && tagData.meta.last_page > 1 && (
|
||||
<Pagination
|
||||
meta={tagData.meta}
|
||||
baseUrl={`/blog/tags/${tagData.tag.slug}`}
|
||||
dict={dict}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
export const SITE_URL = (
|
||||
process.env.NEXT_PUBLIC_FRONT_URL || "https://parsaaghayi.ir"
|
||||
).replace(/\/+$/, "");
|
||||
|
||||
export const SITE_NAME = "پارسا آقایی";
|
||||
export const SITE_NAME_EN = "Parsa Aghayi";
|
||||
|
||||
export const SITE_DESCRIPTION =
|
||||
"وبسایت شخصی پارسا آقایی، توسعهدهنده ارشد فرانتاند و معمار وب. مقالات تخصصی در حوزه React، Next.js، TypeScript، بهینهسازی سرعت و معماری نرمافزار، بههمراه معرفی خدمات و پروژهها.";
|
||||
|
||||
export function ogImageUrl(text: string): string {
|
||||
return `${SITE_URL}/og-image?text=${encodeURIComponent(text)}`;
|
||||
}
|
||||
+32
-3
@@ -1,5 +1,5 @@
|
||||
import type { MetadataRoute } from 'next';
|
||||
import type { CategoryType, PostType } from './types/types';
|
||||
import type { CategoryType, PostType, TagType } from './types/types';
|
||||
|
||||
export const dynamic = 'force-dynamic';
|
||||
|
||||
@@ -11,6 +11,7 @@ const PER_PAGE = 50;
|
||||
// Upper bound on pagination so a huge blog cannot stall the sitemap.
|
||||
const MAX_POST_PAGES = 20;
|
||||
const MAX_CATEGORY_PAGES = 4;
|
||||
const MAX_TAG_PAGES = 4;
|
||||
|
||||
type Paginated<T> = {
|
||||
data?: T[];
|
||||
@@ -23,6 +24,7 @@ type Paginated<T> = {
|
||||
|
||||
type SitemapPost = Pick<PostType, 'slug' | 'updated_at' | 'published_at'>;
|
||||
type SitemapCategory = Pick<CategoryType, 'slug' | 'updated_at'>;
|
||||
type SitemapTag = Pick<TagType, 'slug'>;
|
||||
|
||||
function absoluteUrl(path: string): string {
|
||||
return `${FRONT_URL}${path}`;
|
||||
@@ -108,6 +110,24 @@ export default async function sitemap(): Promise<MetadataRoute.Sitemap> {
|
||||
changeFrequency: 'weekly',
|
||||
priority: 0.7,
|
||||
},
|
||||
{
|
||||
url: absoluteUrl('/blog/filtered-posts/new'),
|
||||
lastModified: now,
|
||||
changeFrequency: 'daily',
|
||||
priority: 0.6,
|
||||
},
|
||||
{
|
||||
url: absoluteUrl('/blog/filtered-posts/popular'),
|
||||
lastModified: now,
|
||||
changeFrequency: 'daily',
|
||||
priority: 0.6,
|
||||
},
|
||||
{
|
||||
url: absoluteUrl('/blog/posts'),
|
||||
lastModified: now,
|
||||
changeFrequency: 'daily',
|
||||
priority: 0.6,
|
||||
},
|
||||
{
|
||||
url: absoluteUrl('/projects'),
|
||||
lastModified: now,
|
||||
@@ -117,9 +137,10 @@ export default async function sitemap(): Promise<MetadataRoute.Sitemap> {
|
||||
];
|
||||
|
||||
try {
|
||||
const [posts, categories] = await Promise.all([
|
||||
const [posts, categories, tags] = await Promise.all([
|
||||
fetchAllPages<SitemapPost>('/posts', MAX_POST_PAGES),
|
||||
fetchAllPages<SitemapCategory>('/categories', MAX_CATEGORY_PAGES),
|
||||
fetchAllPages<SitemapTag>('/tags', MAX_TAG_PAGES),
|
||||
]);
|
||||
|
||||
const postRoutes: MetadataRoute.Sitemap = posts
|
||||
@@ -143,7 +164,15 @@ export default async function sitemap(): Promise<MetadataRoute.Sitemap> {
|
||||
priority: 0.6,
|
||||
}));
|
||||
|
||||
return [...staticRoutes, ...postRoutes, ...categoryRoutes];
|
||||
const tagRoutes: MetadataRoute.Sitemap = tags
|
||||
.filter((tag) => typeof tag?.slug === 'string' && tag.slug.trim() !== '')
|
||||
.map((tag) => ({
|
||||
url: absoluteUrl(`/blog/tags/${tag.slug}`),
|
||||
changeFrequency: 'weekly',
|
||||
priority: 0.5,
|
||||
}));
|
||||
|
||||
return [...staticRoutes, ...postRoutes, ...categoryRoutes, ...tagRoutes];
|
||||
} catch {
|
||||
// A sitemap must never take the site down: fall back to static routes only.
|
||||
return staticRoutes;
|
||||
|
||||
@@ -78,6 +78,18 @@ export type CategoryDataType = {
|
||||
links: LinksType;
|
||||
};
|
||||
|
||||
export type tagSlugPropsType = {
|
||||
params: { slug: string };
|
||||
searchParams: SearchParams;
|
||||
};
|
||||
|
||||
export type TagDataType = {
|
||||
tag: TagType;
|
||||
posts: PostType[];
|
||||
meta: MetaType;
|
||||
links: LinksType;
|
||||
};
|
||||
|
||||
export type FilteredPostsPagepropsType = {
|
||||
params: { filter: string };
|
||||
searchParams: SearchParams;
|
||||
|
||||
Reference in new issue
Block a user