Skip to content

Commit

Permalink
5 simplify overriding routes and controllers (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
benbjurstrom authored Jun 29, 2024
1 parent adb1293 commit f6e6bc9
Show file tree
Hide file tree
Showing 9 changed files with 16 additions and 21 deletions.
12 changes: 0 additions & 12 deletions config/prezet.php
Original file line number Diff line number Diff line change
@@ -1,18 +1,6 @@
<?php

return [
/*
|--------------------------------------------------------------------------
| Blog Path
|--------------------------------------------------------------------------
|
| This is the path to the blog. It is used to generate the routes for the
| blog posts. The path should not have a leading or trailing slash.
|
*/

'path' => 'prezet',

/*
|--------------------------------------------------------------------------
| Data Classes
Expand Down
6 changes: 3 additions & 3 deletions routes/web.php → routes/prezet.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,18 @@
use BenBjurstrom\Prezet\Http\Controllers\ShowController;
use Illuminate\Support\Facades\Route;

Route::get(config('prezet.image.path').'{path}', ImageController::class)
Route::get('prezet/{path}', ImageController::class)
->name('prezet.image')
->where('path', '.*');

Route::get('/prezet/ogimage/{slug}', OgimageController::class)
->name('prezet.ogimage')
->where('slug', '.*');

Route::get(config('prezet.path'), IndexController::class)
Route::get('prezet', IndexController::class)
->name('prezet.index');

Route::get(config('prezet.path').'/{slug}', ShowController::class)
Route::get('prezet/{slug}', ShowController::class)
->name('prezet.show')
->where('slug', '.*');
// https://laravel.com/docs/11.x/routing#parameters-encoded-forward-slashes
8 changes: 8 additions & 0 deletions src/Commands/InstallCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public function handle(): int
{
// Add the prezet disk to the filesystems config
$this->addStorageDisk();
$this->addRoutes();
$this->copyContentStubs();
$this->publishVendorFiles();
$this->copyTailwindFiles();
Expand All @@ -25,6 +26,13 @@ public function handle(): int
return self::SUCCESS;
}

protected function addRoutes()
{
$files = new Filesystem;
$files->copy(__DIR__.'/../../routes/prezet.php', base_path('routes/prezet.php'));
$files->append(base_path('routes/web.php'), "require __DIR__.'/prezet.php';");
}

protected function copyTailwindFiles()
{
$files = new Filesystem;
Expand Down
1 change: 0 additions & 1 deletion src/PrezetServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ public function configurePackage(Package $package): void
->name('prezet')
->hasConfigFile()
->hasViews('prezet')
->hasRoute('web')
->hasCommands([
OgimageCommand::class,
InstallCommand::class,
Expand Down
2 changes: 1 addition & 1 deletion stubs/prezet/.obsidian/app.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@
"tabSize": 2,
"newFileLocation": "folder",
"newFileFolderPath": "content"
}
}
2 changes: 1 addition & 1 deletion stubs/prezet/.obsidian/appearance.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"accentColor": ""
}
}
2 changes: 1 addition & 1 deletion stubs/prezet/.obsidian/community-plugins.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[
"image-converter",
"janitor"
]
]
2 changes: 1 addition & 1 deletion stubs/prezet/.obsidian/core-plugins-migration.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,4 @@
"file-recovery": true,
"publish": false,
"sync": false
}
}
2 changes: 1 addition & 1 deletion stubs/prezet/.obsidian/core-plugins.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@
"outline",
"word-count",
"file-recovery"
]
]

0 comments on commit f6e6bc9

Please sign in to comment.