mirror of
https://github.com/tiennm99/coolify.git
synced 2026-08-20 04:23:34 +00:00
Flagged domains are served with X-Robots-Tag: noindex, nofollow via Traefik and Caddy routing labels, so an auto-generated technical domain can be excluded from indexing while the production domain on the same resource stays indexable.
64 lines
1.9 KiB
PHP
64 lines
1.9 KiB
PHP
<?php
|
|
|
|
namespace App\Traits;
|
|
|
|
use App\Support\ValidationPatterns;
|
|
use Illuminate\Support\Collection;
|
|
|
|
/**
|
|
* Flags the subset of a resource's `fqdn` domains that must not be indexed.
|
|
*
|
|
* Domains are normalized on write and on compare, so a casing difference
|
|
* between the stored flag and the configured domain cannot silently drop it.
|
|
*
|
|
* @property array<int, string>|null $noindex_domains
|
|
*/
|
|
trait HasNoindexDomains
|
|
{
|
|
public function noindexDomains(): Collection
|
|
{
|
|
return collect($this->noindex_domains ?? [])
|
|
->filter(fn ($domain) => is_string($domain) && filled($domain))
|
|
->map(fn (string $domain) => ValidationPatterns::normalizeApplicationDomainUrl($domain))
|
|
->unique()
|
|
->values();
|
|
}
|
|
|
|
public function isDomainNoindexed(string $domain): bool
|
|
{
|
|
return $this->noindexDomains()->contains(
|
|
ValidationPatterns::normalizeApplicationDomainUrl($domain)
|
|
);
|
|
}
|
|
|
|
public function setNoindexDomains(iterable $domains): void
|
|
{
|
|
$this->noindex_domains = collect($domains)
|
|
->filter(fn ($domain) => is_string($domain) && filled($domain))
|
|
->map(fn (string $domain) => ValidationPatterns::normalizeApplicationDomainUrl($domain))
|
|
->intersect($this->currentDomains())
|
|
->unique()
|
|
->values()
|
|
->all();
|
|
}
|
|
|
|
/**
|
|
* Drops flags for domains the resource no longer has. Without this, re-adding
|
|
* a removed domain later would silently resurrect its old flag.
|
|
*/
|
|
public function syncNoindexDomains(): void
|
|
{
|
|
if (blank($this->noindex_domains)) {
|
|
return;
|
|
}
|
|
|
|
$this->setNoindexDomains($this->noindex_domains);
|
|
}
|
|
|
|
private function currentDomains(): Collection
|
|
{
|
|
return collect(ValidationPatterns::applicationDomainList($this->fqdn))
|
|
->map(fn (string $domain) => ValidationPatterns::normalizeApplicationDomainUrl($domain));
|
|
}
|
|
}
|