From 7ca82d2c6c250e321723fdd5a6f821fe69bc0a7d Mon Sep 17 00:00:00 2001 From: Chris Morrell Date: Fri, 15 Nov 2024 07:52:42 -0500 Subject: [PATCH] Remove manual open graph asset --- README.md | 1 - app/Actions/ConfigureGroup.php | 5 ---- app/Actions/SyncGroups.php | 1 - app/Models/Group.php | 23 +++++++++++++++++++ .../2024_11_15_124406_remove_og_asset.php | 21 +++++++++++++++++ database/seeders/GroupSeeder.php | 3 --- groups.json | 1 - resources/markdown/organizers.md | 1 - resources/views/components/layout.blade.php | 4 ++-- tests/Feature/GroupsJsonTest.php | 4 ---- 10 files changed, 46 insertions(+), 18 deletions(-) create mode 100644 database/migrations/2024_11_15_124406_remove_og_asset.php diff --git a/README.md b/README.md index 5bc0a7d..6b9e6d3 100644 --- a/README.md +++ b/README.md @@ -34,7 +34,6 @@ To start a PHP× group: "region": "<>", // can be null if airport code is good enough "description": "<>", "timezone": "<>", - "og_asset": "<>", // can be null "bsky_url": "https://bsky.app/profile/<>" // can be null }, ``` diff --git a/app/Actions/ConfigureGroup.php b/app/Actions/ConfigureGroup.php index 9faf7df..45e5cfa 100644 --- a/app/Actions/ConfigureGroup.php +++ b/app/Actions/ConfigureGroup.php @@ -24,7 +24,6 @@ public function handle( string $timezone = 'America/New_York', // One true timezone ?string $bsky_url = null, ?string $meetup_url = null, - ?string $og_asset = null, ): Group { $group = Group::updateOrCreate([ 'domain' => $domain, @@ -35,7 +34,6 @@ public function handle( 'timezone' => $timezone, 'bsky_url' => $bsky_url ?: null, 'meetup_url' => $meetup_url ?: null, - 'og_asset' => $og_asset ?: null, ]); Cache::clear(); @@ -73,7 +71,6 @@ public function asCommand(Command $command): int $timezone = suggest('Timezone', DateTimeZone::listIdentifiers(), default: str($existing->timezone), required: true); $bsky_url = text('Is there a Bluesky URL?', default: str($existing->bsky_url)); $meetup_url = text('Is there a Meetup URL?', default: str($existing->meetup_url)); - $og_asset = text('What is the open graph image name?', default: str($existing->og_asset)); table(['Option', 'Value'], [ ['Name', $name], @@ -81,7 +78,6 @@ public function asCommand(Command $command): int ['Timezone', $timezone], ['Bluesky', $bsky_url], ['Meetup', $meetup_url], - ['Open Graph Image', $og_asset], ]); if (confirm('Is this correct?')) { @@ -93,7 +89,6 @@ public function asCommand(Command $command): int timezone: $timezone, bsky_url: $bsky_url, meetup_url: $meetup_url, - og_asset: $og_asset, ); $command->info($group->wasRecentlyCreated diff --git a/app/Actions/SyncGroups.php b/app/Actions/SyncGroups.php index 27f15c9..4c133b2 100644 --- a/app/Actions/SyncGroups.php +++ b/app/Actions/SyncGroups.php @@ -72,7 +72,6 @@ protected function syncConfigWithGroup(string $domain, array $config): Group 'timezone', 'bsky_url', 'meetup_url', - 'og_asset', ])); return $group; diff --git a/app/Models/Group.php b/app/Models/Group.php index 54266ba..1773a14 100644 --- a/app/Models/Group.php +++ b/app/Models/Group.php @@ -4,6 +4,7 @@ use Glhd\Bits\Database\HasSnowflakes; use Illuminate\Container\Container; +use Illuminate\Database\Eloquent\Casts\Attribute; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\BelongsToMany; @@ -12,6 +13,7 @@ use Illuminate\Routing\UrlGenerator; use Illuminate\Support\Facades\App; use Illuminate\Support\Facades\Cache; +use Illuminate\Support\Stringable; use Revolution\Bluesky\Contracts\Factory; use Revolution\Bluesky\Facades\Bluesky; use Spatie\MailcoachSdk\Mailcoach; @@ -118,5 +120,26 @@ public function mailcoach_transactional_emails(): HasMany { return $this->hasMany(MailcoachTransactionalEmail::class); } + + protected function airportCode(): Attribute + { + return Attribute::get( + fn(): Stringable => str($this->name)->afterLast('×')->trim()->upper(), + ); + } + + protected function openGraphImageUrl(): Attribute + { + return Attribute::get(function() { + $filename = $this->airport_code->lower()->finish('.png'); + $path = public_path("og/{$filename}"); + + if (file_exists($path)) { + return asset("og/{$filename}").'?t='.filemtime($path); + } + + return null; + }); + } } diff --git a/database/migrations/2024_11_15_124406_remove_og_asset.php b/database/migrations/2024_11_15_124406_remove_og_asset.php new file mode 100644 index 0000000..c30eed3 --- /dev/null +++ b/database/migrations/2024_11_15_124406_remove_og_asset.php @@ -0,0 +1,21 @@ +dropColumn('og_asset'); + }); + } + + public function down(): void + { + Schema::table('groups', function(Blueprint $table) { + $table->string('og_asset')->nullable(); + }); + } +}; diff --git a/database/seeders/GroupSeeder.php b/database/seeders/GroupSeeder.php index e9b64d2..2bffffd 100644 --- a/database/seeders/GroupSeeder.php +++ b/database/seeders/GroupSeeder.php @@ -16,7 +16,6 @@ public function run(): void 'twitter_url' => 'https://twitter.com/joetannenbaum', 'meetup_url' => 'https://www.meetup.com/php-nyc/', 'description' => 'A fresh PHP meetup for NYC area devs.', - 'og_asset' => 'nyc.png', ]); app()->instance('group:phpxnyc.com', $nyc); @@ -28,7 +27,6 @@ public function run(): void 'twitter_url' => 'https://twitter.com/inxilpro', 'meetup_url' => 'https://www.meetup.com/php-philly/', 'description' => 'A Philly-area PHP meetup for web artisans who want to learn and connect.', - 'og_asset' => 'philly.png', ]); app()->instance('group:phpxphilly.com', $philly); @@ -40,7 +38,6 @@ public function run(): void 'twitter_url' => 'https://twitter.com/skylerkatz', 'meetup_url' => 'https://www.meetup.com/php-stl/', 'description' => 'A St. Louis-area PHP meetup for web artisans who want to learn and connect.', - 'og_asset' => 'stl.png', ]); app()->instance('group:phpxstl.com', $stl); diff --git a/groups.json b/groups.json index 34ff952..06c85c5 100644 --- a/groups.json +++ b/groups.json @@ -5,7 +5,6 @@ "region": null, "description": "A Philly-area PHP meetup for web artisans who want to learn and connect.", "timezone": "America/New_York", - "og_asset": "philly.png", "bsky_url": "https://bsky.app/profile/phpxphilly.com" }, "upstatephp.com": { diff --git a/resources/markdown/organizers.md b/resources/markdown/organizers.md index 55e9495..67fa7ec 100644 --- a/resources/markdown/organizers.md +++ b/resources/markdown/organizers.md @@ -16,7 +16,6 @@ To start a PHP× group: "region": "<>", // can be null if airport code is good enough "description": "<>", "timezone": "<>", - "og_asset": "<>", // can be null "bsky_url": "https://bsky.app/profile/<>" // can be null }, ``` diff --git a/resources/views/components/layout.blade.php b/resources/views/components/layout.blade.php index 6247272..e08be40 100644 --- a/resources/views/components/layout.blade.php +++ b/resources/views/components/layout.blade.php @@ -31,8 +31,8 @@ @endif - @if($group->og_asset) - og_asset}") }}" /> + @if($group->open_graph_image_url) + @endif @endif @endisset diff --git a/tests/Feature/GroupsJsonTest.php b/tests/Feature/GroupsJsonTest.php index 620d2b1..a6ea006 100644 --- a/tests/Feature/GroupsJsonTest.php +++ b/tests/Feature/GroupsJsonTest.php @@ -30,10 +30,6 @@ protected function assertValidGroup(string $domain, array $config): void Assert::assertNotEmpty(data_get($config, 'description')); Assert::assertContains(data_get($config, 'timezone'), \DateTimeZone::listIdentifiers()); - if ($og_asset = data_get($config, 'og_asset')) { - Assert::assertFileExists(public_path("og/{$og_asset}")); - } - if ($bsky_url = data_get($config, 'bsky_url')) { Assert::assertEquals(200, Http::get($bsky_url)->status()); }