Correct path to stylesheet, update stylesheets for images

This commit is contained in:
Will Rossiter 2018-03-20 09:45:38 +13:00
parent c3fcd84542
commit adb3ed94fc
6 changed files with 31 additions and 31 deletions

View File

@ -30,7 +30,9 @@ class GoogleSitemapController extends Controller
*/ */
private static $allowed_actions = [ private static $allowed_actions = [
'index', 'index',
'sitemap' 'sitemap',
'styleSheetIndex',
'styleSheet'
]; ];
@ -96,13 +98,13 @@ class GoogleSitemapController extends Controller
return str_replace('-', '\\', $class); 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');
} }
} }

View File

@ -7,20 +7,14 @@ use SilverStripe\ErrorPage\ErrorPage;
use SilverStripe\Forms\DropdownField; use SilverStripe\Forms\DropdownField;
use SilverStripe\Forms\LiteralField; use SilverStripe\Forms\LiteralField;
use SilverStripe\Forms\Tab; use SilverStripe\Forms\Tab;
use SilverStripe\ORM\ArrayList;
class GoogleSitemapSiteTreeExtension extends GoogleSitemapExtension class GoogleSitemapSiteTreeExtension extends GoogleSitemapExtension
{ {
private static $db = [
/**
* @var array
*/
private static $db = array(
"Priority" => "Varchar(5)" "Priority" => "Varchar(5)"
); ];
/**
* @param FieldList
*/
public function updateSettingsFields(&$fields) public function updateSettingsFields(&$fields)
{ {
$prorities = array( $prorities = array(
@ -65,11 +59,6 @@ class GoogleSitemapSiteTreeExtension extends GoogleSitemapExtension
$priority->setEmptyString(_t('GoogleSitemaps.PRIORITYAUTOSET', 'Auto-set based on page depth')); $priority->setEmptyString(_t('GoogleSitemaps.PRIORITYAUTOSET', 'Auto-set based on page depth'));
} }
/**
* @param FieldList
*
* @return void
*/
public function updateFieldLabels(&$labels) public function updateFieldLabels(&$labels)
{ {
parent::updateFieldLabels($labels); parent::updateFieldLabels($labels);
@ -143,20 +132,28 @@ class GoogleSitemapSiteTreeExtension extends GoogleSitemapExtension
public function ImagesForSitemap() public function ImagesForSitemap()
{ {
$list = new ArrayList(); $list = new ArrayList();
$cachedImages = [];
foreach ($this->owner->hasOne() as $field => $type) { foreach ($this->owner->hasOne() as $field => $type) {
if (singleton($type) instanceof Image) { if (singleton($type) instanceof Image) {
$image = $this->owner->getComponent($field); $image = $this->owner->getComponent($field);
if ($image && $image->exists()) {
if ($image && $image->exists() && !isset($cachedImages[$image->ID])) {
$cachedImages[$image->ID] = true;
$list->push($image); $list->push($image);
} }
} }
} }
foreach ($this->owner->hasMany() as $field => $type) { foreach ($this->owner->hasMany() as $field => $type) {
if (singleton($type) instanceof Image) { if (singleton($type) instanceof Image) {
$images = $this->owner->getComponents($field); $images = $this->owner->getComponents($field);
foreach ($images as $image) { foreach ($images as $image) {
if ($image && $image->exists()) { if ($image && $image->exists() && !isset($cachedImages[$image->ID])) {
$cachedImages[$image->ID] = true;
$list->push($image); $list->push($image);
} }
} }
@ -164,6 +161,7 @@ class GoogleSitemapSiteTreeExtension extends GoogleSitemapExtension
} }
$this->owner->extend('updateImagesForSitemap', $list); $this->owner->extend('updateImagesForSitemap', $list);
return $list; return $list;
} }
} }

View File

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type='text/xsl' href='$StylesheetIndexPath'?> <?xml-stylesheet type='text/xsl' href='{$BaseHref}sitemap.xml/styleSheetIndex'?>
<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"><% loop Sitemaps %> <sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"><% loop Sitemaps %>
<sitemap> <sitemap>
<loc>{$AbsoluteBaseURL}sitemap.xml/sitemap/$ClassName/$Page.xml</loc> <loc>{$AbsoluteBaseURL}sitemap.xml/sitemap/$ClassName/$Page.xml</loc>

View File

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type='text/xsl' href='$StylesheetPath'?> <?xml-stylesheet type='text/xsl' href='{$BaseHref}sitemap.xml/styleSheet'?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:image="http://www.google.com/schemas/sitemap-image/1.1"> <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:image="http://www.google.com/schemas/sitemap-image/1.1">
<% loop $Items %> <% loop $Items %>
<url> <url>

View File

@ -6,7 +6,7 @@
<head> <head>
<title>XML Sitemap</title> <title>XML Sitemap</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" href="resources/wilr/silverstripe-googlesitemaps/css/style.css" /> <link rel="stylesheet" href="{$BaseHref}resources/wilr/silverstripe-googlesitemaps/css/style.css" />
</head> </head>
<body> <body>
<div id="content"> <div id="content">
@ -38,12 +38,12 @@
<xsl:value-of select="sitemap:loc"/> <xsl:value-of select="sitemap:loc"/>
</xsl:variable> </xsl:variable>
<xsl:variable name="imagesCount" select="count(image:image)"/> <xsl:variable name="imagesCount" select="count(image:image)"/>
<a href="{$itemURL}"> <a href="{\$itemURL}">
<xsl:value-of select="sitemap:loc"/> <xsl:value-of select="sitemap:loc"/>
</a> </a>
<xsl:if test="$imagesCount &gt; 0"> <xsl:if test="\$imagesCount &gt; 0">
<table class="imagestable" cellpadding="0" cellspacing="0"> <table class="imagestable" cellpadding="0" cellspacing="0">
<tr> <tr>
<th>Images</th> <th>Images</th>
@ -54,10 +54,10 @@
</xsl:variable> </xsl:variable>
<tr> <tr>
<td> <td>
<img src="{$imageURL}" width="40px"/> <img src="{\$imageURL}" width="40px"/>
</td> </td>
<td> <td>
<a href="{$imageURL}"> <a href="{\$imageURL}">
<xsl:value-of select="image:loc"/> <xsl:value-of select="image:loc"/>
</a> </a>
</td> </td>
@ -72,7 +72,7 @@
<xsl:value-of select="concat(sitemap:priority*100,'%')"/> <xsl:value-of select="concat(sitemap:priority*100,'%')"/>
</td> </td>
<td> <td>
<xsl:value-of select="concat(translate(substring(sitemap:changefreq, 1, 1),concat($lower, $upper),concat($upper, $lower)),substring(sitemap:changefreq, 2))"/> <xsl:value-of select="concat(translate(substring(sitemap:changefreq, 1, 1),concat(\$lower, \$upper),concat(\$upper, \$lower)),substring(sitemap:changefreq, 2))"/>
</td> </td>
<td> <td>
<xsl:value-of select="concat(substring(sitemap:lastmod,0,11),concat(' ', substring(sitemap:lastmod,12,5)))"/> <xsl:value-of select="concat(substring(sitemap:lastmod,0,11),concat(' ', substring(sitemap:lastmod,12,5)))"/>

View File

@ -6,7 +6,7 @@
<head> <head>
<title>XML Sitemap</title> <title>XML Sitemap</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" href="resources/wilr/silverstripe-googlesitemaps/css/style.css" /> <link rel="stylesheet" href="{$BaseHref}resources/wilr/silverstripe-googlesitemaps/css/style.css" />
</head> </head>
<body> <body>
<div id="content"> <div id="content">
@ -35,7 +35,7 @@
<xsl:variable name="itemURL"> <xsl:variable name="itemURL">
<xsl:value-of select="sitemap:loc"/> <xsl:value-of select="sitemap:loc"/>
</xsl:variable> </xsl:variable>
<a href="{$itemURL}"> <a href="{\$itemURL}">
<xsl:value-of select="sitemap:loc"/> <xsl:value-of select="sitemap:loc"/>
</a> </a>
</td> </td>