Skip to content

Commit bf0cb54

Browse files
committed
Fonts added
1 parent da7a372 commit bf0cb54

51 files changed

Lines changed: 573 additions & 137 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

app/Concerns/HasFont.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
namespace App\Concerns;
4+
5+
trait HasFont
6+
{
7+
public function toRegistry(): array
8+
{
9+
return array_filter([
10+
'name' => $this->name,
11+
'title' => $this->title,
12+
'type' => $this->type ?? 'registry:font',
13+
'meta' => $this->meta ?? ['category' => 'fonts', 'version' => '1.0.0'],
14+
'author' => $this->author ?? 'designbycode',
15+
'font' => array_filter([
16+
'family' => $this->font_family,
17+
'provider' => $this->font_provider ?? 'google',
18+
'import' => $this->font_import,
19+
'variable' => $this->font_variable,
20+
'weight' => $this->font_weight ?? [],
21+
'subsets' => $this->font_subsets ?? [],
22+
'selector' => $this->font_selector,
23+
'dependency' => $this->font_dependency,
24+
]),
25+
'registryDependencies' => $this->registryDependencies ?? [],
26+
], fn ($v) => ! is_null($v) && $v !== []);
27+
}
28+
}

app/Http/Controllers/AnimateController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ class AnimateController extends Controller
1010
{
1111
public function index()
1212
{
13-
$animates = Animate::all()->map(fn(Animate $a) => [
13+
$animates = Animate::all()->map(fn (Animate $a) => [
1414
'name' => $a->name,
1515
'title' => $a->title,
1616
'text' => Str::title(Str::replace('-', ' ', Str::after($a->name, 'animate-'))),
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
3+
namespace App\Http\Controllers;
4+
5+
use App\Models\Font;
6+
use Inertia\Inertia;
7+
8+
class FontsController extends Controller
9+
{
10+
public function index()
11+
{
12+
return Inertia::render('fonts/index', [
13+
'fonts' => Font::query()->orderBy('title')->get()->map(fn ($f) => [
14+
'name' => $f->name,
15+
'title' => $f->title,
16+
'fontFamily' => $f->font_family,
17+
'fontProvider' => $f->font_provider,
18+
'fontImport' => $f->font_import,
19+
'fontVariable' => $f->font_variable,
20+
'fontWeight' => $f->font_weight,
21+
'fontSubsets' => $f->font_subsets,
22+
'fontDependency' => $f->font_dependency,
23+
]),
24+
]);
25+
}
26+
27+
public function show(string $name)
28+
{
29+
$font = Font::where('name', $name)->firstOrFail();
30+
31+
return response()->json($font->toRegistry());
32+
}
33+
}

app/Models/Animate.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
class Animate extends Model
1313
{
1414
use HasAnimate, SoftDeletes;
15-
15+
1616
public function user(): BelongsTo
1717
{
1818
return $this->belongsTo(User::class);

app/Models/Font.php

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<?php
2+
3+
namespace App\Models;
4+
5+
use App\Concerns\HasFont;
6+
use Illuminate\Database\Eloquent\Attributes\Fillable;
7+
use Illuminate\Database\Eloquent\Model;
8+
use Illuminate\Database\Eloquent\Relations\BelongsTo;
9+
use Illuminate\Database\Eloquent\SoftDeletes;
10+
11+
#[Fillable([
12+
'name', 'title', 'type', 'author', 'user_id',
13+
'meta', 'categories',
14+
'registryDependencies', 'dependencies', 'devDependencies', 'files',
15+
'font_family', 'font_provider', 'font_import', 'font_variable',
16+
'font_weight', 'font_subsets', 'font_selector', 'font_dependency',
17+
])]
18+
class Font extends Model
19+
{
20+
use HasFont, SoftDeletes;
21+
22+
public function user(): BelongsTo
23+
{
24+
return $this->belongsTo(User::class);
25+
}
26+
27+
public function getRouteKeyName(): string
28+
{
29+
return 'name';
30+
}
31+
32+
protected function casts(): array
33+
{
34+
return [
35+
'meta' => 'array',
36+
'categories' => 'array',
37+
'registryDependencies' => 'array',
38+
'dependencies' => 'array',
39+
'devDependencies' => 'array',
40+
'files' => 'array',
41+
'font_weight' => 'array',
42+
'font_subsets' => 'array',
43+
'created_at' => 'datetime',
44+
'updated_at' => 'datetime',
45+
'deleted_at' => 'datetime',
46+
];
47+
}
48+
}
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
<?php
2+
3+
use Illuminate\Database\Migrations\Migration;
4+
use Illuminate\Database\Schema\Blueprint;
5+
use Illuminate\Support\Facades\DB;
6+
use Illuminate\Support\Facades\Schema;
7+
8+
return new class extends Migration
9+
{
10+
public function up(): void
11+
{
12+
Schema::create('fonts', function (Blueprint $table) {
13+
$table->id();
14+
15+
$table->foreignId('user_id')->nullable()->constrained('users')->cascadeOnDelete();
16+
17+
$table->string('name')->unique();
18+
$table->string('title')->nullable();
19+
$table->string('type')->default('registry:font');
20+
$table->string('author')->nullable();
21+
22+
$table->json('meta')->nullable();
23+
$table->json('categories')->nullable();
24+
25+
$table->json('registryDependencies')->nullable();
26+
$table->json('dependencies')->nullable();
27+
$table->json('devDependencies')->nullable();
28+
$table->json('files')->nullable();
29+
30+
$table->string('font_family')->nullable();
31+
$table->string('font_provider')->nullable()->default('google');
32+
$table->string('font_import')->nullable();
33+
$table->string('font_variable')->nullable();
34+
$table->json('font_weight')->nullable();
35+
$table->json('font_subsets')->nullable();
36+
$table->string('font_selector')->nullable();
37+
$table->string('font_dependency')->nullable();
38+
39+
$table->timestamps();
40+
$table->softDeletes();
41+
42+
$table->index('created_at');
43+
});
44+
45+
DB::statement('
46+
INSERT INTO fonts (
47+
name, title, type, author,
48+
meta, categories,
49+
registryDependencies, dependencies, devDependencies, files,
50+
font_family, font_provider, font_import, font_variable,
51+
font_weight, font_subsets, font_selector, font_dependency,
52+
created_at, updated_at, deleted_at
53+
)
54+
SELECT
55+
name, title, type, author,
56+
meta, categories,
57+
registryDependencies, dependencies, devDependencies, files,
58+
font_family, font_provider, font_import, font_variable,
59+
font_weight, font_subsets, font_selector, font_dependency,
60+
created_at, updated_at, deleted_at
61+
FROM registries
62+
WHERE type = \'registry:font\'
63+
');
64+
65+
DB::table('registries')->where('type', 'registry:font')->delete();
66+
}
67+
68+
public function down(): void
69+
{
70+
$fonts = DB::table('fonts')->get();
71+
72+
foreach ($fonts as $font) {
73+
$data = (array) $font;
74+
$data['type'] = 'registry:font';
75+
unset($data['id'], $data['user_id']);
76+
DB::table('registries')->insert($data);
77+
}
78+
79+
Schema::dropIfExists('fonts');
80+
}
81+
};

database/seeders/DatabaseSeeder.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ public function run(): void
2424
$this->call([
2525
ThemeSeeder::class,
2626
AnimateSeeder::class,
27+
FontSeeder::class,
2728
]);
2829
}
2930
}

database/seeders/FontSeeder.php

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
<?php
2+
3+
namespace Database\Seeders;
4+
5+
use App\Models\Font;
6+
use Illuminate\Database\Seeder;
7+
8+
class FontSeeder extends Seeder
9+
{
10+
public function run(): void
11+
{
12+
if (Font::count() > 0) {
13+
$this->command->warn('Fonts table is not empty — skipping seeder.');
14+
15+
return;
16+
}
17+
18+
$total = 0;
19+
20+
foreach (static::fonts() as $font) {
21+
Font::create($font);
22+
$total++;
23+
}
24+
25+
$this->command->info("Seeded {$total} fonts.");
26+
}
27+
28+
/**
29+
* @return list<array<string, mixed>>
30+
*/
31+
private static function fonts(): array
32+
{
33+
$registry = json_decode(
34+
file_get_contents(base_path('registry.json')),
35+
true,
36+
512,
37+
JSON_THROW_ON_ERROR
38+
);
39+
40+
$fonts = [];
41+
42+
foreach ($registry['items'] ?? [] as $item) {
43+
if (($item['type'] ?? '') !== 'registry:font') {
44+
continue;
45+
}
46+
47+
$font = $item['font'] ?? [];
48+
49+
$fonts[] = [
50+
'name' => $item['name'],
51+
'title' => $item['title'],
52+
'type' => 'registry:font',
53+
'author' => $item['author'] ?? 'designbycode',
54+
'meta' => $item['meta'] ?? ['category' => 'fonts', 'version' => '1.0.0'],
55+
'registryDependencies' => $item['registryDependencies'] ?? [],
56+
'font_family' => $font['family'] ?? null,
57+
'font_provider' => $font['provider'] ?? 'google',
58+
'font_import' => $font['import'] ?? null,
59+
'font_variable' => $font['variable'] ?? null,
60+
'font_weight' => $font['weight'] ?? [],
61+
'font_subsets' => $font['subsets'] ?? [],
62+
'font_selector' => $font['selector'] ?? null,
63+
'font_dependency' => $font['dependency'] ?? null,
64+
];
65+
}
66+
67+
return $fonts;
68+
}
69+
}

public/build/assets/animate-css-D2kkQJIA.js

Lines changed: 0 additions & 7 deletions
This file was deleted.

public/build/assets/animate-css-DIp07okz.js

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)