From 51771201e18f093685ecb099fa2420ecfc1d2c4e Mon Sep 17 00:00:00 2001 From: allenjiang Date: Sat, 21 Dec 2024 21:34:05 +0800 Subject: [PATCH] feat: add dynamic default preview image --- app/Http/Controllers/PreviewController.php | 19 +++++++ composer.json | 3 +- composer.lock | 50 ++++++++++++++++++- .../pages/posts/show-post-page.blade.php | 2 + routes/web.php | 3 ++ 5 files changed, 75 insertions(+), 2 deletions(-) create mode 100644 app/Http/Controllers/PreviewController.php diff --git a/app/Http/Controllers/PreviewController.php b/app/Http/Controllers/PreviewController.php new file mode 100644 index 00000000..8b4e24d7 --- /dev/null +++ b/app/Http/Controllers/PreviewController.php @@ -0,0 +1,19 @@ +size(width: 1200, height: 600) + ->backgroundColor('#14b8a6') + ->header(text: config('app.name'), color: 'white') + ->title(text: $post->title, color: 'white', fontSize: 60) + ->output(); + } +} diff --git a/composer.json b/composer.json index 1aeec169..a82b3006 100644 --- a/composer.json +++ b/composer.json @@ -24,7 +24,8 @@ "laravel/tinker": "^2.7", "league/flysystem-aws-s3-v3": "^3.0", "livewire/livewire": "^3.0", - "spatie/laravel-feed": "^4.1" + "spatie/laravel-feed": "^4.1", + "yilanboy/preview": "^1.0" }, "require-dev": { "barryvdh/laravel-debugbar": "^3.6", diff --git a/composer.lock b/composer.lock index a4014244..cd9d34ed 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "6a959023ac03e94f3b284441cf4e72e9", + "content-hash": "a157affefcf3a64160a448973f15a810", "packages": [ { "name": "algolia/algoliasearch-client-php", @@ -7337,6 +7337,54 @@ "source": "https://github.com/webmozarts/assert/tree/1.11.0" }, "time": "2022-06-03T18:03:27+00:00" + }, + { + "name": "yilanboy/preview", + "version": "1.0.1", + "source": { + "type": "git", + "url": "https://github.com/yilanboy/preview.git", + "reference": "f94079122f004af385d8edc07bee241b6a34588d" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/yilanboy/preview/zipball/f94079122f004af385d8edc07bee241b6a34588d", + "reference": "f94079122f004af385d8edc07bee241b6a34588d", + "shasum": "" + }, + "require": { + "ext-gd": "*", + "php": "^8.2" + }, + "require-dev": { + "pestphp/pest": "^3.0.0" + }, + "type": "library", + "autoload": { + "psr-4": { + "Yilanboy\\Preview\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "allenjiang", + "email": "allenjianggo@yahoo.com" + } + ], + "description": "Generate the preview image", + "keywords": [ + "image", + "preview" + ], + "support": { + "issues": "https://github.com/yilanboy/preview/issues", + "source": "https://github.com/yilanboy/preview/tree/1.0.1" + }, + "time": "2024-12-21T10:40:13+00:00" } ], "packages-dev": [ diff --git a/resources/views/livewire/pages/posts/show-post-page.blade.php b/resources/views/livewire/pages/posts/show-post-page.blade.php index 6b6d61e9..19d001b5 100644 --- a/resources/views/livewire/pages/posts/show-post-page.blade.php +++ b/resources/views/livewire/pages/posts/show-post-page.blade.php @@ -2,6 +2,8 @@ @if (!empty($post->preview_url)) @section('preview_url', $post->preview_url) +@else + @section('preview_url', route('posts.preview', $post->id)) @endif @assets diff --git a/routes/web.php b/routes/web.php index 8fad53ca..4b21e9b8 100644 --- a/routes/web.php +++ b/routes/web.php @@ -1,5 +1,6 @@ group(function () { Route::get('/', PostIndexPage::class)->name('posts.index'); + Route::get('/{post}/preview', PreviewController::class)->name('posts.preview'); + Route::middleware(['auth', 'verified'])->group(function () { Route::get('/create', CreatePostPage::class)->name('posts.create'); Route::get('/{id}/edit', EditPostPage::class)->name('posts.edit');