Remove unused redirects from the Next.js configuration and update package dependencies to include new Tiptap extensions for enhanced text editing capabilities. Clean up the database seeding script by removing commented-out code and ensuring proper deletion of obsolete entries. Update various pages to handle not found scenarios gracefully, improving user experience across the application.
This commit is contained in:
1 parent
4b84409ed7
commit
2858b9c746
106 files changed
+2516
-1004
No files matched your search
@@ -43,7 +43,7 @@ export default async function LegalSlugPage({ params }: Props) {
|
||||
<Container className="grid gap-10 lg:grid-cols-[minmax(0,1fr)_minmax(0,1.2fr)] lg:items-start">
|
||||
<div className="min-w-0 space-y-5">
|
||||
{page.body.map((paragraph) => (
|
||||
<p key={paragraph} className="text-base leading-8 text-foreground/90">
|
||||
<p key={paragraph} className="text-justify text-base leading-8 text-foreground/90">
|
||||
{paragraph}
|
||||
</p>
|
||||
))}
|
||||
|
||||
@@ -1,69 +1,5 @@
|
||||
import type { Metadata } from "next";
|
||||
import { getTranslations } from "next-intl/server";
|
||||
import { CmsImage } from "@/components/atoms/CmsImage";
|
||||
import { Container } from "@/components/atoms/Container";
|
||||
import { Heading } from "@/components/atoms/Heading";
|
||||
import { Section } from "@/components/atoms/Section";
|
||||
import { BadgeLabel } from "@/components/atoms/BadgeLabel";
|
||||
import { PageHero } from "@/components/molecules/PageHero";
|
||||
import { SurfaceCard } from "@/components/molecules/SurfaceCard";
|
||||
import { getAlumniStories } from "@/lib/data/site";
|
||||
import { pageMetadata } from "@/lib/seo/metadata";
|
||||
import { notFound } from "next/navigation";
|
||||
|
||||
export async function generateMetadata(): Promise<Metadata> {
|
||||
const t = await getTranslations("pages");
|
||||
return pageMetadata({
|
||||
title: t("alumniTitle"),
|
||||
description: t("alumniIntro"),
|
||||
path: "/alumni",
|
||||
});
|
||||
}
|
||||
|
||||
export default async function AlumniPage() {
|
||||
const t = await getTranslations("pages");
|
||||
const stories = await getAlumniStories();
|
||||
|
||||
return (
|
||||
<main id="main-content">
|
||||
<PageHero
|
||||
title={t("alumniTitle")}
|
||||
intro={t("alumniIntro")}
|
||||
imageUrl="/brand/graduation-cap-neural.webp"
|
||||
/>
|
||||
<Section tone="subtle">
|
||||
<Container>
|
||||
<div className="grid gap-5 md:grid-cols-3">
|
||||
{stories.map((story) => (
|
||||
<SurfaceCard
|
||||
key={story.id}
|
||||
id={story.id}
|
||||
padded={false}
|
||||
className="scroll-mt-24"
|
||||
>
|
||||
<div className="relative aspect-[16/10] bg-muted">
|
||||
<CmsImage
|
||||
src={story.imageUrl}
|
||||
alt={story.name}
|
||||
fill
|
||||
className="object-cover"
|
||||
sizes="(max-width:768px) 100vw, 33vw"
|
||||
/>
|
||||
</div>
|
||||
<div className="p-6">
|
||||
<BadgeLabel>{story.program}</BadgeLabel>
|
||||
<Heading as="h2" level={4} className="mt-3">
|
||||
{story.title}
|
||||
</Heading>
|
||||
<p className="mt-2 text-sm leading-7 text-muted-foreground">
|
||||
{story.excerpt}
|
||||
</p>
|
||||
<p className="mt-4 text-sm font-semibold">{story.name}</p>
|
||||
</div>
|
||||
</SurfaceCard>
|
||||
))}
|
||||
</div>
|
||||
</Container>
|
||||
</Section>
|
||||
</main>
|
||||
);
|
||||
export default function AlumniPage() {
|
||||
notFound();
|
||||
}
|
||||
@@ -1,90 +1,5 @@
|
||||
import type { Metadata } from "next";
|
||||
import { notFound } from "next/navigation";
|
||||
import { CalendarDays, MapPin } from "lucide-react";
|
||||
import { Container } from "@/components/atoms/Container";
|
||||
import { Heading } from "@/components/atoms/Heading";
|
||||
import { Section } from "@/components/atoms/Section";
|
||||
import { TextLink } from "@/components/atoms/TextLink";
|
||||
import { DetailList } from "@/components/molecules/DetailList";
|
||||
import { PageHero } from "@/components/molecules/PageHero";
|
||||
import { SurfaceCard } from "@/components/molecules/SurfaceCard";
|
||||
import { getEventById } from "@/lib/data/events";
|
||||
import { JsonLd } from "@/lib/seo/json-ld";
|
||||
import {
|
||||
absoluteUrl,
|
||||
pageMetadata,
|
||||
truncateMetaDescription,
|
||||
} from "@/lib/seo/metadata";
|
||||
|
||||
type Props = { params: Promise<{ id: string }> };
|
||||
|
||||
const dateFormat: Intl.DateTimeFormatOptions = {
|
||||
year: "numeric",
|
||||
month: "long",
|
||||
day: "numeric",
|
||||
};
|
||||
|
||||
export async function generateMetadata({ params }: Props): Promise<Metadata> {
|
||||
const { id } = await params;
|
||||
const event = await getEventById(id);
|
||||
if (!event) return { title: "رویداد یافت نشد" };
|
||||
return pageMetadata({
|
||||
title: event.title,
|
||||
description: truncateMetaDescription(event.summary),
|
||||
path: `/events/${id}`,
|
||||
});
|
||||
}
|
||||
|
||||
export default async function EventDetailPage({ params }: Props) {
|
||||
const { id } = await params;
|
||||
const event = await getEventById(id);
|
||||
if (!event) notFound();
|
||||
|
||||
const start = new Date(event.startDate).toLocaleDateString("fa-IR", dateFormat);
|
||||
const end = event.endDate
|
||||
? new Date(event.endDate).toLocaleDateString("fa-IR", dateFormat)
|
||||
: null;
|
||||
|
||||
return (
|
||||
<main id="main-content">
|
||||
<JsonLd
|
||||
data={{
|
||||
"@context": "https://schema.org",
|
||||
"@type": "Event",
|
||||
name: event.title,
|
||||
description: event.summary,
|
||||
startDate: event.startDate,
|
||||
...(event.endDate ? { endDate: event.endDate } : {}),
|
||||
location: { "@type": "Place", name: event.location },
|
||||
url: absoluteUrl(`/events/${id}`),
|
||||
}}
|
||||
/>
|
||||
<PageHero title={event.title} intro={event.summary} />
|
||||
<Section tone="subtle">
|
||||
<Container narrow className="space-y-6">
|
||||
<SurfaceCard padded as="div">
|
||||
<DetailList
|
||||
items={[
|
||||
{
|
||||
icon: CalendarDays,
|
||||
label: "زمان",
|
||||
value: end ? `${start} تا ${end}` : start,
|
||||
},
|
||||
{ icon: MapPin, label: "مکان", value: event.location },
|
||||
]}
|
||||
/>
|
||||
</SurfaceCard>
|
||||
<section className="space-y-4">
|
||||
<Heading level={3} as="h2">
|
||||
درباره رویداد
|
||||
</Heading>
|
||||
<p className="text-base leading-8 text-foreground/90">{event.summary}</p>
|
||||
</section>
|
||||
<TextLink href="/events" className="inline-block text-sm">
|
||||
بازگشت به رویدادها
|
||||
</TextLink>
|
||||
</Container>
|
||||
</Section>
|
||||
</main>
|
||||
);
|
||||
export default function EventDetailPage() {
|
||||
notFound();
|
||||
}
|
||||
@@ -1,37 +1,5 @@
|
||||
import type { Metadata } from "next";
|
||||
import { getTranslations } from "next-intl/server";
|
||||
import { Container } from "@/components/atoms/Container";
|
||||
import { Section } from "@/components/atoms/Section";
|
||||
import { EventCard } from "@/components/molecules/Cards";
|
||||
import { PageHero } from "@/components/molecules/PageHero";
|
||||
import { getEvents } from "@/lib/data/events";
|
||||
import { pageMetadata } from "@/lib/seo/metadata";
|
||||
import { notFound } from "next/navigation";
|
||||
|
||||
export async function generateMetadata(): Promise<Metadata> {
|
||||
const t = await getTranslations("pages");
|
||||
return pageMetadata({
|
||||
title: t("eventsTitle"),
|
||||
description: t("eventsIntro"),
|
||||
path: "/events",
|
||||
});
|
||||
}
|
||||
|
||||
export default async function EventsPage() {
|
||||
const t = await getTranslations("pages");
|
||||
const events = await getEvents();
|
||||
|
||||
return (
|
||||
<main id="main-content">
|
||||
<PageHero title={t("eventsTitle")} intro={t("eventsIntro")} />
|
||||
<Section tone="subtle">
|
||||
<Container>
|
||||
<div className="grid gap-4 md:grid-cols-2">
|
||||
{events.map((event) => (
|
||||
<EventCard key={event.id} {...event} variant="list" />
|
||||
))}
|
||||
</div>
|
||||
</Container>
|
||||
</Section>
|
||||
</main>
|
||||
);
|
||||
export default function EventsPage() {
|
||||
notFound();
|
||||
}
|
||||
@@ -1,6 +1,5 @@
|
||||
import { redirect } from "next/navigation";
|
||||
import { notFound } from "next/navigation";
|
||||
|
||||
/** Faculty are not introduced on this site; send visitors home. */
|
||||
export default function FacultyPage() {
|
||||
redirect("/");
|
||||
notFound();
|
||||
}
|
||||
@@ -1,78 +1,5 @@
|
||||
import type { Metadata } from "next";
|
||||
import { notFound } from "next/navigation";
|
||||
import { CmsImage } from "@/components/atoms/CmsImage";
|
||||
import { Container } from "@/components/atoms/Container";
|
||||
import { Section } from "@/components/atoms/Section";
|
||||
import { TextLink } from "@/components/atoms/TextLink";
|
||||
import { PageHero } from "@/components/molecules/PageHero";
|
||||
import { getArticleById } from "@/lib/data/articles";
|
||||
import { JsonLd } from "@/lib/seo/json-ld";
|
||||
import {
|
||||
absoluteUrl,
|
||||
pageMetadata,
|
||||
truncateMetaDescription,
|
||||
} from "@/lib/seo/metadata";
|
||||
|
||||
type Props = { params: Promise<{ id: string }> };
|
||||
|
||||
export async function generateMetadata({ params }: Props): Promise<Metadata> {
|
||||
const { id } = await params;
|
||||
const article = await getArticleById(id);
|
||||
if (!article) return { title: "مقاله یافت نشد" };
|
||||
return pageMetadata({
|
||||
title: article.title,
|
||||
description: truncateMetaDescription(article.excerpt),
|
||||
path: `/insights/${id}`,
|
||||
image: article.imageUrl,
|
||||
});
|
||||
}
|
||||
|
||||
export default async function InsightDetailPage({ params }: Props) {
|
||||
const { id } = await params;
|
||||
const article = await getArticleById(id);
|
||||
if (!article) notFound();
|
||||
|
||||
const date = new Date(article.publishedAt).toLocaleDateString("fa-IR");
|
||||
|
||||
return (
|
||||
<main id="main-content">
|
||||
<JsonLd
|
||||
data={{
|
||||
"@context": "https://schema.org",
|
||||
"@type": "Article",
|
||||
headline: article.title,
|
||||
description: article.excerpt,
|
||||
datePublished: article.publishedAt,
|
||||
author: { "@type": "Person", name: article.author },
|
||||
image: article.imageUrl,
|
||||
url: absoluteUrl(`/insights/${id}`),
|
||||
}}
|
||||
/>
|
||||
<PageHero
|
||||
eyebrow={article.category}
|
||||
title={article.title}
|
||||
intro={`${article.author} · ${date}`}
|
||||
/>
|
||||
<Section tone="subtle">
|
||||
<Container narrow>
|
||||
<div className="relative mb-10 aspect-[16/9] overflow-hidden rounded-2xl bg-muted ring-1 ring-foreground/10">
|
||||
<CmsImage
|
||||
src={article.imageUrl}
|
||||
alt={article.title}
|
||||
fill
|
||||
className="object-cover"
|
||||
sizes="(max-width:768px) 100vw, 800px"
|
||||
priority
|
||||
/>
|
||||
</div>
|
||||
<p className="text-base leading-8 text-foreground/90 sm:text-lg sm:leading-9">
|
||||
{article.body}
|
||||
</p>
|
||||
<TextLink href="/insights" className="mt-10 inline-block text-sm">
|
||||
بازگشت به مقالات
|
||||
</TextLink>
|
||||
</Container>
|
||||
</Section>
|
||||
</main>
|
||||
);
|
||||
export default function InsightArticlePage() {
|
||||
notFound();
|
||||
}
|
||||
@@ -1,49 +1,5 @@
|
||||
import type { Metadata } from "next";
|
||||
import { getTranslations } from "next-intl/server";
|
||||
import { Container } from "@/components/atoms/Container";
|
||||
import { Section } from "@/components/atoms/Section";
|
||||
import { ArticleCard } from "@/components/molecules/Cards";
|
||||
import { PageHero } from "@/components/molecules/PageHero";
|
||||
import { getArticles } from "@/lib/data/articles";
|
||||
import { pageMetadata } from "@/lib/seo/metadata";
|
||||
import { notFound } from "next/navigation";
|
||||
|
||||
export async function generateMetadata(): Promise<Metadata> {
|
||||
const t = await getTranslations("pages");
|
||||
return pageMetadata({
|
||||
title: t("insightsTitle"),
|
||||
description: t("insightsIntro"),
|
||||
path: "/insights",
|
||||
});
|
||||
}
|
||||
|
||||
export default async function InsightsPage() {
|
||||
const t = await getTranslations("pages");
|
||||
const articles = await getArticles();
|
||||
|
||||
return (
|
||||
<main id="main-content">
|
||||
<PageHero
|
||||
title={t("insightsTitle")}
|
||||
intro={t("insightsIntro")}
|
||||
imageUrl="/brand/neural-open-book.webp"
|
||||
/>
|
||||
<Section tone="subtle">
|
||||
<Container>
|
||||
<div className="mx-auto max-w-5xl">
|
||||
{articles.map((article) => (
|
||||
<ArticleCard
|
||||
key={article.id}
|
||||
title={article.title}
|
||||
category={article.category}
|
||||
excerpt={article.excerpt}
|
||||
imageUrl={article.imageUrl}
|
||||
href={article.href}
|
||||
variant="list"
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
</Container>
|
||||
</Section>
|
||||
</main>
|
||||
);
|
||||
export default function InsightsPage() {
|
||||
notFound();
|
||||
}
|
||||
@@ -5,9 +5,12 @@ import { SiteHeader } from "@/components/organisms/SiteHeader";
|
||||
import { buildHomeNavWithCourseTags } from "@/lib/course-nav";
|
||||
import { getCourses } from "@/lib/data/courses";
|
||||
import { listPublishedCourseTags } from "@/lib/data/taxonomy";
|
||||
import { getPrograms } from "@/lib/data/programs";
|
||||
import { getCampaignBanners } from "@/lib/data/site";
|
||||
import { facultySiteUrl, siteShortName } from "@/lib/site-config";
|
||||
import {
|
||||
facultyNetworkUrl,
|
||||
facultySiteUrl,
|
||||
siteShortName,
|
||||
} from "@/lib/site-config";
|
||||
|
||||
// Public CMS pages must read Postgres at request time — static bake at Docker
|
||||
// build often has no DATABASE_URL and ships empty lists.
|
||||
@@ -21,13 +24,11 @@ export default async function MainLayout({
|
||||
const t = await getTranslations();
|
||||
const year = new Date().getFullYear();
|
||||
let courses: Awaited<ReturnType<typeof getCourses>> = [];
|
||||
let programs: Awaited<ReturnType<typeof getPrograms>> = [];
|
||||
let banners: Awaited<ReturnType<typeof getCampaignBanners>> = [];
|
||||
let navTags: Awaited<ReturnType<typeof listPublishedCourseTags>> = [];
|
||||
try {
|
||||
[courses, programs, banners, navTags] = await Promise.all([
|
||||
[courses, banners, navTags] = await Promise.all([
|
||||
getCourses(),
|
||||
getPrograms(),
|
||||
getCampaignBanners(),
|
||||
listPublishedCourseTags({ navOnly: true }),
|
||||
]);
|
||||
@@ -47,7 +48,6 @@ export default async function MainLayout({
|
||||
brandSubtitle={t("nav.brandSubtitle")}
|
||||
variant="home"
|
||||
courses={courses}
|
||||
programs={programs}
|
||||
/>
|
||||
<CampaignBanners banners={banners} />
|
||||
<div className="min-w-0 flex-1 overflow-x-clip">{children}</div>
|
||||
@@ -56,6 +56,7 @@ export default async function MainLayout({
|
||||
linksTitle={t("footer.links")}
|
||||
links={[
|
||||
{ label: t("footer.facultySite"), href: facultySiteUrl },
|
||||
{ label: t("footer.facultyNetwork"), href: facultyNetworkUrl },
|
||||
{ label: t("footer.press"), href: "/press" },
|
||||
{ label: t("footer.careers"), href: "/careers" },
|
||||
]}
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
import type { Metadata } from "next";
|
||||
import { notFound } from "next/navigation";
|
||||
import { NewsDetailTemplate } from "@/components/templates/NewsDetailTemplate";
|
||||
import { getNewsById, newsExcerpt } from "@/lib/data/news";
|
||||
import { pageMetadata } from "@/lib/seo/metadata";
|
||||
|
||||
export async function generateMetadata({
|
||||
params,
|
||||
}: {
|
||||
params: Promise<{ id: string }>;
|
||||
}): Promise<Metadata> {
|
||||
const { id } = await params;
|
||||
const item = await getNewsById(id);
|
||||
if (!item) {
|
||||
return pageMetadata({
|
||||
title: "خبر",
|
||||
description: "خبر مرکز آموزش های آزاد",
|
||||
path: `/news/${id}`,
|
||||
});
|
||||
}
|
||||
return pageMetadata({
|
||||
title: item.title,
|
||||
description: newsExcerpt(item.body),
|
||||
path: `/news/${item.id}`,
|
||||
image: item.bannerImageUrl,
|
||||
});
|
||||
}
|
||||
|
||||
export default async function NewsDetailPage({
|
||||
params,
|
||||
}: {
|
||||
params: Promise<{ id: string }>;
|
||||
}) {
|
||||
const { id } = await params;
|
||||
const item = await getNewsById(id);
|
||||
if (!item) notFound();
|
||||
|
||||
return (
|
||||
<main id="main-content">
|
||||
<NewsDetailTemplate item={item} />
|
||||
</main>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
import type { Metadata } from "next";
|
||||
import { getTranslations } from "next-intl/server";
|
||||
import { NewsListTemplate } from "@/components/templates/NewsListTemplate";
|
||||
import { getNews } from "@/lib/data/news";
|
||||
import { pageMetadata } from "@/lib/seo/metadata";
|
||||
|
||||
export async function generateMetadata(): Promise<Metadata> {
|
||||
const t = await getTranslations("pages");
|
||||
return pageMetadata({
|
||||
title: t("newsTitle"),
|
||||
description: t("newsIntro"),
|
||||
path: "/news",
|
||||
});
|
||||
}
|
||||
|
||||
export default async function NewsPage() {
|
||||
const [t, items] = await Promise.all([getTranslations("pages"), getNews()]);
|
||||
|
||||
return (
|
||||
<main id="main-content">
|
||||
<NewsListTemplate
|
||||
items={items}
|
||||
title={t("newsTitle")}
|
||||
intro={t("newsIntro")}
|
||||
emptyLabel={t("newsEmpty")}
|
||||
/>
|
||||
</main>
|
||||
);
|
||||
}
|
||||
@@ -5,13 +5,11 @@ import {
|
||||
HomeApproach,
|
||||
HomeClosing,
|
||||
HomeCourseSearch,
|
||||
HomeEventsTeaser,
|
||||
HomeHero,
|
||||
HomeIdeas,
|
||||
HomeTeams,
|
||||
type HomeLabels,
|
||||
} from "@/components/templates/HomeTemplate";
|
||||
import { getFeaturedArticle } from "@/lib/data/articles";
|
||||
import { getLatestCourses } from "@/lib/data/courses";
|
||||
|
||||
export async function generateMetadata(): Promise<Metadata> {
|
||||
@@ -46,11 +44,8 @@ async function orFallback<T>(
|
||||
}
|
||||
|
||||
async function HeroSection() {
|
||||
const [featured, labels] = await Promise.all([
|
||||
orFallback("featured article", getFeaturedArticle, null),
|
||||
getLabels(),
|
||||
]);
|
||||
return <HomeHero featured={featured} eyebrow={labels.ideasEyebrow} />;
|
||||
const labels = await getLabels();
|
||||
return <HomeHero featured={null} eyebrow={labels.ideasEyebrow} />;
|
||||
}
|
||||
|
||||
async function CourseSearchSection() {
|
||||
@@ -76,7 +71,6 @@ export default function HomePage() {
|
||||
<HomeIdeas />
|
||||
<CourseSearchSection />
|
||||
<HomeApproach />
|
||||
<HomeEventsTeaser />
|
||||
<HomeTeams />
|
||||
<HomeClosing />
|
||||
</main>
|
||||
|
||||
@@ -1,115 +1,5 @@
|
||||
import type { Metadata } from "next";
|
||||
import Link from "next/link";
|
||||
import { notFound } from "next/navigation";
|
||||
import { getTranslations } from "next-intl/server";
|
||||
import { Container } from "@/components/atoms/Container";
|
||||
import { Heading } from "@/components/atoms/Heading";
|
||||
import { Section } from "@/components/atoms/Section";
|
||||
import { TextLink } from "@/components/atoms/TextLink";
|
||||
import { CheckList } from "@/components/molecules/CheckList";
|
||||
import { DetailList } from "@/components/molecules/DetailList";
|
||||
import { PageHero } from "@/components/molecules/PageHero";
|
||||
import { SectionHeader } from "@/components/molecules/SectionHeader";
|
||||
import { SurfaceCard } from "@/components/molecules/SurfaceCard";
|
||||
import { buttonVariants } from "@/components/ui/button";
|
||||
import { cn } from "@/lib/utils";
|
||||
import { getCourses } from "@/lib/data/courses";
|
||||
import { getProgramBySlug } from "@/lib/data/programs";
|
||||
import { pageMetadata, truncateMetaDescription } from "@/lib/seo/metadata";
|
||||
|
||||
type Props = { params: Promise<{ slug: string }> };
|
||||
|
||||
export async function generateMetadata({ params }: Props): Promise<Metadata> {
|
||||
const { slug } = await params;
|
||||
const program = await getProgramBySlug(slug);
|
||||
if (!program) return { title: "برنامه یافت نشد" };
|
||||
return pageMetadata({
|
||||
title: program.title,
|
||||
description: truncateMetaDescription(program.blurb),
|
||||
path: `/programs/${slug}`,
|
||||
});
|
||||
}
|
||||
|
||||
export default async function ProgramDetailPage({ params }: Props) {
|
||||
const { slug } = await params;
|
||||
const [program, courses, t] = await Promise.all([
|
||||
getProgramBySlug(slug),
|
||||
getCourses(),
|
||||
getTranslations("pages"),
|
||||
]);
|
||||
if (!program) notFound();
|
||||
|
||||
const related = courses.slice(0, 3);
|
||||
|
||||
return (
|
||||
<main id="main-content">
|
||||
<PageHero
|
||||
title={program.title}
|
||||
intro={program.blurb}
|
||||
eyebrow={program.tagline}
|
||||
/>
|
||||
<Section tone="subtle">
|
||||
<Container className="grid min-w-0 gap-10 lg:grid-cols-[minmax(0,1fr)_minmax(0,22rem)] lg:items-start lg:gap-12">
|
||||
<div className="min-w-0 space-y-10">
|
||||
<p className="text-base leading-8 text-foreground/90">{program.body}</p>
|
||||
{program.highlights.length > 0 ? (
|
||||
<section className="space-y-4">
|
||||
<Heading level={3} as="h2">
|
||||
{t("highlights")}
|
||||
</Heading>
|
||||
<CheckList items={program.highlights} />
|
||||
</section>
|
||||
) : null}
|
||||
</div>
|
||||
<aside className="min-w-0 space-y-4 lg:sticky lg:top-28">
|
||||
<SurfaceCard padded as="div">
|
||||
<DetailList
|
||||
items={[
|
||||
{ label: "مخاطب", value: program.audience },
|
||||
{ label: "مدت", value: program.durationLabel },
|
||||
{ label: "فرمت", value: program.formatLabel },
|
||||
]}
|
||||
/>
|
||||
<Link
|
||||
href="/professional"
|
||||
className={cn(buttonVariants({ size: "lg" }), "mt-6 w-full font-bold")}
|
||||
>
|
||||
مشاهده دوره ها
|
||||
</Link>
|
||||
</SurfaceCard>
|
||||
<TextLink href="/programs" className="block px-1 text-sm">
|
||||
{t("backToPrograms")}
|
||||
</TextLink>
|
||||
</aside>
|
||||
</Container>
|
||||
</Section>
|
||||
{related.length > 0 ? (
|
||||
<Section tone="muted">
|
||||
<Container>
|
||||
<SectionHeader title={t("relatedCourses")} />
|
||||
<ul className="grid gap-4 sm:grid-cols-3">
|
||||
{related.map((course) => (
|
||||
<li key={course.id}>
|
||||
<Link href={course.registrationUrl} className="group block h-full">
|
||||
<SurfaceCard padded as="div" interactive className="h-full">
|
||||
<Heading
|
||||
as="h3"
|
||||
level={4}
|
||||
className="transition-colors group-hover:text-accent"
|
||||
>
|
||||
{course.title}
|
||||
</Heading>
|
||||
<p className="mt-2 line-clamp-3 text-sm leading-7 text-muted-foreground">
|
||||
{course.summary}
|
||||
</p>
|
||||
</SurfaceCard>
|
||||
</Link>
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
</Container>
|
||||
</Section>
|
||||
) : null}
|
||||
</main>
|
||||
);
|
||||
export default function ProgramDetailPage() {
|
||||
notFound();
|
||||
}
|
||||
@@ -1,93 +1,5 @@
|
||||
import type { Metadata } from "next";
|
||||
import Link from "next/link";
|
||||
import { getTranslations } from "next-intl/server";
|
||||
import { Container } from "@/components/atoms/Container";
|
||||
import { Heading } from "@/components/atoms/Heading";
|
||||
import { Section } from "@/components/atoms/Section";
|
||||
import { BadgeLabel } from "@/components/atoms/BadgeLabel";
|
||||
import { DetailList } from "@/components/molecules/DetailList";
|
||||
import { PageHero } from "@/components/molecules/PageHero";
|
||||
import { SectionHeader } from "@/components/molecules/SectionHeader";
|
||||
import { SurfaceCard } from "@/components/molecules/SurfaceCard";
|
||||
import { buttonVariants } from "@/components/ui/button";
|
||||
import { cn } from "@/lib/utils";
|
||||
import { getPrograms } from "@/lib/data/programs";
|
||||
import { pageMetadata } from "@/lib/seo/metadata";
|
||||
import { notFound } from "next/navigation";
|
||||
|
||||
export async function generateMetadata(): Promise<Metadata> {
|
||||
const t = await getTranslations("pages");
|
||||
return pageMetadata({
|
||||
title: t("programsTitle"),
|
||||
description: t("programsIntro"),
|
||||
path: "/programs",
|
||||
});
|
||||
}
|
||||
|
||||
export default async function ProgramsPage() {
|
||||
const t = await getTranslations("pages");
|
||||
const programs = await getPrograms();
|
||||
const standard = programs.filter((p) => p.group === "standard");
|
||||
const executive = programs.filter((p) => p.group === "executive");
|
||||
|
||||
return (
|
||||
<main id="main-content">
|
||||
<PageHero
|
||||
title={t("programsTitle")}
|
||||
intro={t("programsIntro")}
|
||||
imageUrl="/brand/neural-tree-knowledge.webp"
|
||||
/>
|
||||
<Section tone="subtle">
|
||||
<Container className="space-y-16">
|
||||
<ProgramGroup title={t("standardGroup")} items={standard} />
|
||||
<ProgramGroup title={t("executiveGroup")} items={executive} />
|
||||
</Container>
|
||||
</Section>
|
||||
</main>
|
||||
);
|
||||
}
|
||||
|
||||
function ProgramGroup({
|
||||
title,
|
||||
items,
|
||||
}: {
|
||||
title: string;
|
||||
items: Awaited<ReturnType<typeof getPrograms>>;
|
||||
}) {
|
||||
if (items.length === 0) return null;
|
||||
return (
|
||||
<div>
|
||||
<SectionHeader title={title} className="mb-6 sm:mb-8" />
|
||||
<div className="grid gap-5 md:grid-cols-2">
|
||||
{items.map((program) => (
|
||||
<SurfaceCard key={program.id} padded className="flex flex-col">
|
||||
{program.tagline ? (
|
||||
<BadgeLabel className="w-fit">{program.tagline}</BadgeLabel>
|
||||
) : null}
|
||||
<Heading as="h3" level={3} className="mt-3">
|
||||
<Link href={program.href} className="transition-colors hover:text-accent">
|
||||
{program.title}
|
||||
</Link>
|
||||
</Heading>
|
||||
<p className="mt-2 flex-1 text-sm leading-7 text-muted-foreground">
|
||||
{program.blurb}
|
||||
</p>
|
||||
<DetailList
|
||||
className="mt-5 border-t border-border pt-4"
|
||||
items={[
|
||||
{ label: "مخاطب", value: program.audience },
|
||||
{ label: "مدت", value: program.durationLabel },
|
||||
{ label: "فرمت", value: program.formatLabel },
|
||||
]}
|
||||
/>
|
||||
<Link
|
||||
href={program.href}
|
||||
className={cn(buttonVariants({ variant: "outline" }), "mt-6 w-fit")}
|
||||
>
|
||||
جزئیات برنامه
|
||||
</Link>
|
||||
</SurfaceCard>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
export default function ProgramsPage() {
|
||||
notFound();
|
||||
}
|
||||
@@ -3,6 +3,7 @@ import { notFound } from "next/navigation";
|
||||
import { getTranslations } from "next-intl/server";
|
||||
import { CourseDetailTemplate } from "@/components/templates/CourseDetailTemplate";
|
||||
import { getCourseById } from "@/lib/data/courses";
|
||||
import { htmlToPlain } from "@/lib/html-text";
|
||||
import { pageMetadata, truncateMetaDescription } from "@/lib/seo/metadata";
|
||||
|
||||
type Props = { params: Promise<{ slug: string }> };
|
||||
@@ -15,7 +16,7 @@ export async function generateMetadata({ params }: Props): Promise<Metadata> {
|
||||
return pageMetadata({
|
||||
title: course.title,
|
||||
description: truncateMetaDescription(
|
||||
course.seoDescription || course.summary,
|
||||
course.seoDescription || htmlToPlain(course.summary),
|
||||
),
|
||||
path: `/register/${pathSlug}`,
|
||||
...(course.posterImageUrl ? { image: course.posterImageUrl } : {}),
|
||||
@@ -45,6 +46,7 @@ export default async function CourseRegisterPage({ params }: Props) {
|
||||
detailsTitle: t("courseDetailsTitle"),
|
||||
aboutTitle: t("courseAboutTitle"),
|
||||
duration: t("courseDuration"),
|
||||
date: t("courseDate"),
|
||||
format: t("courseFormat"),
|
||||
category: t("courseCategory"),
|
||||
price: t("coursePrice"),
|
||||
|
||||
@@ -1,69 +1,5 @@
|
||||
import type { Metadata } from "next";
|
||||
import Link from "next/link";
|
||||
import { notFound } from "next/navigation";
|
||||
import { Container } from "@/components/atoms/Container";
|
||||
import { Section } from "@/components/atoms/Section";
|
||||
import { TextLink } from "@/components/atoms/TextLink";
|
||||
import { CheckList } from "@/components/molecules/CheckList";
|
||||
import { PageHero } from "@/components/molecules/PageHero";
|
||||
import { SurfaceCard } from "@/components/molecules/SurfaceCard";
|
||||
import { buttonVariants } from "@/components/ui/button";
|
||||
import { cn } from "@/lib/utils";
|
||||
import { getTopicBySlug } from "@/lib/data/site";
|
||||
import { pageMetadata, truncateMetaDescription } from "@/lib/seo/metadata";
|
||||
|
||||
type Props = { params: Promise<{ slug: string }> };
|
||||
|
||||
export async function generateMetadata({ params }: Props): Promise<Metadata> {
|
||||
const { slug } = await params;
|
||||
const topic = await getTopicBySlug(slug);
|
||||
if (!topic) return { title: "موضوع یافت نشد" };
|
||||
return pageMetadata({
|
||||
title: topic.title,
|
||||
description: truncateMetaDescription(topic.description),
|
||||
path: `/topics/${slug}`,
|
||||
image: topic.imageUrl,
|
||||
});
|
||||
}
|
||||
|
||||
export default async function TopicPage({ params }: Props) {
|
||||
const { slug } = await params;
|
||||
const topic = await getTopicBySlug(slug);
|
||||
if (!topic) notFound();
|
||||
|
||||
return (
|
||||
<main id="main-content">
|
||||
<PageHero
|
||||
title={topic.title}
|
||||
intro={topic.description}
|
||||
imageUrl={topic.imageUrl}
|
||||
/>
|
||||
<Section tone="subtle">
|
||||
<Container className="grid min-w-0 gap-10 lg:grid-cols-[minmax(0,1fr)_minmax(0,22rem)] lg:items-start lg:gap-12">
|
||||
<div className="min-w-0 space-y-8">
|
||||
<p className="text-base leading-8 text-foreground/90">{topic.body}</p>
|
||||
{topic.highlights.length > 0 ? (
|
||||
<CheckList items={topic.highlights} />
|
||||
) : null}
|
||||
</div>
|
||||
<aside className="min-w-0 space-y-4 lg:sticky lg:top-28">
|
||||
<SurfaceCard padded as="div">
|
||||
<p className="text-sm leading-7 text-muted-foreground">
|
||||
دوره های مرتبط با این موضوع را در فهرست دوره های کوتاه ببینید.
|
||||
</p>
|
||||
<Link
|
||||
href="/professional"
|
||||
className={cn(buttonVariants({ size: "lg" }), "mt-5 w-full font-bold")}
|
||||
>
|
||||
مشاهده دوره ها
|
||||
</Link>
|
||||
</SurfaceCard>
|
||||
<TextLink href="/" className="block px-1 text-sm">
|
||||
بازگشت به خانه
|
||||
</TextLink>
|
||||
</aside>
|
||||
</Container>
|
||||
</Section>
|
||||
</main>
|
||||
);
|
||||
export default function TopicPage() {
|
||||
notFound();
|
||||
}
|
||||
@@ -43,7 +43,7 @@ export default async function ValuesPage() {
|
||||
<Heading as="h2" level={4} className="mt-2">
|
||||
{item.title}
|
||||
</Heading>
|
||||
<p className="mt-2 text-sm leading-7 text-muted-foreground">
|
||||
<p className="mt-2 text-justify text-sm leading-7 text-muted-foreground">
|
||||
{item.text}
|
||||
</p>
|
||||
</SurfaceCard>
|
||||
@@ -69,7 +69,7 @@ export default async function ValuesPage() {
|
||||
<Heading as="h3" level={4} className="group-hover:text-accent">
|
||||
{example.title}
|
||||
</Heading>
|
||||
<p className="mt-2 text-sm leading-7 text-muted-foreground">
|
||||
<p className="mt-2 text-justify text-sm leading-7 text-muted-foreground">
|
||||
{example.text}
|
||||
</p>
|
||||
<span className="mt-4 inline-flex items-center gap-1.5 text-sm font-semibold text-accent">
|
||||
|
||||
@@ -2,7 +2,7 @@ import { NextRequest, NextResponse } from "next/server";
|
||||
import { query } from "@/lib/db";
|
||||
import { rowToAlumniStory, type AlumniStoryRow } from "@/lib/db/mappers";
|
||||
import { requireAdmin } from "@/lib/auth/admin";
|
||||
import { alumniPatchSchema } from "@/lib/validation/admin";
|
||||
import { alumniPatchSchema, normalizeRichWrite } from "@/lib/validation/admin";
|
||||
import { errorResponse } from "@/lib/api/response";
|
||||
import { revalidateSite } from "@/lib/api/revalidate";
|
||||
import { parseJsonBody, buildUpdate } from "@/lib/api/crud";
|
||||
@@ -40,7 +40,7 @@ export async function PATCH(
|
||||
return errorResponse("بدنه درخواست JSON معتبر نیست", 400);
|
||||
}
|
||||
|
||||
const parsed = alumniPatchSchema.safeParse(body);
|
||||
const parsed = alumniPatchSchema.safeParse(normalizeRichWrite(body));
|
||||
if (!parsed.success) {
|
||||
return errorResponse(parsed.error.issues[0]?.message ?? "داده نادرست", 400);
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@ import { NextRequest, NextResponse } from "next/server";
|
||||
import { query } from "@/lib/db";
|
||||
import { rowToAlumniStory, type AlumniStoryRow } from "@/lib/db/mappers";
|
||||
import { requireAdmin } from "@/lib/auth/admin";
|
||||
import { alumniCreateSchema } from "@/lib/validation/admin";
|
||||
import { alumniCreateSchema, normalizeRichWrite } from "@/lib/validation/admin";
|
||||
import { errorResponse } from "@/lib/api/response";
|
||||
import { makeId, parseJsonBody, buildInsert } from "@/lib/api/crud";
|
||||
import { disabledAdminEntityResponse } from "@/lib/admin/disabled-entities";
|
||||
@@ -24,7 +24,7 @@ export async function POST(request: NextRequest) {
|
||||
return errorResponse("بدنه درخواست JSON معتبر نیست", 400);
|
||||
}
|
||||
|
||||
const parsed = alumniCreateSchema.safeParse(body);
|
||||
const parsed = alumniCreateSchema.safeParse(normalizeRichWrite(body));
|
||||
if (!parsed.success) {
|
||||
return errorResponse(parsed.error.issues[0]?.message ?? "داده نادرست", 400);
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@ import { NextRequest, NextResponse } from "next/server";
|
||||
import { query } from "@/lib/db";
|
||||
import { rowToArticle, type ArticleRow } from "@/lib/db/mappers";
|
||||
import { requireAdmin } from "@/lib/auth/admin";
|
||||
import { articlePatchSchema } from "@/lib/validation/admin";
|
||||
import { articlePatchSchema, normalizeRichWrite } from "@/lib/validation/admin";
|
||||
import { errorResponse } from "@/lib/api/response";
|
||||
import { isUniqueViolation } from "@/lib/db/errors";
|
||||
import { revalidateSite } from "@/lib/api/revalidate";
|
||||
@@ -43,7 +43,7 @@ export async function PATCH(
|
||||
return errorResponse("بدنه درخواست JSON معتبر نیست", 400);
|
||||
}
|
||||
|
||||
const parsed = articlePatchSchema.safeParse(body);
|
||||
const parsed = articlePatchSchema.safeParse(normalizeRichWrite(body));
|
||||
if (!parsed.success) {
|
||||
return errorResponse(parsed.error.issues[0]?.message ?? "داده نادرست", 400);
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@ import { randomUUID } from "node:crypto";
|
||||
import { query } from "@/lib/db";
|
||||
import { rowToArticle, type ArticleRow } from "@/lib/db/mappers";
|
||||
import { requireAdmin } from "@/lib/auth/admin";
|
||||
import { articleCreateSchema } from "@/lib/validation/admin";
|
||||
import { articleCreateSchema, normalizeRichWrite } from "@/lib/validation/admin";
|
||||
import { errorResponse } from "@/lib/api/response";
|
||||
import { isUniqueViolation } from "@/lib/db/errors";
|
||||
import { revalidateSite } from "@/lib/api/revalidate";
|
||||
@@ -26,7 +26,7 @@ export async function POST(request: NextRequest) {
|
||||
return errorResponse("بدنه درخواست JSON معتبر نیست", 400);
|
||||
}
|
||||
|
||||
const parsed = articleCreateSchema.safeParse(body);
|
||||
const parsed = articleCreateSchema.safeParse(normalizeRichWrite(body));
|
||||
if (!parsed.success) {
|
||||
return errorResponse(parsed.error.issues[0]?.message ?? "داده نادرست", 400);
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@ import { NextRequest, NextResponse } from "next/server";
|
||||
import { query } from "@/lib/db";
|
||||
import { rowToCampaignBanner, type CampaignBannerRow } from "@/lib/db/mappers";
|
||||
import { requireAdmin } from "@/lib/auth/admin";
|
||||
import { bannerPatchSchema } from "@/lib/validation/admin";
|
||||
import { bannerPatchSchema, normalizeRichWrite } from "@/lib/validation/admin";
|
||||
import { errorResponse } from "@/lib/api/response";
|
||||
import { revalidateSite } from "@/lib/api/revalidate";
|
||||
import { parseJsonBody, buildUpdate } from "@/lib/api/crud";
|
||||
@@ -34,7 +34,7 @@ export async function PATCH(
|
||||
return errorResponse("بدنه درخواست JSON معتبر نیست", 400);
|
||||
}
|
||||
|
||||
const parsed = bannerPatchSchema.safeParse(body);
|
||||
const parsed = bannerPatchSchema.safeParse(normalizeRichWrite(body));
|
||||
if (!parsed.success) {
|
||||
return errorResponse(parsed.error.issues[0]?.message ?? "داده نادرست", 400);
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@ import { NextRequest, NextResponse } from "next/server";
|
||||
import { query } from "@/lib/db";
|
||||
import { rowToCampaignBanner, type CampaignBannerRow } from "@/lib/db/mappers";
|
||||
import { requireAdmin } from "@/lib/auth/admin";
|
||||
import { bannerCreateSchema } from "@/lib/validation/admin";
|
||||
import { bannerCreateSchema, normalizeRichWrite } from "@/lib/validation/admin";
|
||||
import { errorResponse } from "@/lib/api/response";
|
||||
import { makeId, parseJsonBody, buildInsert } from "@/lib/api/crud";
|
||||
|
||||
@@ -20,7 +20,7 @@ export async function POST(request: NextRequest) {
|
||||
return errorResponse("بدنه درخواست JSON معتبر نیست", 400);
|
||||
}
|
||||
|
||||
const parsed = bannerCreateSchema.safeParse(body);
|
||||
const parsed = bannerCreateSchema.safeParse(normalizeRichWrite(body));
|
||||
if (!parsed.success) {
|
||||
return errorResponse(parsed.error.issues[0]?.message ?? "داده نادرست", 400);
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { NextRequest, NextResponse } from "next/server";
|
||||
import { query } from "@/lib/db";
|
||||
import { requireAdmin } from "@/lib/auth/admin";
|
||||
import { courseCategoryPatchSchema } from "@/lib/validation/admin";
|
||||
import { courseCategoryPatchSchema, normalizeRichWrite } from "@/lib/validation/admin";
|
||||
import { errorResponse } from "@/lib/api/response";
|
||||
import { revalidateSite } from "@/lib/api/revalidate";
|
||||
import { parseJsonBody, buildUpdate } from "@/lib/api/crud";
|
||||
@@ -33,7 +33,7 @@ export async function PATCH(
|
||||
return errorResponse("بدنه درخواست JSON معتبر نیست", 400);
|
||||
}
|
||||
|
||||
const parsed = courseCategoryPatchSchema.safeParse(body);
|
||||
const parsed = courseCategoryPatchSchema.safeParse(normalizeRichWrite(body));
|
||||
if (!parsed.success) {
|
||||
return errorResponse(parsed.error.issues[0]?.message ?? "داده نادرست", 400);
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { NextResponse } from "next/server";
|
||||
import { query } from "@/lib/db";
|
||||
import { requireAdmin } from "@/lib/auth/admin";
|
||||
import { courseCategoryCreateSchema } from "@/lib/validation/admin";
|
||||
import { courseCategoryCreateSchema, normalizeRichWrite } from "@/lib/validation/admin";
|
||||
import { errorResponse } from "@/lib/api/response";
|
||||
import { makeId, parseJsonBody, buildInsert } from "@/lib/api/crud";
|
||||
import { isUniqueViolation } from "@/lib/db/errors";
|
||||
@@ -20,7 +20,7 @@ export async function POST(request: Request) {
|
||||
return errorResponse("بدنه درخواست JSON معتبر نیست", 400);
|
||||
}
|
||||
|
||||
const parsed = courseCategoryCreateSchema.safeParse(body);
|
||||
const parsed = courseCategoryCreateSchema.safeParse(normalizeRichWrite(body));
|
||||
if (!parsed.success) {
|
||||
return errorResponse(parsed.error.issues[0]?.message ?? "داده نادرست", 400);
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { NextRequest, NextResponse } from "next/server";
|
||||
import { query } from "@/lib/db";
|
||||
import { requireAdmin } from "@/lib/auth/admin";
|
||||
import { courseTagPatchSchema } from "@/lib/validation/admin";
|
||||
import { courseTagPatchSchema, normalizeRichWrite } from "@/lib/validation/admin";
|
||||
import { errorResponse } from "@/lib/api/response";
|
||||
import { revalidateSite } from "@/lib/api/revalidate";
|
||||
import { parseJsonBody, buildUpdate } from "@/lib/api/crud";
|
||||
@@ -34,7 +34,7 @@ export async function PATCH(
|
||||
return errorResponse("بدنه درخواست JSON معتبر نیست", 400);
|
||||
}
|
||||
|
||||
const parsed = courseTagPatchSchema.safeParse(body);
|
||||
const parsed = courseTagPatchSchema.safeParse(normalizeRichWrite(body));
|
||||
if (!parsed.success) {
|
||||
return errorResponse(parsed.error.issues[0]?.message ?? "داده نادرست", 400);
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { NextResponse } from "next/server";
|
||||
import { query } from "@/lib/db";
|
||||
import { requireAdmin } from "@/lib/auth/admin";
|
||||
import { courseTagCreateSchema } from "@/lib/validation/admin";
|
||||
import { courseTagCreateSchema, normalizeRichWrite } from "@/lib/validation/admin";
|
||||
import { errorResponse } from "@/lib/api/response";
|
||||
import { makeId, parseJsonBody, buildInsert } from "@/lib/api/crud";
|
||||
import { isUniqueViolation } from "@/lib/db/errors";
|
||||
@@ -20,7 +20,7 @@ export async function POST(request: Request) {
|
||||
return errorResponse("بدنه درخواست JSON معتبر نیست", 400);
|
||||
}
|
||||
|
||||
const parsed = courseTagCreateSchema.safeParse(body);
|
||||
const parsed = courseTagCreateSchema.safeParse(normalizeRichWrite(body));
|
||||
if (!parsed.success) {
|
||||
return errorResponse(parsed.error.issues[0]?.message ?? "داده نادرست", 400);
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { NextRequest, NextResponse } from "next/server";
|
||||
import { query } from "@/lib/db";
|
||||
import { requireAdmin } from "@/lib/auth/admin";
|
||||
import { coursePatchSchema } from "@/lib/validation/admin";
|
||||
import { coursePatchSchema, normalizeRichWrite } from "@/lib/validation/admin";
|
||||
import { errorResponse } from "@/lib/api/response";
|
||||
import { isUniqueViolation } from "@/lib/db/errors";
|
||||
import { revalidateSite } from "@/lib/api/revalidate";
|
||||
@@ -38,6 +38,7 @@ const COURSE_COLUMNS: Record<string, string> = {
|
||||
title: "title",
|
||||
summary: "summary",
|
||||
durationHours: "duration_hours",
|
||||
startDate: "start_date",
|
||||
format: "format",
|
||||
price: "price",
|
||||
registrationUrl: "registration_url",
|
||||
@@ -68,7 +69,7 @@ export async function PATCH(
|
||||
return errorResponse("بدنه درخواست JSON معتبر نیست", 400);
|
||||
}
|
||||
|
||||
const parsed = coursePatchSchema.safeParse(body);
|
||||
const parsed = coursePatchSchema.safeParse(normalizeRichWrite(body));
|
||||
if (!parsed.success) {
|
||||
return errorResponse(parsed.error.issues[0]?.message ?? "داده نادرست", 400);
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@ import { NextRequest, NextResponse } from "next/server";
|
||||
import { randomUUID } from "node:crypto";
|
||||
import { query } from "@/lib/db";
|
||||
import { requireAdmin } from "@/lib/auth/admin";
|
||||
import { courseCreateSchema } from "@/lib/validation/admin";
|
||||
import { courseCreateSchema, normalizeRichWrite } from "@/lib/validation/admin";
|
||||
import { errorResponse } from "@/lib/api/response";
|
||||
import { isUniqueViolation } from "@/lib/db/errors";
|
||||
import { revalidateSite } from "@/lib/api/revalidate";
|
||||
@@ -53,7 +53,7 @@ export async function POST(request: NextRequest) {
|
||||
return errorResponse("بدنه درخواست JSON معتبر نیست", 400);
|
||||
}
|
||||
|
||||
const parsed = courseCreateSchema.safeParse(body);
|
||||
const parsed = courseCreateSchema.safeParse(normalizeRichWrite(body));
|
||||
if (!parsed.success) {
|
||||
return errorResponse(parsed.error.issues[0]?.message ?? "داده نادرست", 400);
|
||||
}
|
||||
@@ -63,16 +63,17 @@ export async function POST(request: NextRequest) {
|
||||
try {
|
||||
await query(
|
||||
`INSERT INTO courses
|
||||
(id, slug, title, summary, duration_hours, format, price,
|
||||
(id, slug, title, summary, duration_hours, start_date, format, price,
|
||||
registration_url, poster_image_url, brochure_image_url, image_url,
|
||||
lead_html, body_html, seo_description, published, featured, sort_order)
|
||||
VALUES ($1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12,$13,$14,$15,$16,$17)`,
|
||||
VALUES ($1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12,$13,$14,$15,$16,$17,$18)`,
|
||||
[
|
||||
id,
|
||||
d.slug,
|
||||
d.title,
|
||||
d.summary,
|
||||
d.durationHours ?? null,
|
||||
d.startDate ?? null,
|
||||
d.format,
|
||||
d.price ?? null,
|
||||
d.registrationUrl,
|
||||
|
||||
@@ -2,7 +2,7 @@ import { NextRequest, NextResponse } from "next/server";
|
||||
import { query } from "@/lib/db";
|
||||
import { rowToEvent, type EventRow } from "@/lib/db/mappers";
|
||||
import { requireAdmin } from "@/lib/auth/admin";
|
||||
import { eventPatchSchema } from "@/lib/validation/admin";
|
||||
import { eventPatchSchema, normalizeRichWrite } from "@/lib/validation/admin";
|
||||
import { errorResponse } from "@/lib/api/response";
|
||||
import { revalidateSite } from "@/lib/api/revalidate";
|
||||
import { parseJsonBody, buildUpdate } from "@/lib/api/crud";
|
||||
@@ -40,7 +40,7 @@ export async function PATCH(
|
||||
return errorResponse("بدنه درخواست JSON معتبر نیست", 400);
|
||||
}
|
||||
|
||||
const parsed = eventPatchSchema.safeParse(body);
|
||||
const parsed = eventPatchSchema.safeParse(normalizeRichWrite(body));
|
||||
if (!parsed.success) {
|
||||
return errorResponse(parsed.error.issues[0]?.message ?? "داده نادرست", 400);
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@ import { NextRequest, NextResponse } from "next/server";
|
||||
import { query } from "@/lib/db";
|
||||
import { rowToEvent, type EventRow } from "@/lib/db/mappers";
|
||||
import { requireAdmin } from "@/lib/auth/admin";
|
||||
import { eventCreateSchema } from "@/lib/validation/admin";
|
||||
import { eventCreateSchema, normalizeRichWrite } from "@/lib/validation/admin";
|
||||
import { errorResponse } from "@/lib/api/response";
|
||||
import { makeId, parseJsonBody, buildInsert } from "@/lib/api/crud";
|
||||
import { disabledAdminEntityResponse } from "@/lib/admin/disabled-entities";
|
||||
@@ -24,7 +24,7 @@ export async function POST(request: NextRequest) {
|
||||
return errorResponse("بدنه درخواست JSON معتبر نیست", 400);
|
||||
}
|
||||
|
||||
const parsed = eventCreateSchema.safeParse(body);
|
||||
const parsed = eventCreateSchema.safeParse(normalizeRichWrite(body));
|
||||
if (!parsed.success) {
|
||||
return errorResponse(parsed.error.issues[0]?.message ?? "داده نادرست", 400);
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@ import { NextRequest, NextResponse } from "next/server";
|
||||
import { query } from "@/lib/db";
|
||||
import { rowToFacultyMember, type FacultyMemberRow } from "@/lib/db/mappers";
|
||||
import { requireAdmin } from "@/lib/auth/admin";
|
||||
import { facultyPatchSchema } from "@/lib/validation/admin";
|
||||
import { facultyPatchSchema, normalizeRichWrite } from "@/lib/validation/admin";
|
||||
import { errorResponse } from "@/lib/api/response";
|
||||
import { revalidateSite } from "@/lib/api/revalidate";
|
||||
import { parseJsonBody, buildUpdate } from "@/lib/api/crud";
|
||||
@@ -42,7 +42,7 @@ export async function PATCH(
|
||||
return errorResponse("بدنه درخواست JSON معتبر نیست", 400);
|
||||
}
|
||||
|
||||
const parsed = facultyPatchSchema.safeParse(body);
|
||||
const parsed = facultyPatchSchema.safeParse(normalizeRichWrite(body));
|
||||
if (!parsed.success) {
|
||||
return errorResponse(parsed.error.issues[0]?.message ?? "داده نادرست", 400);
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@ import { NextRequest, NextResponse } from "next/server";
|
||||
import { query } from "@/lib/db";
|
||||
import { rowToFacultyMember, type FacultyMemberRow } from "@/lib/db/mappers";
|
||||
import { requireAdmin } from "@/lib/auth/admin";
|
||||
import { facultyCreateSchema } from "@/lib/validation/admin";
|
||||
import { facultyCreateSchema, normalizeRichWrite } from "@/lib/validation/admin";
|
||||
import { errorResponse } from "@/lib/api/response";
|
||||
import { makeId, parseJsonBody, buildInsert } from "@/lib/api/crud";
|
||||
|
||||
@@ -20,7 +20,7 @@ export async function POST(request: NextRequest) {
|
||||
return errorResponse("بدنه درخواست JSON معتبر نیست", 400);
|
||||
}
|
||||
|
||||
const parsed = facultyCreateSchema.safeParse(body);
|
||||
const parsed = facultyCreateSchema.safeParse(normalizeRichWrite(body));
|
||||
if (!parsed.success) {
|
||||
return errorResponse(parsed.error.issues[0]?.message ?? "داده نادرست", 400);
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@ import { NextRequest, NextResponse } from "next/server";
|
||||
import { query } from "@/lib/db";
|
||||
import { rowToLegalPage, type LegalPageRow } from "@/lib/db/mappers";
|
||||
import { requireAdmin } from "@/lib/auth/admin";
|
||||
import { legalPatchSchema } from "@/lib/validation/admin";
|
||||
import { legalPatchSchema, normalizeRichWrite } from "@/lib/validation/admin";
|
||||
import { errorResponse } from "@/lib/api/response";
|
||||
import { revalidateSite } from "@/lib/api/revalidate";
|
||||
import { parseJsonBody, buildUpdate } from "@/lib/api/crud";
|
||||
@@ -32,7 +32,7 @@ export async function PATCH(
|
||||
return errorResponse("بدنه درخواست JSON معتبر نیست", 400);
|
||||
}
|
||||
|
||||
const parsed = legalPatchSchema.safeParse(body);
|
||||
const parsed = legalPatchSchema.safeParse(normalizeRichWrite(body));
|
||||
if (!parsed.success) {
|
||||
return errorResponse(parsed.error.issues[0]?.message ?? "داده نادرست", 400);
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@ import { NextRequest, NextResponse } from "next/server";
|
||||
import { query } from "@/lib/db";
|
||||
import { rowToLegalPage, type LegalPageRow } from "@/lib/db/mappers";
|
||||
import { requireAdmin } from "@/lib/auth/admin";
|
||||
import { legalCreateSchema } from "@/lib/validation/admin";
|
||||
import { legalCreateSchema, normalizeRichWrite } from "@/lib/validation/admin";
|
||||
import { errorResponse } from "@/lib/api/response";
|
||||
import { parseJsonBody, buildInsert } from "@/lib/api/crud";
|
||||
import { isUniqueViolation } from "@/lib/db/errors";
|
||||
@@ -21,7 +21,7 @@ export async function POST(request: NextRequest) {
|
||||
return errorResponse("بدنه درخواست JSON معتبر نیست", 400);
|
||||
}
|
||||
|
||||
const parsed = legalCreateSchema.safeParse(body);
|
||||
const parsed = legalCreateSchema.safeParse(normalizeRichWrite(body));
|
||||
if (!parsed.success) {
|
||||
return errorResponse(parsed.error.issues[0]?.message ?? "داده نادرست", 400);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,80 @@
|
||||
import { NextRequest, NextResponse } from "next/server";
|
||||
import { query } from "@/lib/db";
|
||||
import { rowToNews, type NewsRow } from "@/lib/db/mappers";
|
||||
import { requireAdmin } from "@/lib/auth/admin";
|
||||
import { newsPatchSchema, normalizeRichWrite } from "@/lib/validation/admin";
|
||||
import { errorResponse } from "@/lib/api/response";
|
||||
import { revalidateSite } from "@/lib/api/revalidate";
|
||||
import { parseJsonBody, buildUpdate } from "@/lib/api/crud";
|
||||
|
||||
export const dynamic = "force-dynamic";
|
||||
|
||||
const NEWS_COLUMNS: Record<string, string> = {
|
||||
title: "title",
|
||||
bannerImageUrl: "banner_image_url",
|
||||
body: "body",
|
||||
galleryImages: "gallery_images",
|
||||
publishedAt: "published_at",
|
||||
published: "published",
|
||||
};
|
||||
|
||||
// PATCH /api/admin/news/[id] — update a news item (admin only)
|
||||
export async function PATCH(
|
||||
request: NextRequest,
|
||||
{ params }: { params: Promise<{ id: string }> },
|
||||
) {
|
||||
const session = await requireAdmin();
|
||||
if (!session) return errorResponse("عدم دسترسی — ورود لازم است", 401);
|
||||
|
||||
const { id } = await params;
|
||||
|
||||
let body: unknown;
|
||||
try {
|
||||
body = await parseJsonBody(request);
|
||||
} catch {
|
||||
return errorResponse("بدنه درخواست JSON معتبر نیست", 400);
|
||||
}
|
||||
|
||||
const parsed = newsPatchSchema.safeParse(normalizeRichWrite(body));
|
||||
if (!parsed.success) {
|
||||
return errorResponse(parsed.error.issues[0]?.message ?? "داده نادرست", 400);
|
||||
}
|
||||
|
||||
const data: Record<string, unknown> = { ...parsed.data };
|
||||
if (data.galleryImages !== undefined) {
|
||||
data.galleryImages = JSON.stringify(data.galleryImages);
|
||||
}
|
||||
|
||||
const spec = buildUpdate("news_items", "id", NEWS_COLUMNS, data);
|
||||
if (spec.empty) return errorResponse("حداقل یک فیلد برای ویرایش لازم است", 400);
|
||||
|
||||
try {
|
||||
const res = await query<NewsRow>(spec.sql, [...spec.params, id]);
|
||||
if (res.rows.length === 0) return errorResponse("خبر یافت نشد", 404);
|
||||
const row = res.rows[0];
|
||||
return NextResponse.json({ ok: true, data: { ...rowToNews(row), published: row.published } });
|
||||
} catch (err) {
|
||||
console.error("admin update news error:", err);
|
||||
return errorResponse("خطای سرور", 500);
|
||||
}
|
||||
}
|
||||
|
||||
// DELETE /api/admin/news/[id] — delete a news item (admin only)
|
||||
export async function DELETE(
|
||||
_request: NextRequest,
|
||||
{ params }: { params: Promise<{ id: string }> },
|
||||
) {
|
||||
const session = await requireAdmin();
|
||||
if (!session) return errorResponse("عدم دسترسی — ورود لازم است", 401);
|
||||
|
||||
const { id } = await params;
|
||||
try {
|
||||
const res = await query(`DELETE FROM news_items WHERE id = $1 RETURNING id`, [id]);
|
||||
if (res.rows.length === 0) return errorResponse("خبر یافت نشد", 404);
|
||||
revalidateSite();
|
||||
return NextResponse.json({ ok: true });
|
||||
} catch (err) {
|
||||
console.error("admin delete news error:", err);
|
||||
return errorResponse("خطای سرور", 500);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
import { NextRequest, NextResponse } from "next/server";
|
||||
import { query } from "@/lib/db";
|
||||
import { rowToNews, type NewsRow } from "@/lib/db/mappers";
|
||||
import { requireAdmin } from "@/lib/auth/admin";
|
||||
import { newsCreateSchema, normalizeRichWrite } from "@/lib/validation/admin";
|
||||
import { errorResponse } from "@/lib/api/response";
|
||||
import { makeId, parseJsonBody, buildInsert } from "@/lib/api/crud";
|
||||
|
||||
export const dynamic = "force-dynamic";
|
||||
|
||||
// POST /api/admin/news — create a news item (admin only)
|
||||
export async function POST(request: NextRequest) {
|
||||
const session = await requireAdmin();
|
||||
if (!session) return errorResponse("عدم دسترسی — ورود لازم است", 401);
|
||||
|
||||
let body: unknown;
|
||||
try {
|
||||
body = await parseJsonBody(request);
|
||||
} catch {
|
||||
return errorResponse("بدنه درخواست JSON معتبر نیست", 400);
|
||||
}
|
||||
|
||||
const parsed = newsCreateSchema.safeParse(normalizeRichWrite(body));
|
||||
if (!parsed.success) {
|
||||
return errorResponse(parsed.error.issues[0]?.message ?? "داده نادرست", 400);
|
||||
}
|
||||
const d = parsed.data;
|
||||
const id = makeId();
|
||||
|
||||
try {
|
||||
const { sql, params } = buildInsert(
|
||||
"news_items",
|
||||
["id", "title", "banner_image_url", "body", "gallery_images", "published_at", "published"],
|
||||
[
|
||||
id,
|
||||
d.title,
|
||||
d.bannerImageUrl,
|
||||
d.body,
|
||||
JSON.stringify(d.galleryImages),
|
||||
d.publishedAt,
|
||||
d.published,
|
||||
],
|
||||
);
|
||||
await query(sql, params);
|
||||
const res = await query<NewsRow>(`SELECT * FROM news_items WHERE id = $1`, [id]);
|
||||
const row = res.rows[0];
|
||||
return NextResponse.json(
|
||||
{ ok: true, data: { ...rowToNews(row), published: row.published } },
|
||||
{ status: 201 },
|
||||
);
|
||||
} catch (err) {
|
||||
console.error("admin create news error:", err);
|
||||
return errorResponse("خطای سرور", 500);
|
||||
}
|
||||
}
|
||||
@@ -2,11 +2,12 @@ import { NextRequest, NextResponse } from "next/server";
|
||||
import { query } from "@/lib/db";
|
||||
import { rowToProgram, type ProgramRow } from "@/lib/db/mappers";
|
||||
import { requireAdmin } from "@/lib/auth/admin";
|
||||
import { programPatchSchema } from "@/lib/validation/admin";
|
||||
import { programPatchSchema, normalizeRichWrite } from "@/lib/validation/admin";
|
||||
import { errorResponse } from "@/lib/api/response";
|
||||
import { revalidateSite } from "@/lib/api/revalidate";
|
||||
import { parseJsonBody, buildUpdate } from "@/lib/api/crud";
|
||||
import { isUniqueViolation } from "@/lib/db/errors";
|
||||
import { disabledAdminEntityResponse } from "@/lib/admin/disabled-entities";
|
||||
|
||||
export const dynamic = "force-dynamic";
|
||||
|
||||
@@ -30,6 +31,9 @@ export async function PATCH(
|
||||
request: NextRequest,
|
||||
{ params }: { params: Promise<{ id: string }> },
|
||||
) {
|
||||
const disabled = disabledAdminEntityResponse("programs");
|
||||
if (disabled) return disabled;
|
||||
|
||||
const session = await requireAdmin();
|
||||
if (!session) return errorResponse("عدم دسترسی — ورود لازم است", 401);
|
||||
|
||||
@@ -42,7 +46,7 @@ export async function PATCH(
|
||||
return errorResponse("بدنه درخواست JSON معتبر نیست", 400);
|
||||
}
|
||||
|
||||
const parsed = programPatchSchema.safeParse(body);
|
||||
const parsed = programPatchSchema.safeParse(normalizeRichWrite(body));
|
||||
if (!parsed.success) {
|
||||
return errorResponse(parsed.error.issues[0]?.message ?? "داده نادرست", 400);
|
||||
}
|
||||
@@ -74,6 +78,9 @@ export async function DELETE(
|
||||
_request: NextRequest,
|
||||
{ params }: { params: Promise<{ id: string }> },
|
||||
) {
|
||||
const disabled = disabledAdminEntityResponse("programs");
|
||||
if (disabled) return disabled;
|
||||
|
||||
const session = await requireAdmin();
|
||||
if (!session) return errorResponse("عدم دسترسی — ورود لازم است", 401);
|
||||
|
||||
|
||||
@@ -2,15 +2,19 @@ import { NextRequest, NextResponse } from "next/server";
|
||||
import { query } from "@/lib/db";
|
||||
import { rowToProgram, type ProgramRow } from "@/lib/db/mappers";
|
||||
import { requireAdmin } from "@/lib/auth/admin";
|
||||
import { programCreateSchema } from "@/lib/validation/admin";
|
||||
import { programCreateSchema, normalizeRichWrite } from "@/lib/validation/admin";
|
||||
import { errorResponse } from "@/lib/api/response";
|
||||
import { makeId, parseJsonBody, buildInsert } from "@/lib/api/crud";
|
||||
import { isUniqueViolation } from "@/lib/db/errors";
|
||||
import { disabledAdminEntityResponse } from "@/lib/admin/disabled-entities";
|
||||
|
||||
export const dynamic = "force-dynamic";
|
||||
|
||||
// POST /api/admin/programs — create program (admin only)
|
||||
export async function POST(request: NextRequest) {
|
||||
const disabled = disabledAdminEntityResponse("programs");
|
||||
if (disabled) return disabled;
|
||||
|
||||
const session = await requireAdmin();
|
||||
if (!session) return errorResponse("عدم دسترسی — ورود لازم است", 401);
|
||||
|
||||
@@ -21,7 +25,7 @@ export async function POST(request: NextRequest) {
|
||||
return errorResponse("بدنه درخواست JSON معتبر نیست", 400);
|
||||
}
|
||||
|
||||
const parsed = programCreateSchema.safeParse(body);
|
||||
const parsed = programCreateSchema.safeParse(normalizeRichWrite(body));
|
||||
if (!parsed.success) {
|
||||
return errorResponse(parsed.error.issues[0]?.message ?? "داده نادرست", 400);
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { NextRequest, NextResponse } from "next/server";
|
||||
import { query } from "@/lib/db";
|
||||
import { requireAdmin } from "@/lib/auth/admin";
|
||||
import { registrationStatusSchema } from "@/lib/validation/admin";
|
||||
import { registrationStatusSchema, normalizeRichWrite } from "@/lib/validation/admin";
|
||||
import { errorResponse } from "@/lib/api/response";
|
||||
import { parseJsonBody } from "@/lib/api/crud";
|
||||
import type { RegistrationLeadRow } from "@/app/api/admin/registrations/route";
|
||||
@@ -25,7 +25,7 @@ export async function PATCH(
|
||||
return errorResponse("بدنه درخواست JSON معتبر نیست", 400);
|
||||
}
|
||||
|
||||
const parsed = registrationStatusSchema.safeParse(body);
|
||||
const parsed = registrationStatusSchema.safeParse(normalizeRichWrite(body));
|
||||
if (!parsed.success) {
|
||||
return errorResponse(parsed.error.issues[0]?.message ?? "داده نادرست", 400);
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@ import { NextRequest, NextResponse } from "next/server";
|
||||
import { query } from "@/lib/db";
|
||||
import { rowToSiteStat, type SiteStatRow } from "@/lib/db/mappers";
|
||||
import { requireAdmin } from "@/lib/auth/admin";
|
||||
import { statPatchSchema } from "@/lib/validation/admin";
|
||||
import { statPatchSchema, normalizeRichWrite } from "@/lib/validation/admin";
|
||||
import { errorResponse } from "@/lib/api/response";
|
||||
import { revalidateSite } from "@/lib/api/revalidate";
|
||||
import { parseJsonBody, buildUpdate } from "@/lib/api/crud";
|
||||
@@ -32,7 +32,7 @@ export async function PATCH(
|
||||
return errorResponse("بدنه درخواست JSON معتبر نیست", 400);
|
||||
}
|
||||
|
||||
const parsed = statPatchSchema.safeParse(body);
|
||||
const parsed = statPatchSchema.safeParse(normalizeRichWrite(body));
|
||||
if (!parsed.success) {
|
||||
return errorResponse(parsed.error.issues[0]?.message ?? "داده نادرست", 400);
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@ import { NextRequest, NextResponse } from "next/server";
|
||||
import { query } from "@/lib/db";
|
||||
import { rowToSiteStat, type SiteStatRow } from "@/lib/db/mappers";
|
||||
import { requireAdmin } from "@/lib/auth/admin";
|
||||
import { statCreateSchema } from "@/lib/validation/admin";
|
||||
import { statCreateSchema, normalizeRichWrite } from "@/lib/validation/admin";
|
||||
import { errorResponse } from "@/lib/api/response";
|
||||
import { makeId, parseJsonBody, buildInsert } from "@/lib/api/crud";
|
||||
|
||||
@@ -20,7 +20,7 @@ export async function POST(request: NextRequest) {
|
||||
return errorResponse("بدنه درخواست JSON معتبر نیست", 400);
|
||||
}
|
||||
|
||||
const parsed = statCreateSchema.safeParse(body);
|
||||
const parsed = statCreateSchema.safeParse(normalizeRichWrite(body));
|
||||
if (!parsed.success) {
|
||||
return errorResponse(parsed.error.issues[0]?.message ?? "داده نادرست", 400);
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@ import { NextRequest, NextResponse } from "next/server";
|
||||
import { query } from "@/lib/db";
|
||||
import { rowToTestimonial, type TestimonialRow } from "@/lib/db/mappers";
|
||||
import { requireAdmin } from "@/lib/auth/admin";
|
||||
import { testimonialPatchSchema } from "@/lib/validation/admin";
|
||||
import { testimonialPatchSchema, normalizeRichWrite } from "@/lib/validation/admin";
|
||||
import { errorResponse } from "@/lib/api/response";
|
||||
import { revalidateSite } from "@/lib/api/revalidate";
|
||||
import { parseJsonBody, buildUpdate } from "@/lib/api/crud";
|
||||
@@ -34,7 +34,7 @@ export async function PATCH(
|
||||
return errorResponse("بدنه درخواست JSON معتبر نیست", 400);
|
||||
}
|
||||
|
||||
const parsed = testimonialPatchSchema.safeParse(body);
|
||||
const parsed = testimonialPatchSchema.safeParse(normalizeRichWrite(body));
|
||||
if (!parsed.success) {
|
||||
return errorResponse(parsed.error.issues[0]?.message ?? "داده نادرست", 400);
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@ import { NextRequest, NextResponse } from "next/server";
|
||||
import { query } from "@/lib/db";
|
||||
import { rowToTestimonial, type TestimonialRow } from "@/lib/db/mappers";
|
||||
import { requireAdmin } from "@/lib/auth/admin";
|
||||
import { testimonialCreateSchema } from "@/lib/validation/admin";
|
||||
import { testimonialCreateSchema, normalizeRichWrite } from "@/lib/validation/admin";
|
||||
import { errorResponse } from "@/lib/api/response";
|
||||
import { makeId, parseJsonBody, buildInsert } from "@/lib/api/crud";
|
||||
|
||||
@@ -20,7 +20,7 @@ export async function POST(request: NextRequest) {
|
||||
return errorResponse("بدنه درخواست JSON معتبر نیست", 400);
|
||||
}
|
||||
|
||||
const parsed = testimonialCreateSchema.safeParse(body);
|
||||
const parsed = testimonialCreateSchema.safeParse(normalizeRichWrite(body));
|
||||
if (!parsed.success) {
|
||||
return errorResponse(parsed.error.issues[0]?.message ?? "داده نادرست", 400);
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@ import { NextRequest, NextResponse } from "next/server";
|
||||
import { query } from "@/lib/db";
|
||||
import { rowToIntersectionTopic, type IntersectionTopicRow } from "@/lib/db/mappers";
|
||||
import { requireAdmin } from "@/lib/auth/admin";
|
||||
import { topicPatchSchema } from "@/lib/validation/admin";
|
||||
import { topicPatchSchema, normalizeRichWrite } from "@/lib/validation/admin";
|
||||
import { errorResponse } from "@/lib/api/response";
|
||||
import { revalidateSite } from "@/lib/api/revalidate";
|
||||
import { parseJsonBody, buildUpdate } from "@/lib/api/crud";
|
||||
@@ -38,7 +38,7 @@ export async function PATCH(
|
||||
return errorResponse("بدنه درخواست JSON معتبر نیست", 400);
|
||||
}
|
||||
|
||||
const parsed = topicPatchSchema.safeParse(body);
|
||||
const parsed = topicPatchSchema.safeParse(normalizeRichWrite(body));
|
||||
if (!parsed.success) {
|
||||
return errorResponse(parsed.error.issues[0]?.message ?? "داده نادرست", 400);
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@ import { NextRequest, NextResponse } from "next/server";
|
||||
import { query } from "@/lib/db";
|
||||
import { rowToIntersectionTopic, type IntersectionTopicRow } from "@/lib/db/mappers";
|
||||
import { requireAdmin } from "@/lib/auth/admin";
|
||||
import { topicCreateSchema } from "@/lib/validation/admin";
|
||||
import { topicCreateSchema, normalizeRichWrite } from "@/lib/validation/admin";
|
||||
import { errorResponse } from "@/lib/api/response";
|
||||
import { makeId, parseJsonBody, buildInsert } from "@/lib/api/crud";
|
||||
import { isUniqueViolation } from "@/lib/db/errors";
|
||||
@@ -21,7 +21,7 @@ export async function POST(request: NextRequest) {
|
||||
return errorResponse("بدنه درخواست JSON معتبر نیست", 400);
|
||||
}
|
||||
|
||||
const parsed = topicCreateSchema.safeParse(body);
|
||||
const parsed = topicCreateSchema.safeParse(normalizeRichWrite(body));
|
||||
if (!parsed.success) {
|
||||
return errorResponse(parsed.error.issues[0]?.message ?? "داده نادرست", 400);
|
||||
}
|
||||
|
||||
@@ -1,13 +1,5 @@
|
||||
import { NextResponse } from "next/server";
|
||||
import { getArticleById } from "@/lib/data/articles";
|
||||
|
||||
type Params = { params: Promise<{ id: string }> };
|
||||
|
||||
export async function GET(_request: Request, { params }: Params) {
|
||||
const { id } = await params;
|
||||
const article = await getArticleById(id);
|
||||
if (!article) {
|
||||
return NextResponse.json({ error: "Article not found" }, { status: 404 });
|
||||
}
|
||||
return NextResponse.json({ data: article });
|
||||
export function GET() {
|
||||
return new NextResponse(null, { status: 404 });
|
||||
}
|
||||
@@ -1,7 +1,5 @@
|
||||
import { NextResponse } from "next/server";
|
||||
import { getArticles } from "@/lib/data/articles";
|
||||
|
||||
export async function GET() {
|
||||
const data = await getArticles();
|
||||
return NextResponse.json({ data });
|
||||
export function GET() {
|
||||
return new NextResponse(null, { status: 404 });
|
||||
}
|
||||
@@ -1,13 +1,5 @@
|
||||
import { NextResponse } from "next/server";
|
||||
import { getEventById } from "@/lib/data/events";
|
||||
|
||||
type Params = { params: Promise<{ id: string }> };
|
||||
|
||||
export async function GET(_request: Request, { params }: Params) {
|
||||
const { id } = await params;
|
||||
const event = await getEventById(id);
|
||||
if (!event) {
|
||||
return NextResponse.json({ error: "Event not found" }, { status: 404 });
|
||||
}
|
||||
return NextResponse.json({ data: event });
|
||||
export function GET() {
|
||||
return new NextResponse(null, { status: 404 });
|
||||
}
|
||||
@@ -1,7 +1,5 @@
|
||||
import { NextResponse } from "next/server";
|
||||
import { getEvents } from "@/lib/data/events";
|
||||
|
||||
export async function GET() {
|
||||
const data = await getEvents();
|
||||
return NextResponse.json({ data });
|
||||
export function GET() {
|
||||
return new NextResponse(null, { status: 404 });
|
||||
}
|
||||
@@ -1,13 +1,5 @@
|
||||
import { NextResponse } from "next/server";
|
||||
import { getProgramBySlug } from "@/lib/data/programs";
|
||||
|
||||
type Params = { params: Promise<{ slug: string }> };
|
||||
|
||||
export async function GET(_request: Request, { params }: Params) {
|
||||
const { slug } = await params;
|
||||
const program = await getProgramBySlug(slug);
|
||||
if (!program) {
|
||||
return NextResponse.json({ error: "Program not found" }, { status: 404 });
|
||||
}
|
||||
return NextResponse.json({ data: program });
|
||||
export function GET() {
|
||||
return new NextResponse(null, { status: 404 });
|
||||
}
|
||||
@@ -1,7 +1,5 @@
|
||||
import { NextResponse } from "next/server";
|
||||
import { getPrograms } from "@/lib/data/programs";
|
||||
|
||||
export async function GET() {
|
||||
const data = await getPrograms();
|
||||
return NextResponse.json({ data });
|
||||
export function GET() {
|
||||
return new NextResponse(null, { status: 404 });
|
||||
}
|
||||
@@ -184,6 +184,19 @@
|
||||
/* Metamorph field: static on purpose (animations removed for mobile perf).
|
||||
Legacy keyframes kept only so reduced-motion rules stay harmless. */
|
||||
|
||||
/* Persian paragraphs: even both edges. Last line stays natural. */
|
||||
.text-justify {
|
||||
text-justify: inter-word;
|
||||
}
|
||||
|
||||
.rich-text-editor p.is-editor-empty:first-child::before {
|
||||
float: inline-end;
|
||||
height: 0;
|
||||
color: var(--muted-foreground);
|
||||
content: attr(data-placeholder);
|
||||
pointer-events: none;
|
||||
}
|
||||
|
||||
.page-hero::after,
|
||||
.home-hero::after {
|
||||
position: absolute;
|
||||
|
||||
@@ -39,6 +39,7 @@ const getCounts = async (): Promise<Record<string, number>> => {
|
||||
UNION ALL SELECT 'programs', count(*) FROM programs
|
||||
UNION ALL SELECT 'events', count(*) FROM events
|
||||
UNION ALL SELECT 'articles', count(*) FROM articles
|
||||
UNION ALL SELECT 'news', count(*) FROM news_items
|
||||
UNION ALL SELECT 'faculty', count(*) FROM faculty_members
|
||||
UNION ALL SELECT 'alumni', count(*) FROM alumni_stories`,
|
||||
);
|
||||
@@ -49,6 +50,7 @@ const countCards = [
|
||||
{ key: "courses", label: "دوره ها", href: "/mstcontroller/courses", icon: BookOpen },
|
||||
{ key: "programs", label: "برنامه ها", href: "/mstcontroller/programs", icon: GraduationCap },
|
||||
{ key: "events", label: "رویدادها", href: "/mstcontroller/events", icon: Calendar },
|
||||
{ key: "news", label: "اخبار", href: "/mstcontroller/news", icon: Newspaper },
|
||||
{ key: "articles", label: "مقالات", href: "/mstcontroller/articles", icon: Newspaper },
|
||||
{ key: "faculty", label: "اساتید", href: "/mstcontroller/faculty", icon: Users },
|
||||
{ key: "alumni", label: "دانش آموختگان", href: "/mstcontroller/alumni", icon: MessageSquareQuote },
|
||||
|
||||
@@ -4,9 +4,9 @@ import { SiteHeader } from "@/components/organisms/SiteHeader";
|
||||
import { buildCourseNavChildren } from "@/lib/course-nav";
|
||||
import { getCourses } from "@/lib/data/courses";
|
||||
import { listPublishedCourseTags } from "@/lib/data/taxonomy";
|
||||
import { getPrograms } from "@/lib/data/programs";
|
||||
import {
|
||||
courseNavParentTag,
|
||||
facultyNetworkUrl,
|
||||
facultySiteUrl,
|
||||
professionalNav,
|
||||
siteShortName,
|
||||
@@ -22,12 +22,10 @@ export default async function ProfessionalLayout({
|
||||
const t = await getTranslations();
|
||||
const year = new Date().getFullYear();
|
||||
let courses: Awaited<ReturnType<typeof getCourses>> = [];
|
||||
let programs: Awaited<ReturnType<typeof getPrograms>> = [];
|
||||
let navTags: Awaited<ReturnType<typeof listPublishedCourseTags>> = [];
|
||||
try {
|
||||
[courses, programs, navTags] = await Promise.all([
|
||||
[courses, navTags] = await Promise.all([
|
||||
getCourses(),
|
||||
getPrograms(),
|
||||
listPublishedCourseTags({ navOnly: true }),
|
||||
]);
|
||||
} catch (err) {
|
||||
@@ -53,7 +51,6 @@ export default async function ProfessionalLayout({
|
||||
brandSubtitle={t("nav.brandSubtitle")}
|
||||
variant="professional"
|
||||
courses={courses}
|
||||
programs={programs}
|
||||
/>
|
||||
<div className="min-w-0 flex-1 overflow-x-clip">{children}</div>
|
||||
<SiteFooter
|
||||
@@ -62,6 +59,7 @@ export default async function ProfessionalLayout({
|
||||
linksTitle={t("footer.links")}
|
||||
links={[
|
||||
{ label: t("footer.facultySite"), href: facultySiteUrl },
|
||||
{ label: t("footer.facultyNetwork"), href: facultyNetworkUrl },
|
||||
{ label: t("footer.press"), href: "/press" },
|
||||
{ label: t("footer.careers"), href: "/careers" },
|
||||
]}
|
||||
|
||||
+31
-79
@@ -1,9 +1,7 @@
|
||||
import type { MetadataRoute } from "next";
|
||||
import { getArticles } from "@/lib/data/articles";
|
||||
import { getCourses } from "@/lib/data/courses";
|
||||
import { getEvents } from "@/lib/data/events";
|
||||
import { getPrograms } from "@/lib/data/programs";
|
||||
import { getTopics } from "@/lib/data/site";
|
||||
import { connection } from "next/server";
|
||||
import { getCoursesForSitemap } from "@/lib/data/courses";
|
||||
import { getNewsForSitemap } from "@/lib/data/news";
|
||||
|
||||
const BASE_URL = (
|
||||
process.env.NEXT_PUBLIC_SITE_URL ?? "https://edu.mstaut.ir"
|
||||
@@ -15,6 +13,9 @@ const LEGAL_SLUGS = ["press", "careers"] as const;
|
||||
type SitemapEntry = MetadataRoute.Sitemap[number];
|
||||
type ChangeFrequency = NonNullable<SitemapEntry["changeFrequency"]>;
|
||||
|
||||
/** Run on each request so published news and courses stay current. */
|
||||
export const dynamic = "force-dynamic";
|
||||
|
||||
function sitemapEntry(
|
||||
path: string,
|
||||
options: {
|
||||
@@ -26,103 +27,54 @@ function sitemapEntry(
|
||||
const normalized = path.startsWith("/") ? path : `/${path}`;
|
||||
return {
|
||||
url: `${BASE_URL}${normalized}`,
|
||||
lastModified: options.lastModified ?? new Date(),
|
||||
...(options.lastModified ? { lastModified: options.lastModified } : {}),
|
||||
changeFrequency: options.changeFrequency ?? "monthly",
|
||||
priority: options.priority ?? 0.5,
|
||||
};
|
||||
}
|
||||
|
||||
export default async function sitemap(): Promise<MetadataRoute.Sitemap> {
|
||||
await connection();
|
||||
|
||||
const entries: MetadataRoute.Sitemap = [
|
||||
sitemapEntry("/", { changeFrequency: "weekly", priority: 1.0 }),
|
||||
sitemapEntry("/professional", { changeFrequency: "weekly", priority: 0.9 }),
|
||||
sitemapEntry("/about", { priority: 0.7 }),
|
||||
sitemapEntry("/contact", { priority: 0.7 }),
|
||||
sitemapEntry("/values", { priority: 0.7 }),
|
||||
sitemapEntry("/alumni", { priority: 0.6 }),
|
||||
sitemapEntry("/programs", { changeFrequency: "weekly", priority: 0.8 }),
|
||||
sitemapEntry("/insights", { changeFrequency: "weekly", priority: 0.7 }),
|
||||
sitemapEntry("/events", { changeFrequency: "weekly", priority: 0.7 }),
|
||||
sitemapEntry("/news", { changeFrequency: "weekly", priority: 0.6 }),
|
||||
...LEGAL_SLUGS.map((slug) =>
|
||||
sitemapEntry(`/${slug}`, { changeFrequency: "yearly", priority: 0.4 }),
|
||||
),
|
||||
];
|
||||
|
||||
try {
|
||||
const courses = await getCourses();
|
||||
for (const course of courses) {
|
||||
if (!course.slug) continue;
|
||||
const [newsResult, coursesResult] = await Promise.allSettled([
|
||||
getNewsForSitemap(),
|
||||
getCoursesForSitemap(),
|
||||
]);
|
||||
|
||||
if (newsResult.status === "fulfilled") {
|
||||
for (const item of newsResult.value) {
|
||||
entries.push(
|
||||
sitemapEntry(`/register/${course.slug}`, {
|
||||
sitemapEntry(`/news/${encodeURIComponent(item.id)}`, {
|
||||
changeFrequency: "weekly",
|
||||
priority: 0.6,
|
||||
lastModified: item.updatedAt,
|
||||
}),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if (coursesResult.status === "fulfilled") {
|
||||
for (const course of coursesResult.value) {
|
||||
entries.push(
|
||||
sitemapEntry(`/register/${encodeURIComponent(course.slug)}`, {
|
||||
changeFrequency: "weekly",
|
||||
priority: 0.8,
|
||||
lastModified: course.updatedAt,
|
||||
}),
|
||||
);
|
||||
}
|
||||
} catch {
|
||||
// DB unavailable at build time — omit dynamic course URLs
|
||||
}
|
||||
|
||||
try {
|
||||
const programs = await getPrograms();
|
||||
for (const program of programs) {
|
||||
if (!program.slug) continue;
|
||||
entries.push(
|
||||
sitemapEntry(`/programs/${program.slug}`, {
|
||||
changeFrequency: "monthly",
|
||||
priority: 0.75,
|
||||
}),
|
||||
);
|
||||
}
|
||||
} catch {
|
||||
// omit
|
||||
}
|
||||
|
||||
try {
|
||||
const articles = await getArticles();
|
||||
for (const article of articles) {
|
||||
if (!article.id) continue;
|
||||
entries.push(
|
||||
sitemapEntry(`/insights/${article.id}`, {
|
||||
changeFrequency: "monthly",
|
||||
priority: 0.65,
|
||||
lastModified: article.publishedAt,
|
||||
}),
|
||||
);
|
||||
}
|
||||
} catch {
|
||||
// omit
|
||||
}
|
||||
|
||||
try {
|
||||
const events = await getEvents();
|
||||
for (const event of events) {
|
||||
if (!event.id) continue;
|
||||
entries.push(
|
||||
sitemapEntry(`/events/${event.id}`, {
|
||||
changeFrequency: "weekly",
|
||||
priority: 0.65,
|
||||
lastModified: event.startDate,
|
||||
}),
|
||||
);
|
||||
}
|
||||
} catch {
|
||||
// omit
|
||||
}
|
||||
|
||||
try {
|
||||
const topics = await getTopics();
|
||||
for (const topic of topics) {
|
||||
if (!topic.slug) continue;
|
||||
entries.push(
|
||||
sitemapEntry(`/topics/${topic.slug}`, {
|
||||
changeFrequency: "monthly",
|
||||
priority: 0.6,
|
||||
}),
|
||||
);
|
||||
}
|
||||
} catch {
|
||||
// omit
|
||||
}
|
||||
|
||||
return entries;
|
||||
|
||||
Reference in new issue
Block a user