Merge pull request #121 from timezoneone/J003064/images-for-xml-sitemaps

added a way to include any images displayed on the pages to the googl…
This commit is contained in:
Will Rossiter 2018-03-07 08:02:49 +13:00 committed by GitHub
commit 628dbd8404
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 77 additions and 3 deletions

View File

@ -101,7 +101,6 @@ table.tablesorter thead tr .headerSortDown {
table.tablesorter tbody td {
color: #005A92;
padding: 4px;
vertical-align: top;
}
table.tablesorter tbody tr{
@ -124,6 +123,20 @@ table.tablesorter tbody tr:hover td,
table.tablesorter tbody tr:hover a{
color: #000;
}
table.imagestable,
table.imagestable a {
font-size: 8pt;
}
table.imagestable {
margin-top: 15px;
}
table.imagestable tr.odd {
background: transparent;
}
table.imagestable tr.even {
background: transparent;
}
#Footer{
margin: 50px 0 10px;
text-align: right;

View File

@ -2,6 +2,7 @@
namespace Wilr\GoogleSitemaps\Extensions;
use SilverStripe\Assets\Image;
use SilverStripe\ErrorPage\ErrorPage;
use SilverStripe\Forms\DropdownField;
use SilverStripe\Forms\LiteralField;
@ -47,7 +48,7 @@ class GoogleSitemapSiteTreeExtension extends GoogleSitemapExtension
'<a href="http://www.google.com/support/webmasters/bin/answer.py?hl=en&answer=71936#prioritize" '
. 'target="_blank">?</a>'
);
$message .= "</p>";
$message .= "</p>";
$tabset->push(new Tab(
'GoogleSitemap',
@ -138,4 +139,32 @@ class GoogleSitemapSiteTreeExtension extends GoogleSitemapExtension
return (is_numeric($priority) && $priority <= 1.0) ? $priority : 0.5;
}
}
public function ImagesForSitemap()
{
$list = new ArrayList();
foreach ($this->owner->hasOne() as $field => $type) {
if (singleton($type) instanceof Image) {
$image = $this->owner->getComponent($field);
if ($image && $image->exists()) {
$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()) {
$list->push($image);
}
}
}
}
$this->owner->extend('updateImagesForSitemap', $list);
return $list;
}
}

View File

@ -1,12 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type='text/xsl' href='$StylesheetPath'?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:image="http://www.google.com/schemas/sitemap-image/1.1">
<% loop $Items %>
<url>
<loc>$AbsoluteLink</loc>
<% if $LastEdited %><lastmod>$LastEdited.Rfc3339()</lastmod><% end_if %>
<% if $ChangeFrequency %><changefreq>$ChangeFrequency</changefreq><% end_if %>
<% if $GooglePriority %><priority>$GooglePriority</priority><% end_if %>
<% if $ImagesForSitemap %><% loop $ImagesForSitemap %>
<image:image>
<image:loc>{$AbsoluteLink}</image:loc>
</image:image>
<% end_loop %><% end_if %>
</url>
<% end_loop %>
</urlset>

View File

@ -37,9 +37,36 @@
<xsl:variable name="itemURL">
<xsl:value-of select="sitemap:loc"/>
</xsl:variable>
<xsl:variable name="imagesCount" select="count(image:image)"/>
<a href="{$itemURL}">
<xsl:value-of select="sitemap:loc"/>
</a>
<xsl:if test="$imagesCount &gt; 0">
<table class="imagestable" cellpadding="0" cellspacing="0">
<tr>
<th>Images</th>
</tr>
<xsl:for-each select="image:image">
<xsl:variable name="imageURL">
<xsl:value-of select="image:loc"/>
</xsl:variable>
<tr>
<td>
<img src="{$imageURL}" width="40px"/>
</td>
<td>
<a href="{$imageURL}">
<xsl:value-of select="image:loc"/>
</a>
</td>
</tr>
</xsl:for-each>
</table>
</xsl:if>
</td>
<td>
<xsl:value-of select="concat(sitemap:priority*100,'%')"/>