diff --git a/classes/Robotstxt.php b/classes/Robotstxt.php index 5fcbc45..e1343a9 100644 --- a/classes/Robotstxt.php +++ b/classes/Robotstxt.php @@ -67,20 +67,7 @@ private function addGroups(mixed $groups = null): self $groups = ['*' => ['disallow' => ['/']]]; } if (is_array($groups)) { - foreach ($groups as $useragent => $group) { - $this->txt[] = 'user-agent: '.$useragent; - if (! is_array($group)) { - continue; - } - foreach ($group as $field => $values) { - if (! is_array($values)) { - continue; - } - foreach ($values as $value) { - $this->txt[] = implode('', [$field, ': ', $value]); - } - } - } + $this->processGroupsArray($groups); } elseif (is_string($groups)) { $this->txt[] = $groups; } @@ -88,6 +75,32 @@ private function addGroups(mixed $groups = null): self return $this; } + private function processGroupsArray(array $groups): void + { + foreach ($groups as $useragent => $group) { + $this->txt[] = 'user-agent: '.$useragent; + if (is_array($group)) { + $this->processGroupFields($group); + } + } + } + + private function processGroupFields(array $group): void + { + foreach ($group as $field => $values) { + if (is_array($values)) { + $this->processFieldValues($field, $values); + } + } + } + + private function processFieldValues(string $field, array $values): void + { + foreach ($values as $value) { + $this->txt[] = implode('', [$field, ': ', $value]); + } + } + private function hasSitemapFromKnownPlugin(): bool { return count(array_filter([ diff --git a/composer.json b/composer.json index 0c02349..46375a6 100644 --- a/composer.json +++ b/composer.json @@ -2,7 +2,7 @@ "name": "bnomei/kirby3-robots-txt", "type": "kirby-plugin", "description": "Manage a virtual robots.txt from the Kirby config file", - "version": "5.0.1", + "version": "5.0.2", "license": "MIT", "authors": [ { diff --git a/vendor/composer/installed.php b/vendor/composer/installed.php index 8eda763..4b6631f 100644 --- a/vendor/composer/installed.php +++ b/vendor/composer/installed.php @@ -1,8 +1,8 @@ array( 'name' => 'bnomei/kirby3-robots-txt', - 'pretty_version' => '5.0.1', - 'version' => '5.0.1.0', + 'pretty_version' => '5.0.2', + 'version' => '5.0.2.0', 'reference' => null, 'type' => 'kirby-plugin', 'install_path' => __DIR__ . '/../../', @@ -11,8 +11,8 @@ ), 'versions' => array( 'bnomei/kirby3-robots-txt' => array( - 'pretty_version' => '5.0.1', - 'version' => '5.0.1.0', + 'pretty_version' => '5.0.2', + 'version' => '5.0.2.0', 'reference' => null, 'type' => 'kirby-plugin', 'install_path' => __DIR__ . '/../../',