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
SiteMapEntryobject provides a URL and other information about an asset. The resulting sitemap XML for an asset is determined by theSiteMapEntrymethods that you set in the implementation.
The following example shows a getSiteMapEntries() implementation.
1public class MyContentType extends Content implements2Directory.Item, /* Generates permalinks used in sitemaps. */3SiteMapItem { /* Generates a list of sitemap entries. */45@Override6public List<SiteMapEntry> getSiteMapEntries() {7List<SiteMapEntry> siteMapEntries = new ArrayList<>();89/*10* Loop over all sites hosting this object. If the site11* itself has a permalink, create a sitemap entry for the object.12*/13Site.Static.findAll().forEach(e -> {1415String sitePermalink = as(Directory.ObjectModification.class).getSitePermalink(e);1617if (!StringUtils.isBlank(sitePermalink)) {18SiteMapEntry siteMapEntry = new SiteMapEntry();19siteMapEntry.setUpdateDate(getUpdateDate());20siteMapEntry.setPermalink(sitePermalink);21siteMapEntries.add(siteMapEntry);22}23});2425/* Return the list of sitemap entries associated with this object. */26return siteMapEntries;27}28}
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.
1public class MySiteMapConfig implements SiteMapConfig {23@Override4public JobSettings getJobSettings() {5return new JobSettings() {67/*8* Check for correct host. As a best practice, implement this method to call9* TaskUtils.isRunningOnTaskHost(). Doing so verifies that the host on which10* the sitemap generation task will run is the host configured in11* Admin > Sites & Settings > Global > Debug > Default Task Host.12*/13@Override14public boolean isAllowedToRun() {15return TaskUtils.isRunningOnTaskHost();16}1718/* Time to run task. */19@Override20public DateTime calculateRunTime(DateTime currentTime) {21return currentTime.property(DateTimeFieldType.dayOfMonth()).roundFloorCopy();22}2324/* Job identification in log. */25@Override26public String getLabel() {27return "Sitemap Settings";28}29};30}3132/* Additionally implemented SiteMapConfig and GlobalSiteMapConfig methods */33}