added a way to include any images displayed on the pages to the google site maps and updated the XSL to show them on the screen.

This commit is contained in:
Nivanka Fonseka 2017-07-25 17:43:33 +05:30 committed by Daniel Hensby
parent 36ef636249
commit 29be1bc504
No known key found for this signature in database
GPG Key ID: B00D1E9767F0B06E
4 changed files with 76 additions and 2 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;
@ -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(is_a(singleton($type), 'Image')) {
$image = $this->owner->getComponent($field);
if($image && $image->exists()) {
$list->push($image);
}
}
}
foreach ($this->owner->hasMany() as $field => $type) {
if(is_a(singleton($type), '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,'%')"/>