diff --git a/simple_sitemap.routing.yml b/simple_sitemap.routing.yml index 7c1da48..c42c31a 100644 --- a/simple_sitemap.routing.yml +++ b/simple_sitemap.routing.yml @@ -26,6 +26,14 @@ simple_sitemap.chunk: requirements: _access: 'TRUE' +simple_sitemap.sitemap_xsl: + path: '/sitemap.xsl' + defaults: + _controller: '\Drupal\simple_sitemap\Controller\SimplesitemapController::renderSitemapXsl' + _title: 'Sitemap XSL' + requirements: + _access: 'TRUE' + simple_sitemap.settings: path: '/admin/config/search/simplesitemap' defaults: diff --git a/src/Controller/SimplesitemapController.php b/src/Controller/SimplesitemapController.php index 8e62daf..71c343e 100644 --- a/src/Controller/SimplesitemapController.php +++ b/src/Controller/SimplesitemapController.php @@ -65,4 +65,38 @@ class SimplesitemapController extends ControllerBase { return new static($container->get('simple_sitemap.generator')); } + /** + * Provides the sitemap in XSL format. + * + * @return \Symfony\Component\HttpFoundation\Response + * Response object in XSL format. + */ + public function renderSitemapXsl() { + // Read the XSL content from the file. + $module_path = drupal_get_path('module', 'simple_sitemap'); + $xsl_content = file_get_contents($module_path . '/xsl/simple_sitemap.xsl'); + + // Make sure the strings in the XSL content are translated properly. + $replacements = array( + 'Sitemap file' => t('Sitemap file'), + 'Generated by the Drupal Simple XML sitemap module.' => t('Generated by the Drupal Simple XML sitemap module.', array('@link-simple_sitemap' => 'http://drupal.org/project/simple_sitemap')), + 'Number of sitemaps in this index' => t('Number of sitemaps in this index'), + 'Click on the table headers to change sorting.' => t('Click on the table headers to change sorting.'), + 'Sitemap URL' => t('Sitemap URL'), + 'Last modification date' => t('Last modification date'), + 'Number of URLs in this sitemap' => t('Number of URLs in this sitemap'), + 'URL location' => t('URL location'), + 'Translation set' => t('Translation set'), + 'Priority' => t('Priority'), + '[xsl-css]' => base_path() . $module_path . '/xsl/simple_sitemap.xsl.css', + ); + $xsl_content = strtr($xsl_content, $replacements); + + // Output the XSL content. + $response = new Response($xsl_content); + $response->headers->set('Content-type', 'application/xml; charset=utf-8'); + $response->headers->set('X-Robots-Tag', 'noindex, follow'); + return $response; + } + } diff --git a/src/SitemapGenerator.php b/src/SitemapGenerator.php index 7e959ff..40c0cd1 100644 --- a/src/SitemapGenerator.php +++ b/src/SitemapGenerator.php @@ -175,6 +175,7 @@ class SitemapGenerator { $writer->openMemory(); $writer->setIndent(TRUE); $writer->startDocument(self::XML_VERSION, self::ENCODING); + $writer->writePI('xml-stylesheet', 'type="text/xsl" href="' . $GLOBALS['base_url'] . '/sitemap.xsl"'); $writer->writeComment(self::GENERATED_BY); $writer->startElement('sitemapindex'); $writer->writeAttribute('xmlns', self::XMLNS); @@ -209,9 +210,10 @@ class SitemapGenerator { $writer->openMemory(); $writer->setIndent(TRUE); $writer->startDocument(self::XML_VERSION, self::ENCODING); + $writer->writePI('xml-stylesheet', 'type="text/xsl" href="' . $GLOBALS['base_url'] . '/sitemap.xsl"'); $writer->writeComment(self::GENERATED_BY); $writer->startElement('urlset'); - $writer->writeAttribute('xmlns', self::XMLNS); + $writer->writeAttribute('xmlns:sitemap', self::XMLNS); if ($this->isHreflangSitemap) { $writer->writeAttribute('xmlns:xhtml', self::XMLNS_XHTML); } diff --git a/xsl/simple_sitemap.xsl b/xsl/simple_sitemap.xsl new file mode 100644 index 0000000..1d84f36 --- /dev/null +++ b/xsl/simple_sitemap.xsl @@ -0,0 +1,60 @@ + + + + + + + + + + + Simple Sitemap + + + + + +

Sitemap

+ +
+

Number of URLs in this sitemap:

+
+ + + + + + + + + + + + + + + +
URLTranslation setPriority
+ + + +
+ + +
+
+
+
+
+ + + + + + +
+
diff --git a/xsl/simple_sitemap.xsl.css b/xsl/simple_sitemap.xsl.css new file mode 100644 index 0000000..043bfef --- /dev/null +++ b/xsl/simple_sitemap.xsl.css @@ -0,0 +1,55 @@ + +body { + background-color: #FFF; + font-family: Verdana,sans-serif; + font-size: 10pt; +} +h1 { + font-size: 1.25em; +} +table.tablesorter { + background-color: #CDCDCD; + margin:10px 0pt 15px; + font-size: 8pt; + width: 100%; + text-align: left; +} +table.tablesorter thead tr th, table.tablesorter tfoot tr th { + background-color: #E6EEEE; + border: 1px solid #FFF; + font-size: 8pt; + padding: 3px; +} +table.tablesorter thead tr .header { + cursor: pointer; +} +table.tablesorter tbody td { + color: #3D3D3D; + padding: 3px; + background-color: #FFF; + vertical-align: top; +} +table.tablesorter tbody tr.odd td { + background-color: #EFEFEF; +} +table.tablesorter thead tr .headerSortUp { + background: url(/core/misc/arrow-asc.png) no-repeat center right; +} +table.tablesorter thead tr .headerSortDown { + background: url(/core/misc/arrow-desc.png) no-repeat center right; +} +table.tablesorter thead tr .headerSortDown, table.tablesorter thead tr .headerSortUp { + background-color: #5050D3; + color: #FFF; + font-style: italic; +} + +dl.translation-set { + margin: 0; +} +dl.translation-set dt { + float: left; +} +dl.translation-set dd:before { + content: ": "; +}