Add headless CMS for official site content management

Integrate article and page management into the Laravel admin dashboard
to serve as a headless CMS for the Next.js frontend (usher-site).

Backend:
- 7 migrations: article_categories, article_tags, articles, pivots, attachments, pages
- 5 models with relationships: Article, ArticleCategory, ArticleTag, ArticleAttachment, Page
- 4 admin controllers: articles (with publish/archive/pin), categories, tags, pages
- Admin views with EasyMDE markdown editor, multi-select categories/tags
- Navigation section "官網管理" in admin sidebar

API (v1):
- GET /api/v1/articles (filtered by type, category, tag, search; paginated)
- GET /api/v1/articles/{slug} (with related articles)
- GET /api/v1/categories
- GET /api/v1/pages/{slug} (with children)
- GET /api/v1/homepage (aggregated homepage data)
- Attachment download endpoint
- CORS configured for usher.org.tw, vercel.app, localhost:3000

Content migration:
- ImportHugoContent command: imports Hugo markdown files as articles/pages
- Successfully imported 27 articles, 17 categories, 11 tags, 9 pages

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-02-07 11:58:22 +08:00
parent bfbec861d0
commit a30af8eaf7
45 changed files with 4816 additions and 31 deletions

View File

@@ -0,0 +1,34 @@
<?php
namespace App\Http\Resources;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;
class ArticleCollectionResource extends JsonResource
{
public function toArray(Request $request): array
{
return [
'id' => $this->id,
'title' => $this->title,
'slug' => $this->slug,
'summary' => $this->summary,
'excerpt' => $this->getExcerpt(200),
'content_type' => $this->content_type,
'content_type_label' => $this->getContentTypeLabel(),
'featured_image_url' => $this->featured_image_url,
'featured_image_alt' => $this->featured_image_alt,
'author_name' => $this->author_name,
'is_pinned' => $this->is_pinned,
'published_at' => $this->published_at?->toIso8601String(),
'categories' => CategoryResource::collection($this->whenLoaded('categories')),
'tags' => $this->whenLoaded('tags', function () {
return $this->tags->map(fn ($tag) => [
'name' => $tag->name,
'slug' => $tag->slug,
]);
}),
];
}
}

View File

@@ -0,0 +1,47 @@
<?php
namespace App\Http\Resources;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;
class ArticleResource extends JsonResource
{
public function toArray(Request $request): array
{
return [
'id' => $this->id,
'title' => $this->title,
'slug' => $this->slug,
'summary' => $this->summary,
'content' => $this->content,
'content_type' => $this->content_type,
'content_type_label' => $this->getContentTypeLabel(),
'featured_image_url' => $this->featured_image_url,
'featured_image_alt' => $this->featured_image_alt,
'author_name' => $this->author_name,
'meta_description' => $this->meta_description,
'meta_keywords' => $this->meta_keywords,
'is_pinned' => $this->is_pinned,
'view_count' => $this->view_count,
'published_at' => $this->published_at?->toIso8601String(),
'categories' => CategoryResource::collection($this->whenLoaded('categories')),
'tags' => $this->whenLoaded('tags', function () {
return $this->tags->map(fn ($tag) => [
'id' => $tag->id,
'name' => $tag->name,
'slug' => $tag->slug,
]);
}),
'attachments' => $this->whenLoaded('attachments', function () {
return $this->attachments->map(fn ($att) => [
'id' => $att->id,
'original_filename' => $att->original_filename,
'mime_type' => $att->mime_type,
'file_size' => $att->file_size,
'description' => $att->description,
]);
}),
];
}
}

View File

@@ -0,0 +1,20 @@
<?php
namespace App\Http\Resources;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;
class CategoryResource extends JsonResource
{
public function toArray(Request $request): array
{
return [
'id' => $this->id,
'name' => $this->name,
'slug' => $this->slug,
'description' => $this->description,
'articles_count' => $this->whenCounted('articles'),
];
}
}

View File

@@ -0,0 +1,25 @@
<?php
namespace App\Http\Resources;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;
class PageResource extends JsonResource
{
public function toArray(Request $request): array
{
return [
'id' => $this->id,
'title' => $this->title,
'slug' => $this->slug,
'content' => $this->content,
'template' => $this->template,
'custom_fields' => $this->custom_fields,
'meta_description' => $this->meta_description,
'meta_keywords' => $this->meta_keywords,
'published_at' => $this->published_at?->toIso8601String(),
'children' => PageResource::collection($this->whenLoaded('children')),
];
}
}