Skip to content

Commit

Permalink
🚀 v5
Browse files Browse the repository at this point in the history
  • Loading branch information
bnomei committed Nov 24, 2024
1 parent 2c3b642 commit ee8c735
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 87 deletions.
30 changes: 19 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,32 +6,40 @@
[![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)


Manage a virtual [robots.txt](https://developers.google.com/search/reference/robots_txt) from the Kirby config file.

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

## Installation

- unzip [master.zip](https://github.com/bnomei/kirby3-robots-txt/archive/master.zip) as folder `site/plugins/kirby3-robots-txt` or
- `git submodule add https://github.com/bnomei/kirby3-robots-txt.git site/plugins/kirby3-robots-txt` or
- `composer require bnomei/kirby3-robots-txt`

## Staging Server? Debug Mode = Disallow all
## Zero-Configuration

The plugin will work out of the box without the need to configure anything. It will generate a virtual `robots.txt` file with the following content.

```txt
User-agent: *
Disallow: /kirby/
Disallow: /site/
Disallow: /cdn-cgi/
Allow: /media/
```

Setting the global Kirby `debug` configuration to `true` will prevent all indexing for every user agent. This is particularly useful on staging servers, but you may also want to consider it for XML sitemaps and RSS feeds, among other things.
## Active Debug Mode will block Indexing by Search Engines

> [!WARNING]
> This means if you have Kirby's debug mode enabled in production, all search engines will be blocked from indexing your site!
> Setting the global Kirby `debug` configuration to `true` will prevent all indexing for every user agent (all Search Engines).
## Adding Sitemap Link to Robots.txt
## Link to Sitemap.xml

This plugin will add the sitemap link **automatically** to the virtual `robots.txt` file for most available SEO plugins. In that case, you can skip setting the `bnomei.robots-txt.sitemap` config value to `sitemap.xml`.
This plugin will add the link to your `sitemap.xml` **automatically** for most available SEO plugins. In that case, you can skip setting the `bnomei.robots-txt.sitemap` config value to `sitemap.xml`.

## Setup
## Optional Manual Configuration

The plugin generates automatic defaults for the starterkit. You do not have to enter them in the config file. But if you would, it would look like this.
The plugin generates automatic defaults optimized for the official [Kirby Starterkit](https://github.com/getkirby/starterkit). You do not have to enter any of them in the config file. But if you would, they would look like this.

**defaults for starterkit**
**defaults for Kirby Starterkit**
```php
<?php
return [
Expand Down
26 changes: 6 additions & 20 deletions classes/Robotstxt.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,30 +8,17 @@

final class Robotstxt
{
/**
* @var string[]
*/
private $txt;

/**
* @var array
*/
private $options;

/**
* Robotstxt constructor.
*/
public function __construct(array $options = [])
{
$this->txt = [];

public function __construct(
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, $options);
$this->options = array_merge($defaults, $this->options);

foreach ($this->options as $key => $call) {
if ($call instanceof \Closure) {
Expand Down Expand Up @@ -114,8 +101,7 @@ private function hasSitemapFromKnownPlugin(): bool
if (option('kirbyzone.sitemapper.customMap') instanceof \Closure) {
return true;
}
$feedPlugin = kirby()->plugin('bnomei/feed');
if ($feedPlugin && option('bnomei.feed.sitemap.enable') === true && version_compare($feedPlugin->version(), '1.4.0', '>=')) {
if (option('bnomei.feed.sitemap.enable') === true) {
return true;
}

Expand Down
97 changes: 49 additions & 48 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion tests/IndexTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ protected function setUp(): void
$this->setOutputCallback(function () {});
}

public function testIndex()
public function test_index()
{
$response = kirby()->render('/robots.txt');
$this->assertTrue($response->code() === 200);
Expand Down
Loading

0 comments on commit ee8c735

Please sign in to comment.