diff --git a/src/Control/GoogleSitemapController.php b/src/Control/GoogleSitemapController.php index 31932b7..6c02e68 100644 --- a/src/Control/GoogleSitemapController.php +++ b/src/Control/GoogleSitemapController.php @@ -30,7 +30,9 @@ class GoogleSitemapController extends Controller */ private static $allowed_actions = [ 'index', - 'sitemap' + 'sitemap', + 'styleSheetIndex', + 'styleSheet' ]; @@ -96,13 +98,13 @@ class GoogleSitemapController extends Controller return str_replace('-', '\\', $class); } - public function StylesheetIndexPath() + public function styleSheetIndex() { - return ModuleResourceLoader::resourceURL('wilr/silverstripe-googlesitemaps:xsl/xml-sitemapindex.xsl'); + return $this->renderWith('xml-sitemapindex'); } - public function StylesheetPath() + public function styleSheet() { - return ModuleResourceLoader::resourceURL('wilr/silverstripe-googlesitemaps:xsl/xml-sitemap.xsl'); + return $this->renderWith('xml-sitemap'); } } diff --git a/src/Extensions/GoogleSitemapSiteTreeExtension.php b/src/Extensions/GoogleSitemapSiteTreeExtension.php index cef8cee..65a940d 100644 --- a/src/Extensions/GoogleSitemapSiteTreeExtension.php +++ b/src/Extensions/GoogleSitemapSiteTreeExtension.php @@ -7,20 +7,14 @@ use SilverStripe\ErrorPage\ErrorPage; use SilverStripe\Forms\DropdownField; use SilverStripe\Forms\LiteralField; use SilverStripe\Forms\Tab; +use SilverStripe\ORM\ArrayList; class GoogleSitemapSiteTreeExtension extends GoogleSitemapExtension { - - /** - * @var array - */ - private static $db = array( + private static $db = [ "Priority" => "Varchar(5)" - ); + ]; - /** - * @param FieldList - */ public function updateSettingsFields(&$fields) { $prorities = array( @@ -65,11 +59,6 @@ class GoogleSitemapSiteTreeExtension extends GoogleSitemapExtension $priority->setEmptyString(_t('GoogleSitemaps.PRIORITYAUTOSET', 'Auto-set based on page depth')); } - /** - * @param FieldList - * - * @return void - */ public function updateFieldLabels(&$labels) { parent::updateFieldLabels($labels); @@ -143,20 +132,28 @@ class GoogleSitemapSiteTreeExtension extends GoogleSitemapExtension public function ImagesForSitemap() { $list = new ArrayList(); + $cachedImages = []; foreach ($this->owner->hasOne() as $field => $type) { if (singleton($type) instanceof Image) { $image = $this->owner->getComponent($field); - if ($image && $image->exists()) { + + if ($image && $image->exists() && !isset($cachedImages[$image->ID])) { + $cachedImages[$image->ID] = true; + $list->push($image); } } } + foreach ($this->owner->hasMany() as $field => $type) { if (singleton($type) instanceof Image) { $images = $this->owner->getComponents($field); + foreach ($images as $image) { - if ($image && $image->exists()) { + if ($image && $image->exists() && !isset($cachedImages[$image->ID])) { + $cachedImages[$image->ID] = true; + $list->push($image); } } @@ -164,6 +161,7 @@ class GoogleSitemapSiteTreeExtension extends GoogleSitemapExtension } $this->owner->extend('updateImagesForSitemap', $list); + return $list; } } diff --git a/templates/Wilr/GoogleSitemaps/Control/GoogleSitemapController.ss b/templates/Wilr/GoogleSitemaps/Control/GoogleSitemapController.ss index 064a91a..0f6d132 100644 --- a/templates/Wilr/GoogleSitemaps/Control/GoogleSitemapController.ss +++ b/templates/Wilr/GoogleSitemaps/Control/GoogleSitemapController.ss @@ -1,5 +1,5 @@ - + <% loop Sitemaps %> {$AbsoluteBaseURL}sitemap.xml/sitemap/$ClassName/$Page.xml diff --git a/templates/Wilr/GoogleSitemaps/Control/GoogleSitemapController_sitemap.ss b/templates/Wilr/GoogleSitemaps/Control/GoogleSitemapController_sitemap.ss index 0a573c8..d9a0204 100644 --- a/templates/Wilr/GoogleSitemaps/Control/GoogleSitemapController_sitemap.ss +++ b/templates/Wilr/GoogleSitemaps/Control/GoogleSitemapController_sitemap.ss @@ -1,5 +1,5 @@ - + <% loop $Items %> diff --git a/xsl/xml-sitemap.xsl b/templates/xml-sitemap.ss similarity index 89% rename from xsl/xml-sitemap.xsl rename to templates/xml-sitemap.ss index a716346..9c60b41 100644 --- a/xsl/xml-sitemap.xsl +++ b/templates/xml-sitemap.ss @@ -6,7 +6,7 @@ XML Sitemap - +
@@ -38,12 +38,12 @@ - + - + @@ -54,10 +54,10 @@ @@ -72,7 +72,7 @@
Images
- + - + - + diff --git a/xsl/xml-sitemapindex.xsl b/templates/xml-sitemapindex.ss similarity index 94% rename from xsl/xml-sitemapindex.xsl rename to templates/xml-sitemapindex.ss index 50c56c5..f8d8c04 100644 --- a/xsl/xml-sitemapindex.xsl +++ b/templates/xml-sitemapindex.ss @@ -6,7 +6,7 @@ XML Sitemap - +
@@ -35,7 +35,7 @@ - +