sgammon/GUST

View on GitHub
java/gust/backend/builtin/sitemap.soy

Summary

Maintainability
Test Coverage
/*
 * Copyright © 2020, The Gust Framework Authors. All rights reserved.
 *
 * The Gust/Elide framework and tools, and all associated source or object computer code, except where otherwise noted,
 * are licensed under the Zero Prosperity license, which is enclosed in this repository, in the file LICENSE.txt. Use of
 * this code in object or source form requires and implies consent and agreement to that license in principle and
 * practice. Source or object code not listing this header, or unless specified otherwise, remain the property of
 * Elide LLC and its suppliers, if any. The intellectual and technical concepts contained herein are proprietary to
 * Elide LLC and its suppliers and may be covered by U.S. and Foreign Patents, or patents in process, and are protected
 * by trade secret and copyright law. Dissemination of this information, or reproduction of this material, in any form,
 * is strictly forbidden except in adherence with assigned license requirements.
 */
{namespace gust.builtins.sitemap}


/**
 * Render the change frequency type for a given page.
 */
{template .changeFrequency visibility="private" kind="text"}
  {@param frequency: builtin.sitemap.Sitemap.ChangeFrequency}  // Page change frequency.

  {switch $frequency}
    {case 0}none
    {case 1}daily
    {case 2}weekly
    {case 3}monthly
    {case 4}yearly
  {/switch}
{/template}

/**
 * Render a single sitemap entry, as part of a larger site map. Individual sitemap entries specify details regarding a
 * single page, including the location, change frequency, priority, and last-modified-time.
 */
{template .sitemapEntry visibility="private"}
  {@param entry: builtin.sitemap.Sitemap.PageEntry}  // Page entry record to render.

  <url>
    <loc>{$entry.location}</loc>
    {if isNonnull($entry.lastModified) and $entry.lastModified != ''}
      <lastmod>{$entry.lastModified}</lastmod>
    {/if}
    {if isNonnull($entry.changeFrequency) and $entry.changeFrequency != 0}
      {let $renderedFreq kind="text"}
        {call .changeFrequency}
          {param frequency: $entry.changeFrequency /}
        {/call}
      {/let}
      <changefreq>{$renderedFreq}</changefreq>
    {/if}
    {if isNonnull($entry.priority) and $entry.priority != ''}
      <priority>{$entry.priority}</priority>
    {/if}
  </url>
{/template}


/**
 * Calculate a URL to use when referring to a given JavaScript or CSS asset. This factors in the notion of *CDN
 * prefixes*, which are hostnames that are applied to the beginning of the link.
 */
{template .sitemapFile}
  {@param sitemap: builtin.sitemap.Sitemap}  // Sitemap record to render.

  <urlset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
          xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd">
    {for $entry in $sitemap.pageList}
      {call .sitemapEntry}
        {param entry: $entry /}
      {/call}
    {/for}
  </urlset>
{/template}