Brightspot CMS Developer Guide

Implementing sitemaps for custom content types


To generate sitemap entries for custom content types, ensure those types implement Directory.Item, SiteMapItem, and optionally SiteMapConfig.


Step 1: Implement SiteMapItem

For a custom content type to be included in a sitemap, it must:

  • Extend Content.
  • Implement the method SiteMapItem#getSiteMapEntries. This method returns a list of SiteMapEntry objects. A SiteMapEntry object provides a URL and other information about an asset. The resulting sitemap XML for an asset is determined by the SiteMapEntry methods that you set in the implementation.

The following example shows a getSiteMapEntries() implementation.

public class MyContentType extends Content implements
    Directory.Item, /* Generates permalinks used in sitemaps. */
    SiteMapItem {   /* Generates a list of sitemap entries. */

    @Override
    public List<SiteMapEntry> getSiteMapEntries() {
        List<SiteMapEntry> siteMapEntries = new ArrayList<>();

        /*
        * Loop over all sites hosting this object. If the site
        * itself has a permalink, create a sitemap entry for the object.
        */
        Site.Static.findAll().forEach(e -> {

            String sitePermalink = as(Directory.ObjectModification.class).getSitePermalink(e);

            if (!StringUtils.isBlank(sitePermalink)) {
                SiteMapEntry siteMapEntry = new SiteMapEntry();
                siteMapEntry.setUpdateDate(getUpdateDate());
                siteMapEntry.setPermalink(sitePermalink);
                siteMapEntries.add(siteMapEntry);
            }
        });

        /* Return the list of sitemap entries associated with this object. */
        return siteMapEntries;
    }
}

For content types that you want to include in the news- or video-sitemap, implement the NewsSiteMapItem or VideoSiteMapItem interface.

Step 2 (optional): Implement SiteMapConfig

Sitemap configuration informs the background tasks about the types of sitemaps to generate and when to generate them. Brightspot provides a default sitemap configuration that accommodates any custom content types that you add; however, if you want a custom sitemap configuration, you must implement SiteMapConfig and related interfaces.

The SiteMapConfig is a subinterface of GlobalSiteMapConfig, which includes the getJobSettings() method. Implementing this method requires that you implement the JobSettings interface.

The following snippet shows a partial implementation of SiteMapConfig.

public class MySiteMapConfig implements SiteMapConfig {

   @Override
   public JobSettings getJobSettings() {
      return new JobSettings() {

         /*
         * Check for correct host. As a best practice, implement this method to call
         * TaskUtils.isRunningOnTaskHost(). Doing so verifies that the host on which
         * the sitemap generation task will run is the host configured in
         * Admin > Sites & Settings > Global > Debug > Default Task Host.
         */
         @Override
         public boolean isAllowedToRun() {
             return TaskUtils.isRunningOnTaskHost();
         }

         /* Time to run task. */
         @Override
         public DateTime calculateRunTime(DateTime currentTime) {
             return currentTime.property(DateTimeFieldType.dayOfMonth()).roundFloorCopy();
         }

         /* Job identification in log. */
         @Override
         public String getLabel() {
             return "Sitemap Settings";
         }
      };
   }

   /* Additionally implemented SiteMapConfig and GlobalSiteMapConfig methods */
}

Previous Topic
Viewing sitemap background tasks
Next Topic
Notifications
Was this topic helpful?
Thanks for your feedback.
Our robust, flexible Design System provides hundreds of pre-built components you can use to build the presentation layer of your dreams.

Asset types
Module types
Page types
Brightspot is packaged with content types that get you up and running in a matter of days, including assets, modules and landing pages.

Content types
Modules
Landing pages
Everything you need to know when creating, managing, and administering content within Brightspot CMS.

Dashboards
Publishing
Workflows
Admin configurations
A guide for installing, supporting, extending, modifying and administering code on the Brightspot platform.

Field types
Content modeling
Rich-text elements
Images
A guide to configuring Brightspot's library of integrations, including pre-built options and developer-configured extensions.

Google Analytics
Shopify
Apple News