From 1a0172d1f1a0062e3a5db4d2a20900882e37c806 Mon Sep 17 00:00:00 2001 From: Ash Monsh Date: Tue, 26 Sep 2023 07:29:42 +0300 Subject: [PATCH] updating Configuration --- routes/web.php | 29 +++---- src/Configuration.php | 183 +++++++++++++++++++++++++++--------------- src/Models/Post.php | 4 +- 3 files changed, 136 insertions(+), 80 deletions(-) diff --git a/routes/web.php b/routes/web.php index 86a84cd..8f3faee 100644 --- a/routes/web.php +++ b/routes/web.php @@ -1,14 +1,15 @@ middleware(config('zeus-sky.middleware')) ->group(function () { - if (in_array('FaqResource', config('zeus-sky.enabledResources'))) { - Route::get(config('zeus-sky.uriPrefix.faq'), Faq::class) + if (in_array('faq', config('zeus-sky.uri'))) { + Route::get(config('zeus-sky.uri.faq'), Faq::class) ->name('faq'); } - if (in_array('LibraryResource', config('zeus-sky.enabledResources'))) { - Route::prefix(config('zeus-sky.uriPrefix.library')) + if (in_array('library', config('zeus-sky.uri'))) { + Route::prefix(config('zeus-sky.uri.library')) ->group(function () { Route::get('/', Library::class)->name('library'); Route::get('/tag/{slug}', LibraryTag::class)->name('library.tag'); @@ -48,7 +49,7 @@ ->name('passwordConfirmation');*/ Route::get('/', Posts::class)->name('blogs'); - Route::get(config('zeus-sky.uriPrefix.post') . '/{slug}', Post::class)->name('post'); - Route::get(config('zeus-sky.uriPrefix.page') . '/{slug}', Page::class)->name('page'); + Route::get(config('zeus-sky.uri.post') . '/{slug}', Post::class)->name('post'); + Route::get(config('zeus-sky.uri.page') . '/{slug}', Page::class)->name('page'); Route::get('{type}/{slug}', Tags::class)->name('tags'); }); diff --git a/src/Configuration.php b/src/Configuration.php index 5d69c23..8d51121 100644 --- a/src/Configuration.php +++ b/src/Configuration.php @@ -7,17 +7,20 @@ trait Configuration { /** + * @deprecated deprecated since version 3.2 * set the default path for the blog homepage. */ protected Closure | string $skyPrefix = 'sky'; /** + * @deprecated deprecated since version 3.2 * the middleware you want to apply on all the blog routes * for example if you want to make your blog for users only, add the middleware 'auth'. */ protected array $skyMiddleware = ['web']; /** + * @deprecated deprecated since version 3.2 * URI prefix for each content type */ protected array $uriPrefix = [ @@ -27,26 +30,12 @@ trait Configuration 'faq' => 'faq', ]; - protected bool $hasPostResource = true; - - protected bool $hasPageResource = true; - - protected bool $hasFaqResource = true; - - protected bool $hasLibraryResource = true; - protected Closure | string $navigationGroupLabel = 'Sky'; /** * you can overwrite any model and use your own */ - protected array $skyModels = [ - 'Faq' => \LaraZeus\Sky\Models\Faq::class, - 'Post' => \LaraZeus\Sky\Models\Post::class, - 'PostStatus' => \LaraZeus\Sky\Models\PostStatus::class, - 'Tag' => \LaraZeus\Sky\Models\Tag::class, - 'Library' => \LaraZeus\Sky\Models\Library::class, - ]; + protected array $skyModels = []; /** * the default editor for pages and posts, Available: @@ -58,6 +47,8 @@ trait Configuration protected string $editor = Editors\MarkdownEditor::class; /** + * @deprecated deprecated since version 3.2 + * * parse the content * you can add any parser to do str_replace or any other operation: * @@ -68,22 +59,30 @@ trait Configuration ]; /** + * @deprecated deprecated since version 3.2 + * * for the frontend */ protected int $recentPostsLimit = 5; /** + * @deprecated deprecated since version 3.2 + * * css class to apply on found search result, e.g. `bg-yellow-400`. */ protected string $searchResultHighlightCssClass = 'highlight'; /** + * @deprecated deprecated since version 3.2 + * * supply a list of terms that will disable the search highlight to not * destroy html structure. */ protected array $skipHighlightingTerms = ['iframe']; /** + * @deprecated deprecated since version 3.2 + * * default featured image, set to null to disable it. * ex: https://placehold.co/600x400 */ @@ -112,6 +111,17 @@ trait Configuration */ protected Closure | string $uploadDirectory = ''; + protected bool $hasPostResource = true; + + protected bool $hasPageResource = true; + + protected bool $hasFaqResource = true; + + protected bool $hasLibraryResource = true; + + /* + * @deprecated deprecated since version 3.2 + */ public function skyPrefix(Closure | string $prefix): static { $this->skyPrefix = $prefix; @@ -119,11 +129,17 @@ public function skyPrefix(Closure | string $prefix): static return $this; } + /* + * @deprecated deprecated since version 3.2 + */ public function getSkyPrefix(): Closure | string { return $this->evaluate($this->skyPrefix); } + /* + * @deprecated deprecated since version 3.2 + */ public function skyMiddleware(array $middleware): static { $this->skyMiddleware = $middleware; @@ -131,59 +147,14 @@ public function skyMiddleware(array $middleware): static return $this; } + /* + * @deprecated deprecated since version 3.2 + */ public function getMiddleware(): array { return $this->skyMiddleware; } - public function postResource(bool $condition = true): static - { - $this->hasPostResource = $condition; - - return $this; - } - - public function hasPostResource(): bool - { - return $this->hasPostResource; - } - - public function pageResource(bool $condition = true): static - { - $this->hasPageResource = $condition; - - return $this; - } - - public function hasPageResource(): bool - { - return $this->hasPageResource; - } - - public function faqResource(bool $condition = true): static - { - $this->hasFaqResource = $condition; - - return $this; - } - - public function hasFaqResource(): bool - { - return $this->hasFaqResource; - } - - public function libraryResource(bool $condition = true): static - { - $this->hasLibraryResource = $condition; - - return $this; - } - - public function hasLibraryResource(): bool - { - return $this->hasLibraryResource; - } - public function navigationGroupLabel(Closure | string $lable): static { $this->navigationGroupLabel = $lable; @@ -211,7 +182,7 @@ public function getSkyModels(): array public static function getModel(string $model): string { return array_merge( - (new static())->skyModels, + config('zeus-sky.models'), (new static())::get()->getSkyModels() )[$model]; } @@ -228,6 +199,9 @@ public function getEditor(): string return $this->editor; } + /* + * @deprecated deprecated since version 3.2 + */ public function parsers(array $parsers): static { $this->parsers = $parsers; @@ -235,11 +209,17 @@ public function parsers(array $parsers): static return $this; } + /* + * @deprecated deprecated since version 3.2 + */ public function getParsers(): array { return $this->parsers; } + /* + * @deprecated deprecated since version 3.2 + */ public function recentPostsLimit(int $limit): static { $this->recentPostsLimit = $limit; @@ -247,6 +227,9 @@ public function recentPostsLimit(int $limit): static return $this; } + /* + * @deprecated deprecated since version 3.2 + */ public function getRecentPostsLimit(): int { return $this->recentPostsLimit; @@ -276,6 +259,9 @@ public function getTagTypes(): ?array return $this->tagTypes; } + /* + * @deprecated deprecated since version 3.2 + */ public function uriPrefix(array $prefix): static { $this->uriPrefix = $prefix; @@ -283,11 +269,17 @@ public function uriPrefix(array $prefix): static return $this; } + /* + * @deprecated deprecated since version 3.2 + */ public function getUriPrefix(): array { return $this->uriPrefix; } + /* + * @deprecated deprecated since version 3.2 + */ public function searchResultHighlightCssClass(string $class): static { $this->searchResultHighlightCssClass = $class; @@ -295,11 +287,17 @@ public function searchResultHighlightCssClass(string $class): static return $this; } + /* + * @deprecated deprecated since version 3.2 + */ public function getSearchResultHighlightCssClass(): string { return $this->searchResultHighlightCssClass; } + /* + * @deprecated deprecated since version 3.2 + */ public function skipHighlightingTerms(array $skip): static { $this->skipHighlightingTerms = $skip; @@ -307,11 +305,17 @@ public function skipHighlightingTerms(array $skip): static return $this; } + /* + * @deprecated deprecated since version 3.2 + */ public function getSkipHighlightingTerms(): array { return $this->skipHighlightingTerms; } + /* + * @deprecated deprecated since version 3.2 + */ public function defaultFeaturedImage(string $image): static { $this->defaultFeaturedImage = $image; @@ -319,6 +323,9 @@ public function defaultFeaturedImage(string $image): static return $this; } + /* + * @deprecated deprecated since version 3.2 + */ public function getDefaultFeaturedImage(): ?string { return $this->defaultFeaturedImage; @@ -347,4 +354,52 @@ public function getUploadDirectory(): Closure | string { return $this->evaluate($this->uploadDirectory); } + + public function postResource(bool $condition = true): static + { + $this->hasPostResource = $condition; + + return $this; + } + + public function hasPostResource(): bool + { + return $this->hasPostResource; + } + + public function pageResource(bool $condition = true): static + { + $this->hasPageResource = $condition; + + return $this; + } + + public function hasPageResource(): bool + { + return $this->hasPageResource; + } + + public function faqResource(bool $condition = true): static + { + $this->hasFaqResource = $condition; + + return $this; + } + + public function hasFaqResource(): bool + { + return $this->hasFaqResource; + } + + public function libraryResource(bool $condition = true): static + { + $this->hasLibraryResource = $condition; + + return $this; + } + + public function hasLibraryResource(): bool + { + return $this->hasLibraryResource; + } } diff --git a/src/Models/Post.php b/src/Models/Post.php index 4a6f69f..e55cd7b 100644 --- a/src/Models/Post.php +++ b/src/Models/Post.php @@ -106,7 +106,7 @@ public function image(): Collection | string | null if (! $this->getMedia('posts')->isEmpty()) { return $this->getFirstMediaUrl('posts'); } else { - return $this->featured_image ?? SkyPlugin::get()->getDefaultFeaturedImage(); + return $this->featured_image ?? config('zeus-sky.defaultFeaturedImage'); } } @@ -127,7 +127,7 @@ public function getContent(): string public function parseContent(string $content): string { - $parsers = SkyPlugin::get()->getParsers(); + $parsers = config('zeus-sky.parsers'); if (filled($parsers)) { foreach ($parsers as $parser) {