Skip to content

Commit

Permalink
Remove manual open graph asset
Browse files Browse the repository at this point in the history
  • Loading branch information
inxilpro committed Nov 15, 2024
1 parent 4c0f1ce commit 7ca82d2
Show file tree
Hide file tree
Showing 10 changed files with 46 additions and 18 deletions.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ To start a PHP× group:
"region": "<<short city or region name>>", // can be null if airport code is good enough
"description": "<<short description>>",
"timezone": "<<php-compatible timezone ID>>",
"og_asset": "<<include image in public/og/ in pr>>", // can be null
"bsky_url": "https://bsky.app/profile/<<group profile>>" // can be null
},
```
Expand Down
5 changes: 0 additions & 5 deletions app/Actions/ConfigureGroup.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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();
Expand Down Expand Up @@ -73,15 +71,13 @@ 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],
['Description', $description],
['Timezone', $timezone],
['Bluesky', $bsky_url],
['Meetup', $meetup_url],
['Open Graph Image', $og_asset],
]);

if (confirm('Is this correct?')) {
Expand All @@ -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
Expand Down
1 change: 0 additions & 1 deletion app/Actions/SyncGroups.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ protected function syncConfigWithGroup(string $domain, array $config): Group
'timezone',
'bsky_url',
'meetup_url',
'og_asset',
]));

return $group;
Expand Down
23 changes: 23 additions & 0 deletions app/Models/Group.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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;
});
}
}

21 changes: 21 additions & 0 deletions database/migrations/2024_11_15_124406_remove_og_asset.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration {
public function up(): void
{
Schema::table('groups', function(Blueprint $table) {
$table->dropColumn('og_asset');
});
}

public function down(): void
{
Schema::table('groups', function(Blueprint $table) {
$table->string('og_asset')->nullable();
});
}
};
3 changes: 0 additions & 3 deletions database/seeders/GroupSeeder.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand Down
1 change: 0 additions & 1 deletion groups.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
1 change: 0 additions & 1 deletion resources/markdown/organizers.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ To start a PHP× group:
"region": "<<short city or region name>>", // can be null if airport code is good enough
"description": "<<short description>>",
"timezone": "<<php-compatible timezone ID>>",
"og_asset": "<<include image in public/og/ in pr>>", // can be null
"bsky_url": "https://bsky.app/profile/<<group profile>>" // can be null
},
```
4 changes: 2 additions & 2 deletions resources/views/components/layout.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@
<meta name="description" content="{{ $group->description }}" />
<meta property="og:description" content="{{ $group->description }}" />
@endif
@if($group->og_asset)
<meta property="og:image" content="{{ asset("og/{$group->og_asset}") }}" />
@if($group->open_graph_image_url)
<meta property="og:image" content="{{ $group->open_graph_image_url }}" />
@endif
@endif
@endisset
Expand Down
4 changes: 0 additions & 4 deletions tests/Feature/GroupsJsonTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
Expand Down

0 comments on commit 7ca82d2

Please sign in to comment.