Keep the public site readable after import (nbsp, highlighter, wrapping code, compact pager) and finish the admin extras already in this tree: sticky levels, preview, page cache, and live llms.txt. Co-authored-by: Cursor <cursoragent@cursor.com>
114 lines
4.2 KiB
PHP
114 lines
4.2 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Filament\Resources\Posts\Tables;
|
|
|
|
use App\Models\Post;
|
|
use Filament\Actions\Action;
|
|
use Filament\Actions\BulkActionGroup;
|
|
use Filament\Actions\DeleteBulkAction;
|
|
use Filament\Actions\EditAction;
|
|
use Filament\Actions\ViewAction;
|
|
use Filament\Support\Enums\Width;
|
|
use Filament\Tables\Columns\TextColumn;
|
|
use Filament\Tables\Enums\FiltersLayout;
|
|
use Filament\Tables\Filters\SelectFilter;
|
|
use Filament\Tables\Table;
|
|
|
|
class PostsTable
|
|
{
|
|
public static function configure(Table $table): Table
|
|
{
|
|
return $table
|
|
->columns([
|
|
TextColumn::make('title')
|
|
->label('标题')
|
|
->searchable()
|
|
->limit(40)
|
|
->description(fn ($record) => $record->category?->name),
|
|
TextColumn::make('content_format')
|
|
->label('格式')
|
|
->badge()
|
|
->formatStateUsing(fn ($state) => $state === 'markdown' ? 'MD' : 'HTML')
|
|
->color(fn ($state) => $state === 'markdown' ? 'success' : 'gray'),
|
|
TextColumn::make('status')
|
|
->label('状态')
|
|
->badge()
|
|
->formatStateUsing(fn ($state) => match ($state) {
|
|
'published' => '已发布',
|
|
'draft' => '草稿',
|
|
'private' => '私密',
|
|
default => $state,
|
|
})
|
|
->color(fn ($state) => match ($state) {
|
|
'published' => 'success',
|
|
'draft' => 'warning',
|
|
default => 'gray',
|
|
}),
|
|
TextColumn::make('sticky_level')
|
|
->label('置顶')
|
|
->badge()
|
|
->sortable()
|
|
->formatStateUsing(fn ($state) => Post::stickyLevelOptions()[(int) $state] ?? '不置顶')
|
|
->color(fn ($state) => match ((int) $state) {
|
|
Post::STICKY_HEADLINE => 'danger',
|
|
Post::STICKY_STRONG => 'warning',
|
|
Post::STICKY_LIGHT => 'success',
|
|
default => 'gray',
|
|
}),
|
|
TextColumn::make('views')
|
|
->label('阅读')
|
|
->numeric()
|
|
->sortable(),
|
|
TextColumn::make('comment_count')
|
|
->label('评论')
|
|
->numeric()
|
|
->sortable(),
|
|
TextColumn::make('published_at')
|
|
->label('发布时间')
|
|
->dateTime('Y-m-d H:i')
|
|
->sortable(),
|
|
])
|
|
->filters([
|
|
SelectFilter::make('category_id')
|
|
->label('分类')
|
|
->relationship('category', 'name'),
|
|
SelectFilter::make('status')
|
|
->label('状态')
|
|
->options([
|
|
'published' => '已发布',
|
|
'draft' => '草稿',
|
|
'private' => '私密',
|
|
]),
|
|
SelectFilter::make('content_format')
|
|
->label('格式')
|
|
->options([
|
|
'markdown' => 'Markdown',
|
|
'html' => 'HTML',
|
|
]),
|
|
SelectFilter::make('sticky_level')
|
|
->label('置顶')
|
|
->options(Post::stickyLevelOptions()),
|
|
], FiltersLayout::AboveContent)
|
|
->filtersFormColumns(3)
|
|
->filtersFormWidth(Width::ThreeExtraLarge)
|
|
->recordActions([
|
|
Action::make('preview')
|
|
->label('预览')
|
|
->url(fn (Post $record): string => $record->url)
|
|
->openUrlInNewTab(),
|
|
ViewAction::make(),
|
|
EditAction::make(),
|
|
])
|
|
->recordUrl(null)
|
|
->recordAction(null)
|
|
->toolbarActions([
|
|
BulkActionGroup::make([
|
|
DeleteBulkAction::make(),
|
|
]),
|
|
])
|
|
->defaultSort('published_at', 'desc');
|
|
}
|
|
}
|