Class: SiteMaps::Builder::XSLStylesheet

Inherits:
Object
  • Object
show all
Defined in:
lib/site_maps/builder/xsl_stylesheet.rb

Constant Summary collapse

URLSET_XSL =
<<~XSL
  <?xml version="1.0" encoding="UTF-8"?>
  <xsl:stylesheet version="2.0"
    xmlns:html="http://www.w3.org/TR/REC-html40"
    xmlns:sitemap="http://www.sitemaps.org/schemas/sitemap/0.9"
    xmlns:image="http://www.google.com/schemas/sitemap-image/1.1"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output method="html" version="1.0" encoding="UTF-8" indent="yes"/>
    <xsl:template match="/">
      <html xmlns="http://www.w3.org/1999/xhtml">
        <head>
          <title>XML Sitemap</title>
          <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
          <style type="text/css">
            body {
              font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif;
              font-size: 13px;
              color: #545353;
            }
            a { color: #05809e; text-decoration: none; }
            a:visited { color: #06577d; }
            a:hover { text-decoration: underline; }
            #content {
              margin: 0 auto;
              padding: 0 20px;
              max-width: 1200px;
            }
            h1 { font-size: 24px; margin: 20px 0 10px; }
            p.desc { color: #777; margin: 0 0 20px; }
            table {
              border: none;
              border-collapse: collapse;
              width: 100%;
              margin: 0 0 20px;
            }
            th {
              text-align: left;
              padding: 10px 8px;
              font-size: 12px;
              border-bottom: 1px solid #ccc;
            }
            td {
              padding: 8px;
              font-size: 12px;
              border-bottom: 1px solid #eee;
            }
            tr:nth-child(odd) td { background-color: #f8f8f8; }
            tr:hover td { background-color: #e8e8e8; }
            td.url { max-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
            #footer { margin: 10px 0 30px; font-size: 11px; color: #999; }
          </style>
        </head>
        <body>
          <div id="content">
            <h1>XML Sitemap</h1>
            <p class="desc">
              This XML sitemap is used by search engines which follow the
              <a href="https://www.sitemaps.org">XML sitemap standard</a>.
            </p>
            <table>
              <tr>
                <th style="width:80%">URL</th>
                <th style="width:5%">Images</th>
                <th style="width:15%">Last Modified</th>
              </tr>
              <xsl:for-each select="sitemap:urlset/sitemap:url">
                <tr>
                  <td class="url">
                    <a href="{sitemap:loc}"><xsl:value-of select="sitemap:loc"/></a>
                  </td>
                  <td>
                    <xsl:value-of select="count(image:image)"/>
                  </td>
                  <td>
                    <xsl:value-of select="concat(substring(sitemap:lastmod, 0, 11), ' ', substring(sitemap:lastmod, 12, 5))"/>
                  </td>
                </tr>
              </xsl:for-each>
            </table>
            <p id="footer">
              Generated by <a href="https://github.com/marcosgz/site_maps">SiteMaps</a>
            </p>
          </div>
        </body>
      </html>
    </xsl:template>
  </xsl:stylesheet>
XSL
INDEX_XSL =
<<~XSL
  <?xml version="1.0" encoding="UTF-8"?>
  <xsl:stylesheet version="2.0"
    xmlns:html="http://www.w3.org/TR/REC-html40"
    xmlns:sitemap="http://www.sitemaps.org/schemas/sitemap/0.9"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output method="html" version="1.0" encoding="UTF-8" indent="yes"/>
    <xsl:template match="/">
      <html xmlns="http://www.w3.org/1999/xhtml">
        <head>
          <title>XML Sitemap Index</title>
          <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
          <style type="text/css">
            body {
              font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif;
              font-size: 13px;
              color: #545353;
            }
            a { color: #05809e; text-decoration: none; }
            a:visited { color: #06577d; }
            a:hover { text-decoration: underline; }
            #content {
              margin: 0 auto;
              padding: 0 20px;
              max-width: 1200px;
            }
            h1 { font-size: 24px; margin: 20px 0 10px; }
            p.desc { color: #777; margin: 0 0 20px; }
            table {
              border: none;
              border-collapse: collapse;
              width: 100%;
              margin: 0 0 20px;
            }
            th {
              text-align: left;
              padding: 10px 8px;
              font-size: 12px;
              border-bottom: 1px solid #ccc;
            }
            td {
              padding: 8px;
              font-size: 12px;
              border-bottom: 1px solid #eee;
            }
            tr:nth-child(odd) td { background-color: #f8f8f8; }
            tr:hover td { background-color: #e8e8e8; }
            td.url { max-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
            #footer { margin: 10px 0 30px; font-size: 11px; color: #999; }
          </style>
        </head>
        <body>
          <div id="content">
            <h1>XML Sitemap Index</h1>
            <p class="desc">
              This XML sitemap index file contains
              <xsl:value-of select="count(sitemap:sitemapindex/sitemap:sitemap)"/> sitemaps.
            </p>
            <table>
              <tr>
                <th style="width:75%">Sitemap</th>
                <th style="width:25%">Last Modified</th>
              </tr>
              <xsl:for-each select="sitemap:sitemapindex/sitemap:sitemap">
                <tr>
                  <td class="url">
                    <a href="{sitemap:loc}"><xsl:value-of select="sitemap:loc"/></a>
                  </td>
                  <td>
                    <xsl:value-of select="concat(substring(sitemap:lastmod, 0, 11), ' ', substring(sitemap:lastmod, 12, 5))"/>
                  </td>
                </tr>
              </xsl:for-each>
            </table>
            <p id="footer">
              Generated by <a href="https://github.com/marcosgz/site_maps">SiteMaps</a>
            </p>
          </div>
        </body>
      </html>
    </xsl:template>
  </xsl:stylesheet>
XSL

Class Method Summary collapse

Class Method Details

.index_xslObject



187
188
189
# File 'lib/site_maps/builder/xsl_stylesheet.rb', line 187

def index_xsl
  INDEX_XSL
end

.processing_instruction(url) ⇒ Object



179
180
181
# File 'lib/site_maps/builder/xsl_stylesheet.rb', line 179

def processing_instruction(url)
  %(<?xml-stylesheet type="text/xsl" href="#{url}"?>)
end

.urlset_xslObject



183
184
185
# File 'lib/site_maps/builder/xsl_stylesheet.rb', line 183

def urlset_xsl
  URLSET_XSL
end