Skip to content

Commit

Permalink
Feature/exclude external redirect (#18)
Browse files Browse the repository at this point in the history
* change getSitemapPages to ignore redirect pages that redirect to external URLs

* update comment
  • Loading branch information
oscarholt authored May 12, 2023
1 parent 7c87dfa commit 40792ca
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions src/Controller/SitemapXMLController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@
namespace PlasticStudio\SEO\Controller;

use Page;
use PlasticStudio\SEO\Generators\SitemapGenerator;
use SilverStripe\Control\Controller;
use SilverStripe\ORM\ArrayList;
use SilverStripe\Control\Director;
use SilverStripe\Control\HTTPRequest;
use SilverStripe\Control\Controller;
use SilverStripe\Core\Config\Config;
use SilverStripe\ORM\ArrayList;
use SilverStripe\Control\HTTPRequest;
use SilverStripe\ErrorPage\ErrorPage;
use SilverStripe\CMS\Model\RedirectorPage;
use PlasticStudio\SEO\Generators\SitemapGenerator;

/**
* SitemapXML_Controller
Expand All @@ -31,7 +32,7 @@ public function init()
{
parent::init();

$this->response->addHeader("Content-Type", "application/xml");
$this->response->addHeader("Content-Type", "application/xml");
}

/**
Expand Down Expand Up @@ -93,7 +94,13 @@ public function getSitemapPages()
foreach ($objects as $name => $values) {
// exclude error pages, so google doesn't error
$list = $name::get()->filter('ClassName:not', ErrorPage::class);

foreach ($list as $page) {
// Exclude redirector pages that redirect to external URLs, so google doesn't error
if ($page instanceof RedirectorPage && $page->RedirectionType == 'External') {
continue;
}

if (!$page->SitemapHide) {
$pages->push($page);
}
Expand All @@ -102,4 +109,4 @@ public function getSitemapPages()
}
return $pages;
}
}
}

0 comments on commit 40792ca

Please sign in to comment.