diff --git a/backend/src/wiki/wiki.service.ts b/backend/src/wiki/wiki.service.ts index 85c0d75d..13fbca07 100644 --- a/backend/src/wiki/wiki.service.ts +++ b/backend/src/wiki/wiki.service.ts @@ -7,7 +7,9 @@ export class WikiService { constructor(private prisma: PrismaService) {} async findAll(filters: PaginationDto) { - const { search, page = 1, limit = 10, sortBy = 'term', sortOrder = 'asc' } = filters; + const { search, page = 1, limit = 10, sortBy: rawSortBy = 'term', sortOrder = 'asc' } = filters; + const allowedSortFields = ['key', 'term', 'wikiId']; + const sortBy = allowedSortFields.includes(rawSortBy) ? rawSortBy : 'term'; const whereClause: any = {}; if (search) { diff --git a/frontend/application/app/blog/[slug]/page.tsx b/frontend/application/app/blog/[slug]/page.tsx index 60b6ec80..c02020a8 100644 --- a/frontend/application/app/blog/[slug]/page.tsx +++ b/frontend/application/app/blog/[slug]/page.tsx @@ -3,9 +3,11 @@ import { ChevronRight, Calendar, User, Sparkles } from "lucide-react"; import Link from 'next/link'; import type { Metadata } from 'next'; +const API_URL = process.env.NEXT_PUBLIC_API_URL || 'http://localhost:4001'; + async function getBlog(slug: string) { try { - const res = await fetch(`http://localhost:4001/api/blogs/${slug}`, { next: { revalidate: 60 } }); + const res = await fetch(`${API_URL}/api/blogs/${slug}`, { next: { revalidate: 60 } }); if (!res.ok) throw new Error('Failed to fetch blog'); const b = await res.json(); return { @@ -54,7 +56,6 @@ export default async function BlogPostPage({ params }: { params: Promise<{ slug: return (
- {/* Breadcrumbs */}
خانه diff --git a/frontend/application/app/wiki/[slug]/page.tsx b/frontend/application/app/wiki/[slug]/page.tsx index d1c5fb41..989bd4e7 100644 --- a/frontend/application/app/wiki/[slug]/page.tsx +++ b/frontend/application/app/wiki/[slug]/page.tsx @@ -2,10 +2,12 @@ import Link from 'next/link'; import { ChevronRight } from 'lucide-react'; import type { Metadata } from 'next'; -async function getBlog(slug: string) { +const API_URL = process.env.NEXT_PUBLIC_API_URL || 'http://localhost:4001'; + +async function getWikiTerm(key: string) { try { - const res = await fetch(`http://localhost:4001/api/blogs/${slug}`, { next: { revalidate: 60 } }); - if (!res.ok) throw new Error('Failed to fetch blog'); + const res = await fetch(`${API_URL}/api/wiki/${encodeURIComponent(key)}`, { next: { revalidate: 60 } }); + if (!res.ok) throw new Error('Failed to fetch wiki term'); return res.json(); } catch (error) { console.error(error); @@ -15,23 +17,23 @@ async function getBlog(slug: string) { export async function generateMetadata({ params }: { params: Promise<{ slug: string }> }): Promise { const { slug } = await params; - const blog = await getBlog(slug); - if (!blog) return { title: 'مقاله یافت نشد' }; - + const term = await getWikiTerm(slug); + if (!term) return { title: 'ترکیب علمی یافت نشد' }; + return { - title: blog.metaTitle || blog.title, - description: blog.metaDescription || blog.title, + title: term.metaTitle || term.term, + description: term.metaDescription || term.definition?.substring(0, 160), }; } -export default async function BlogPage({ params }: { params: Promise<{ slug: string }> }) { +export default async function WikiTermPage({ params }: { params: Promise<{ slug: string }> }) { const { slug } = await params; - const blog = await getBlog(slug); + const term = await getWikiTerm(slug); - if (!blog) { + if (!term) { return (
-

مقاله‌ای یافت نشد

+

ترکیب علمی یافت نشد

بازگشت به دانشنامه @@ -45,32 +47,16 @@ export default async function BlogPage({ params }: { params: Promise<{ slug: str
- بازگشت به مقالات + بازگشت به دانشنامه - {blog.imageUrl && ( -
- {blog.title} -
- )} -

- {blog.title} + {term.term}

-
- نوشته شده در {new Date(blog.createdAt).toLocaleDateString('fa-IR')} - {blog.author && ( - <> - - توسط {blog.author.firstName} {blog.author.lastName} - - )} -
-