fix: wiki sortBy, wiki detail page endpoint, blog SSR URL, and upload volume
Deploy Canina / deploy (push) Successful in 1m34s
Deploy Canina / deploy (push) Successful in 1m34s
This commit is contained in:
1 parent
10849233de
commit
f71b22a664
3 files changed
+23
-34
No files matched your search
@@ -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) {
|
||||
|
||||
@@ -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 (
|
||||
<div className="min-h-screen bg-medical-gray-50 pt-8 pb-20 px-4 font-vazir" dir="rtl">
|
||||
<div className="max-w-7xl mx-auto">
|
||||
{/* Breadcrumbs */}
|
||||
<div className="flex items-center gap-2 text-[10px] font-black text-medical-gray-400 uppercase tracking-widest mb-10">
|
||||
<Link href="/" className="hover:text-canina-blue transition-colors">خانه</Link>
|
||||
<ChevronRight className="w-2.5 h-2.5" />
|
||||
|
||||
@@ -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<Metadata> {
|
||||
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 (
|
||||
<div className="min-h-[50vh] flex flex-col items-center justify-center font-vazir text-center" dir="rtl">
|
||||
<h1 className="text-3xl font-black text-medical-gray-900 mb-4">مقالهای یافت نشد</h1>
|
||||
<h1 className="text-3xl font-black text-medical-gray-900 mb-4">ترکیب علمی یافت نشد</h1>
|
||||
<Link href="/wiki" className="text-canina-blue font-bold flex items-center gap-2">
|
||||
<ChevronRight className="w-4 h-4" />
|
||||
بازگشت به دانشنامه
|
||||
@@ -45,32 +47,16 @@ export default async function BlogPage({ params }: { params: Promise<{ slug: str
|
||||
<div className="max-w-4xl mx-auto">
|
||||
<Link href="/wiki" className="inline-flex items-center gap-2 text-medical-gray-400 hover:text-canina-blue transition-colors font-bold mb-8">
|
||||
<ChevronRight className="w-5 h-5" />
|
||||
بازگشت به مقالات
|
||||
بازگشت به دانشنامه
|
||||
</Link>
|
||||
|
||||
{blog.imageUrl && (
|
||||
<div className="aspect-video rounded-[2rem] overflow-hidden mb-12 shadow-xl border border-medical-gray-100">
|
||||
<img src={blog.imageUrl} alt={blog.title} className="w-full h-full object-cover" />
|
||||
</div>
|
||||
)}
|
||||
|
||||
<h1 className="text-4xl lg:text-5xl font-black text-medical-gray-900 mb-6 leading-tight">
|
||||
{blog.title}
|
||||
{term.term}
|
||||
</h1>
|
||||
|
||||
<div className="flex items-center gap-4 text-sm font-bold text-medical-gray-400 mb-12 pb-8 border-b border-medical-gray-100">
|
||||
<span>نوشته شده در {new Date(blog.createdAt).toLocaleDateString('fa-IR')}</span>
|
||||
{blog.author && (
|
||||
<>
|
||||
<span className="w-1 h-1 rounded-full bg-medical-gray-300" />
|
||||
<span>توسط {blog.author.firstName} {blog.author.lastName}</span>
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<div
|
||||
className="prose prose-lg prose-medical-gray max-w-none prose-headings:font-black prose-p:leading-relaxed prose-a:text-canina-blue"
|
||||
dangerouslySetInnerHTML={{ __html: blog.content }}
|
||||
dangerouslySetInnerHTML={{ __html: term.definition }}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Reference in new issue
Block a user