Skip to content

Commit

Permalink
added robots.txt controller
Browse files Browse the repository at this point in the history
  • Loading branch information
fonsekaean committed May 23, 2019
1 parent cfea875 commit a718b85
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 10 deletions.
6 changes: 5 additions & 1 deletion _config/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,8 @@ SilverStripe\Core\Injector\Injector:

SilverStripe\Admin\LeftAndMain:
extra_requirements_css:
- silverstripers/seo:client/dist/styles/bundle.css
- silverstripers/seo:client/dist/styles/bundle.css

SilverStripe\Control\Director:
rules:
'robots.txt': 'SilverStripers\seo\Control\RobotsTXTController'
33 changes: 33 additions & 0 deletions src/Control/RobotsTXTController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php
/**
* Created by Nivanka Fonseka (nivanka@silverstripers.com).
* User: nivankafonseka
* Date: 5/23/19
* Time: 7:28 PM
* To change this template use File | Settings | File Templates.
*/

namespace SilverStripers\seo\Control;


use SilverStripe\Control\Controller;
use SilverStripe\SiteConfig\SiteConfig;

class RobotsTXTController extends Controller
{

public function index()
{
$this->getResponse()->addHeader('Content-Type', 'text/plain');
$siteConfig = SiteConfig::current_site_config();
if($siteConfig->RobotsTXT) {
return $siteConfig->RobotsTXT;
}
return <<<ROBOTS
User-agent: *
Allow: /
ROBOTS;

}

}
28 changes: 19 additions & 9 deletions src/Extensions/SiteConfigExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,20 @@ class SiteConfigExtension extends DataExtension
{

private static $db = [
'DisableSearchEngineVisibility' => 'Boolean',
'TwitterUsername' => 'Varchar(250)',
'FacebookAdmin' => 'Varchar(250)',
'FacebookAppID' => 'Varchar(250)',
'DisableSearchEngineVisibility' => 'Boolean',
'TwitterUsername' => 'Varchar(250)',
'FacebookAdmin' => 'Varchar(250)',
'FacebookAppID' => 'Varchar(250)',

'HeadScripts' => 'Text',
'BodyStartScripts' => 'Text',
'BodyEndScripts' => 'Text'
'HeadScripts' => 'Text',
'BodyStartScripts' => 'Text',
'BodyEndScripts' => 'Text',

'RobotsTXT' => 'Text'
];

private static $has_one = [
'GlobalSocialSharingImage' => Image::class
'GlobalSocialSharingImage' => Image::class
];

private static $owns = [
Expand All @@ -57,7 +59,15 @@ public function updateCMSFields(FieldList $fields)
TextareaField::create('HeadScripts', 'Scripts within <head> block'),
TextareaField::create('BodyStartScripts', 'Scripts just after opening <body>'),
TextareaField::create('BodyEndScripts', 'Scripts just before opening <body>'),
]);

HeaderField::create('RobotsTXTHeading', 'Robots TXT')->setHeadingLevel(4),
TextareaField::create('RobotsTXT', 'Robots TXT')
->setDescription('<p>An example robots.txt<br>
<pre>
User-agent: *
Allow: /
</pre></p>')
]);
}


Expand Down

0 comments on commit a718b85

Please sign in to comment.