-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
31 changed files
with
490 additions
and
547 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
<?php | ||
|
||
namespace Aerni\AdvancedSeo\Actions; | ||
|
||
use Aerni\AdvancedSeo\Concerns\AsAction; | ||
use Aerni\AdvancedSeo\Concerns\EvaluatesIndexability; | ||
use Aerni\AdvancedSeo\Facades\Seo; | ||
use Statamic\Contracts\Entries\Entry; | ||
use Statamic\Contracts\Taxonomies\Taxonomy; | ||
use Statamic\Contracts\Taxonomies\Term; | ||
use Statamic\Facades\Blink; | ||
|
||
class IncludeInSitemap | ||
{ | ||
use AsAction; | ||
use EvaluatesIndexability; | ||
|
||
public function handle(Entry|Term|Taxonomy $model, ?string $locale = null): bool | ||
{ | ||
$locale ??= $model->locale(); | ||
|
||
return Blink::once("{$model->id()}::{$locale}", fn () => match (true) { | ||
$model instanceof Entry => $this->includeEntryOrTermInSitemap($model), | ||
$model instanceof Term => $this->includeEntryOrTermInSitemap($model), | ||
$model instanceof Taxonomy => $this->includeTaxonomyInSitemap($model, $locale) | ||
}); | ||
} | ||
|
||
protected function includeEntryOrTermInSitemap(Entry|Term $model): bool | ||
{ | ||
return ! $this->isExcludedFromSitemap($model, $model->locale) | ||
&& $this->isIndexableEntryOrTerm($model) | ||
&& $model->seo_sitemap_enabled | ||
&& $model->seo_canonical_type == 'current'; | ||
} | ||
|
||
protected function includeTaxonomyInSitemap(Taxonomy $taxonomy, string $locale): bool | ||
{ | ||
return ! $this->isExcludedFromSitemap($taxonomy, $locale) | ||
&& $this->isIndexableSite($locale); | ||
} | ||
|
||
protected function isExcludedFromSitemap(Entry|Term|Taxonomy $model, string $locale): bool | ||
{ | ||
$excluded = Seo::find('site', 'indexing') | ||
?->in($locale) | ||
?->value('excluded_'.EvaluateModelType::handle($model)) ?? []; | ||
|
||
return in_array(EvaluateModelHandle::handle($model), $excluded); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?php | ||
|
||
namespace Aerni\AdvancedSeo\Concerns; | ||
|
||
trait AsAction | ||
{ | ||
/** | ||
* @return static | ||
*/ | ||
public static function make() | ||
{ | ||
return app(static::class); | ||
} | ||
|
||
/** | ||
* @see static::handle() | ||
* | ||
* @param mixed ...$arguments | ||
* @return mixed | ||
*/ | ||
public static function run(...$arguments) | ||
{ | ||
return static::make()->handle(...$arguments); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php | ||
|
||
namespace Aerni\AdvancedSeo\Concerns; | ||
|
||
use Statamic\Contracts\Entries\Collection; | ||
use Statamic\Tags\Context; | ||
use Statamic\Taxonomies\Taxonomy; | ||
|
||
trait EvaluatesContextType | ||
{ | ||
protected function contextIsEntryOrTerm(Context $context): bool | ||
{ | ||
return $context->value('is_entry') || $context->value('is_term'); | ||
} | ||
|
||
protected function contextIsTaxonomy(Context $context): bool | ||
{ | ||
return $context->get('page') instanceof Taxonomy | ||
&& $context->get('page')->collection() === null; | ||
} | ||
|
||
protected function contextIsCollectionTaxonomy(Context $context): bool | ||
{ | ||
return $context->get('page') instanceof Taxonomy | ||
&& $context->get('page')->collection() instanceof Collection; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.