Skip to content

Commit

Permalink
🚀 v5
Browse files Browse the repository at this point in the history
  • Loading branch information
bnomei committed Nov 25, 2024
1 parent ee8c735 commit cb801c1
Show file tree
Hide file tree
Showing 16 changed files with 6,830 additions and 1,302 deletions.
24 changes: 24 additions & 0 deletions .github/workflows/fix-php-code-style-issues.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: Fix PHP code style issues

on:
push:
paths:
- '**.php'

jobs:
php-code-styling:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v4
with:
ref: ${{ github.head_ref }}

- name: Fix PHP code style issues
uses: aglipanci/laravel-pint-action@2.3.0

- name: Commit changes
uses: stefanzweifel/git-auto-commit-action@v4
with:
commit_message: Fix styling
38 changes: 38 additions & 0 deletions .github/workflows/pest-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: Pest Tests

on:
push:
paths:
- "**.php"
- "composer.lock"
pull_request:
paths:
- "**.php"
- "composer.lock"

jobs:
test:
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: 8.2
tools: composer:v2
coverage: none

- name: Cache composer dependencies
uses: actions/cache@v4
with:
path: vendor
key: composer-${{ hashFiles('composer.lock') }}

- name: Install
run: composer kirby

- name: PEST
run: vendor/bin/pest --ci
34 changes: 34 additions & 0 deletions .github/workflows/phpstan.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: PHPStan

on:
push:
paths:
- '**.php'
- 'phpstan.neon.dist'

jobs:
phpstan:
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: 8.2
tools: composer:v2
coverage: none

- name: Cache composer dependencies
uses: actions/cache@v4
with:
path: vendor
key: composer-${{ hashFiles('composer.lock') }}

- name: Install
run: composer kirby

- name: Run PHPStan
run: vendor/bin/phpstan --error-format=github
52 changes: 0 additions & 52 deletions .github/workflows/test.yml

This file was deleted.

19 changes: 11 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
# Kirby Robots.txt

