Add comprehensive page management system to admin dashboard
Features added: - Database schema for pages and media files with content types (Rich Text, HTML, Markdown) - Admin API routes for full page CRUD operations - Image upload functionality with file management - Rich text editor using TinyMCE with image insertion - Admin interface for creating/editing pages with SEO options - Dynamic navigation and footer integration - Public page display routes with proper SEO metadata - Support for featured images and content excerpts Admin features: - Create/edit/delete pages with rich content editor - Upload and manage images through media library - Configure pages to appear in navigation or footer - Set page status (Draft, Published, Archived) - SEO title and description management - Real-time preview of content changes 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
47
app/api/pages/[slug]/route.ts
Normal file
47
app/api/pages/[slug]/route.ts
Normal file
@@ -0,0 +1,47 @@
|
||||
import { NextRequest, NextResponse } from 'next/server';
|
||||
import { prisma } from '@/lib/db';
|
||||
|
||||
export async function GET(
|
||||
request: NextRequest,
|
||||
{ params }: { params: { slug: string } }
|
||||
) {
|
||||
try {
|
||||
const page = await prisma.page.findUnique({
|
||||
where: {
|
||||
slug: params.slug,
|
||||
status: 'PUBLISHED'
|
||||
},
|
||||
select: {
|
||||
id: true,
|
||||
title: true,
|
||||
slug: true,
|
||||
content: true,
|
||||
contentType: true,
|
||||
excerpt: true,
|
||||
featuredImage: true,
|
||||
seoTitle: true,
|
||||
seoDescription: true,
|
||||
publishedAt: true,
|
||||
updatedAt: true
|
||||
}
|
||||
});
|
||||
|
||||
if (!page) {
|
||||
return NextResponse.json(
|
||||
{ success: false, error: 'Page not found' },
|
||||
{ status: 404 }
|
||||
);
|
||||
}
|
||||
|
||||
return NextResponse.json({
|
||||
success: true,
|
||||
data: page
|
||||
});
|
||||
} catch (error) {
|
||||
console.error('Error fetching page by slug:', error);
|
||||
return NextResponse.json(
|
||||
{ success: false, error: 'Failed to fetch page' },
|
||||
{ status: 500 }
|
||||
);
|
||||
}
|
||||
}
|
||||
53
app/api/pages/route.ts
Normal file
53
app/api/pages/route.ts
Normal file
@@ -0,0 +1,53 @@
|
||||
import { NextRequest, NextResponse } from 'next/server';
|
||||
import { prisma } from '@/lib/db';
|
||||
|
||||
export async function GET(request: NextRequest) {
|
||||
try {
|
||||
const { searchParams } = new URL(request.url);
|
||||
const location = searchParams.get('location'); // 'navigation', 'footer', or 'all'
|
||||
|
||||
const where: any = {
|
||||
status: 'PUBLISHED'
|
||||
};
|
||||
|
||||
if (location === 'navigation') {
|
||||
where.showInNavigation = true;
|
||||
} else if (location === 'footer') {
|
||||
where.showInFooter = true;
|
||||
}
|
||||
|
||||
const orderBy: any = [];
|
||||
if (location === 'navigation') {
|
||||
orderBy.push({ navigationOrder: 'asc' });
|
||||
} else if (location === 'footer') {
|
||||
orderBy.push({ footerOrder: 'asc' });
|
||||
}
|
||||
orderBy.push({ title: 'asc' });
|
||||
|
||||
const pages = await prisma.page.findMany({
|
||||
where,
|
||||
orderBy,
|
||||
select: {
|
||||
id: true,
|
||||
title: true,
|
||||
slug: true,
|
||||
excerpt: true,
|
||||
showInNavigation: true,
|
||||
showInFooter: true,
|
||||
navigationOrder: true,
|
||||
footerOrder: true
|
||||
}
|
||||
});
|
||||
|
||||
return NextResponse.json({
|
||||
success: true,
|
||||
data: pages
|
||||
});
|
||||
} catch (error) {
|
||||
console.error('Error fetching public pages:', error);
|
||||
return NextResponse.json(
|
||||
{ success: false, error: 'Failed to fetch pages' },
|
||||
{ status: 500 }
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user