Make the site crawlable and describe itself properly

public/robots.txt was "Disallow: /", which told every crawler to ignore the
entire site. It now allows crawling, keeps /admin and the API paths out of the
index, and points at the sitemap.

Add a generated sitemap covering the static routes plus every post and
category. The API caps per_page at 50, so it follows meta.last_page instead of
asking for more, and every fetch is wrapped so an unreachable API degrades to
the static entries rather than taking the site down.

Replace the placeholder layout metadata with real Persian titles, description,
keywords, canonical URL, hreflang alternates, OpenGraph and Twitter cards, and
add Person/WebSite JSON-LD.
This commit is contained in:
root committed 2026-10-01 16:33:19 -04:00
1 parent a3cce41d1e
commit cc7a5f2b7c
3 files changed
+288 -8

No files matched your search

+12 -1
View File
@@ -1,2 +1,13 @@
User-agent: *
Disallow: /
Allow: /
# Admin panel: no indexing, no crawling of the panel or its assets.
Disallow: /admin
Disallow: /admin/
Disallow: /admin/*
# Internal helpers that should never appear in search results.
Disallow: /og-image
Disallow: /api/
Sitemap: https://parsaaghayi.ir/sitemap.xml
+125 -7
View File
@@ -3,22 +3,125 @@ import Header from "./components/header/header";
import Footer from "./components/footer/footer";
import NextTopLoader from "nextjs-toploader";
const SITE_URL = (
process.env.NEXT_PUBLIC_FRONT_URL || "https://parsaaghayi.ir"
).replace(/\/+$/, "");
const SITE_NAME = "پارسا آقایی";
const SITE_NAME_EN = "Parsa Aghayi";
const DESCRIPTION =
"وب‌سایت شخصی پارسا آقایی، توسعه‌دهنده ارشد فرانت‌اند و معمار وب. مقالات تخصصی در حوزه React، Next.js، TypeScript، بهینه‌سازی سرعت و معماری نرم‌افزار، به‌همراه معرفی خدمات و پروژه‌ها.";
const KEYWORDS = [
"پارسا آقایی",
"پارسا آقایی وب سایت",
"توسعه دهنده فرانت اند",
"برنامه نویسی وب",
"React",
"Next.js",
"TypeScript",
"JavaScript",
"معماری وب",
"بهینه سازی سرعت سایت",
"طراحی رابط کاربری",
"وبلاگ برنامه نویسی",
"توسعه وب فارسی",
];
export const metadata: Metadata = {
metadataBase: new URL(SITE_URL),
title: {
template: "%s | parsa aghayi",
default: "parsa aghayi",
template: `%s | ${SITE_NAME}`,
default: `${SITE_NAME} | توسعه‌دهنده فرانت‌اند و معمار وب`,
},
description: DESCRIPTION,
applicationName: SITE_NAME,
keywords: KEYWORDS,
authors: [
{
name: SITE_NAME,
url: SITE_URL,
},
],
creator: SITE_NAME,
publisher: SITE_NAME,
alternates: {
canonical: "./",
languages: {
fa: "./",
en: "./",
"x-default": "./",
},
},
description: "parsa aghayi personal website",
openGraph: {
title: {
template: "%s | parsa aghayi",
default: "parsa aghayi",
template: `%s | ${SITE_NAME}`,
default: `${SITE_NAME} | توسعه‌دهنده فرانت‌اند و معمار وب`,
},
description: "parsa aghayi's personal website",
description: DESCRIPTION,
type: "website",
locale: "fa_IR",
alternateLocale: ["en_US"],
url: SITE_URL,
siteName: SITE_NAME,
images: [
`${process.env.NEXT_PUBLIC_FRONT_URL}/og-image?text=parsa aghayi's personal website`,
{
url: `${SITE_URL}/og-image?text=${encodeURIComponent(SITE_NAME)}`,
width: 1200,
height: 1200,
alt: SITE_NAME,
},
],
},
twitter: {
card: "summary_large_image",
title: `${SITE_NAME} | توسعه‌دهنده فرانت‌اند و معمار وب`,
description: DESCRIPTION,
images: [
`${SITE_URL}/og-image?text=${encodeURIComponent(SITE_NAME)}`,
],
},
};
const PERSON_JSON_LD = {
"@context": "https://schema.org",
"@type": "Person",
name: SITE_NAME,
alternateName: SITE_NAME_EN,
jobTitle: "Senior Frontend Engineer & Web Architect",
description: DESCRIPTION,
url: SITE_URL,
email: "mailto:ceo@parsaaghayi.ir",
knowsAbout: [
"React",
"Next.js",
"TypeScript",
"JavaScript",
"Web Performance",
"Software Architecture",
"UI/UX",
],
};
const WEBSITE_JSON_LD = {
"@context": "https://schema.org",
"@type": "WebSite",
name: SITE_NAME,
alternateName: SITE_NAME_EN,
url: SITE_URL,
inLanguage: ["fa", "en"],
publisher: {
"@id": `${SITE_URL}/#person`,
},
potentialAction: {
"@type": "SearchAction",
target: {
"@type": "EntryPoint",
urlTemplate: `${SITE_URL}/blog/filtered-posts/new?search={search_term_string}`,
},
"query-input": "required name=search_term_string",
},
};
export default function RootLayout({
@@ -34,6 +137,21 @@ export default function RootLayout({
type="image/ico"
sizes="32x32"
/>
{/* JSON-LD must be delivered as a script tag, so dangerouslySetInnerHTML is
required here. The payload is fully static (site config + env URLs), never
user input, so there is no injection risk. */}
<script
type="application/ld+json"
dangerouslySetInnerHTML={{
__html: JSON.stringify({
"@context": "https://schema.org",
"@graph": [
{ ...PERSON_JSON_LD, "@id": `${SITE_URL}/#person` },
WEBSITE_JSON_LD,
],
}),
}}
/>
<div className="scroll-watcher" id="top"></div>
<div className="absolute start-0 top-0 opacity-0" id="here-is-top"></div>
<Header />
+151
View File
@@ -0,0 +1,151 @@
import type { MetadataRoute } from 'next';
import type { CategoryType, PostType } from './types/types';
export const dynamic = 'force-dynamic';
const FRONT_URL = (process.env.NEXT_PUBLIC_FRONT_URL || 'https://parsaaghayi.ir').replace(/\/+$/, '');
const BLOG_API_URL = (process.env.NEXT_PUBLIC_BLOG_API_URL || 'https://backend.parsaaghayi.ir/api/blog').replace(/\/+$/, '');
// The blog API rejects `per_page` values above 50.
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;
type Paginated<T> = {
data?: T[];
meta?: {
total?: number;
current_page?: number;
last_page?: number;
};
};
type SitemapPost = Pick<PostType, 'slug' | 'updated_at' | 'published_at'>;
type SitemapCategory = Pick<CategoryType, 'slug' | 'updated_at'>;
function absoluteUrl(path: string): string {
return `${FRONT_URL}${path}`;
}
function parseDate(...candidates: (string | null | undefined)[]): Date | undefined {
for (const candidate of candidates) {
if (typeof candidate !== 'string' || candidate.trim() === '') {
continue;
}
const parsed = new Date(candidate.trim());
if (!Number.isNaN(parsed.getTime())) {
return parsed;
}
}
return undefined;
}
async function fetchJson<T>(url: string): Promise<T | null> {
try {
const response = await fetch(url, { cache: 'no-store' });
if (!response.ok) {
return null;
}
return (await response.json()) as T;
} catch {
return null;
}
}
async function fetchAllPages<T>(
path: string,
maxPages: number,
): Promise<T[]> {
const items: T[] = [];
for (let page = 1; page <= maxPages; page += 1) {
const payload = await fetchJson<Paginated<T>>(
`${BLOG_API_URL}${path}?per_page=${PER_PAGE}&page=${page}`,
);
if (!payload || !Array.isArray(payload.data) || payload.data.length === 0) {
break;
}
items.push(...payload.data);
const lastPage = payload.meta?.last_page ?? 1;
const currentPage = payload.meta?.current_page ?? page;
if (currentPage >= lastPage) {
break;
}
}
return items;
}
export default async function sitemap(): Promise<MetadataRoute.Sitemap> {
const now = new Date();
const staticRoutes: MetadataRoute.Sitemap = [
{
url: absoluteUrl('/'),
lastModified: now,
changeFrequency: 'weekly',
priority: 1,
},
{
url: absoluteUrl('/blog'),
lastModified: now,
changeFrequency: 'daily',
priority: 0.9,
},
{
url: absoluteUrl('/blog/categories'),
lastModified: now,
changeFrequency: 'weekly',
priority: 0.7,
},
{
url: absoluteUrl('/projects'),
lastModified: now,
changeFrequency: 'monthly',
priority: 0.7,
},
];
try {
const [posts, categories] = await Promise.all([
fetchAllPages<SitemapPost>('/posts', MAX_POST_PAGES),
fetchAllPages<SitemapCategory>('/categories', MAX_CATEGORY_PAGES),
]);
const postRoutes: MetadataRoute.Sitemap = posts
.filter((post) => typeof post?.slug === 'string' && post.slug.trim() !== '')
.map((post) => ({
url: absoluteUrl(`/blog/posts/${post.slug}`),
lastModified: parseDate(post.updated_at, post.published_at) ?? now,
changeFrequency: 'monthly',
priority: 0.8,
}));
const categoryRoutes: MetadataRoute.Sitemap = categories
.filter(
(category) =>
typeof category?.slug === 'string' && category.slug.trim() !== '',
)
.map((category) => ({
url: absoluteUrl(`/blog/categories/${category.slug}`),
lastModified: parseDate(category.updated_at) ?? now,
changeFrequency: 'weekly',
priority: 0.6,
}));
return [...staticRoutes, ...postRoutes, ...categoryRoutes];
} catch {
// A sitemap must never take the site down: fall back to static routes only.
return staticRoutes;
}
}