![Release](https://flat.badgen.net/packagist/v/bnomei/kirby3-robots-txt?color=ae81ff)
![Downloads](https://flat.badgen.net/packagist/dt/bnomei/kirby3-robots-txt?color=272822)
[![Coverage](https://flat.badgen.net/codeclimate/coverage/bnomei/kirby3-robots-txt)](https://codeclimate.com/github/bnomei/kirby3-robots-txt)
[![Maintainability](https://flat.badgen.net/codeclimate/maintainability/bnomei/kirby3-robots-txt)](https://codeclimate.com/github/bnomei/kirby3-robots-txt)
[![Discord](https://flat.badgen.net/badge/discord/bnomei?color=7289da)](https://discordapp.com/users/bnomei)
[![Kirby 5](https://flat.badgen.net/badge/Kirby/5?color=ECC748)](https://getkirby.com)
![PHP 8.2](https://flat.badgen.net/badge/PHP/8.2?color=4E5B93&icon=php&label)
![Release](https://flat.badgen.net/packagist/v/bnomei/kirby3-robots-txt?color=ae81ff&icon=github&label)
![Downloads](https://flat.badgen.net/packagist/dt/bnomei/kirby3-robots-txt?color=272822&icon=github&label)
[![Coverage](https://flat.badgen.net/codeclimate/coverage/bnomei/kirby3-robots-txt?icon=codeclimate&label)](https://codeclimate.com/github/bnomei/kirby3-robots-txt)
[![Maintainability](https://flat.badgen.net/codeclimate/maintainability/bnomei/kirby3-robots-txt?icon=codeclimate&label)](https://codeclimate.com/github/bnomei/kirby3-robots-txt/issues)
[![Discord](https://flat.badgen.net/badge/discord/bnomei?color=7289da&icon=discord&label)](https://discordapp.com/users/bnomei)
[![Buymecoffee](https://flat.badgen.net/badge/icon/donate?icon=buymeacoffee&color=FF813F&label)](https://www.buymeacoffee.com/bnomei)

Installing the plugin is enough to get a virtual [robots.txt](https://developers.google.com/search/reference/robots_txt).
Installing the plugin is enough to get a virtual [robots.txt](https://developers.google.com/search/reference/robots_txt) file.

## Installation

Expand All @@ -26,9 +29,9 @@ Disallow: /cdn-cgi/
Allow: /media/
```

## Active Debug Mode will block Indexing by Search Engines
## Active debug mode will block indexing by search engines

> [!WARNING]
> [!WARNING]
> Setting the global Kirby `debug` configuration to `true` will prevent all indexing for every user agent (all Search Engines).
## Link to Sitemap.xml
Expand Down
57 changes: 29 additions & 28 deletions classes/Robotstxt.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,31 @@
final class Robotstxt
{
public function __construct(
private array $options = [],
private array $txt = [],
private array $options = []
) {
$defaults = [
'debug' => option('debug'),
'content' => option('bnomei.robots-txt.content'),
'groups' => option('bnomei.robots-txt.groups'),
'sitemap' => option('bnomei.robots-txt.sitemap'),
];
$this->options = array_merge($defaults, $this->options);
$this->options = array_merge($defaults, $options);

foreach ($this->options as $key => $call) {
if ($call instanceof \Closure) {
$this->options[$key] = $call();
}
}

$this->addContent(A::get($this->options, 'content'));
$this->addGroups(A::get($this->options, 'groups'));
$this->addSitemap(A::get($this->options, 'sitemap'));
$this->addContent($this->option('content'))
->addGroups($this->option('groups'))
->addSitemap($this->option('sitemap'));
}

public function option(string $key): mixed
{
return A::get($this->options, $key);
}

public function toArray(): ?array
Expand All @@ -41,44 +46,43 @@ public function toTxt(): ?string
return count($this->txt) ? implode(PHP_EOL, $this->txt).PHP_EOL : null;
}

/**
* @param null $content
*/
private function addContent($content = null): Robotstxt
private function addContent(mixed $content = null): self
{
if (! $content) {
if (empty($content)) {
return $this;
}
$this->txt[] = (string) $content;
if (is_string($content)) {
$this->txt[] = $content;
}

return $this;
}

/**
* @param null $groups
*/
private function addGroups($groups = null): Robotstxt
private function addGroups(mixed $groups = null): self
{
if (! $groups) {
if (empty($groups)) {
return $this;
}
if (A::get($this->options, 'debug')) {
if ($this->option('debug')) {
$groups = ['*' => ['disallow' => ['/']]];
}
if (! is_array($groups) && ! is_string($groups) && is_callable($groups)) {
$groups = $groups();
}
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[] = $field.': '.$value;
$this->txt[] = implode('', [$field, ': ', $value]);
}
}
}
} else {
$this->txt[] = (string) $groups;
} elseif (is_string($groups)) {
$this->txt[] = $groups;
}

return $this;
Expand Down Expand Up @@ -108,10 +112,7 @@ private function hasSitemapFromKnownPlugin(): bool
return false;
}

/**
* @param null $sitemap
*/
private function addSitemap($sitemap = null): Robotstxt
private function addSitemap(mixed $sitemap = null): self
{
// @codeCoverageIgnoreStart
if ($this->hasSitemapFromKnownPlugin()) {
Expand All @@ -121,7 +122,7 @@ private function addSitemap($sitemap = null): Robotstxt
}
// @codeCoverageIgnoreEnd

if (! $sitemap) {
if (! is_string($sitemap)) {
return $this;
}

Expand Down
26 changes: 15 additions & 11 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
"config": {
"optimize-autoloader": true,
"allow-plugins": {
"getkirby/composer-installer": true
"getkirby/composer-installer": true,
"pestphp/pest-plugin": true
}
},
"conflict": {
Expand All @@ -36,26 +37,29 @@
"getkirby/composer-installer": "^1.1"
},
"require-dev": {
"getkirby/cms": "^5.0.0-alpha.3",
"phpunit/phpunit": "^9.5",
"laravel/pint": "^1.13"
"getkirby/cms": "^5.0.0-alpha.4",
"larastan/larastan": "^v3.0.0",
"laravel/pint": "^1.13",
"pestphp/pest": "^v3.5.1",
"spatie/ray": "^1.39",
"pestphp/pest-plugin-drift": "^3.0"
},
"scripts": {
"fix": "vendor/bin/pint",
"test": [
"mkdir -p tests/logs",
"@putenv XDEBUG_MODE=coverage",
"phpunit --configuration ./phpunit.xml"
],
"stan": "./vendor/bin/phpstan",
"fix": "./vendor/bin/pint",
"test": "./vendor/bin/pest --profile",
"dist": [
"composer fix",
"composer install --no-dev --optimize-autoloader",
"git rm -rf --cached .; git add .;"
],
"kirby": [
"composer install",
"composer update",
"composer install --working-dir=tests/kirby --no-dev --optimize-autoloader",
"composer update --working-dir=tests/kirby"
"composer update --working-dir=tests/kirby",
"sed -i.bak 's/function dump(/function xdump(/g' tests/kirby/config/helpers.php",
"sed -i.bak 's/function e(/function xe(/g' tests/kirby/config/helpers.php"
]
},
"extra": {
Expand Down
Loading

0 comments on commit cb801c1

Please sign in to comment.