Geta Optimizely Sitemaps

Search engine sitemaps.xml for Optimizely CMS 13 and Commerce 15
Description
This tool allows you to generate xml sitemaps for search engines to better index your Optimizely sites.
Features
- sitemap generation as a scheduled job, or from the admin page with the “Generate sitemaps” button
- filtering pages by virtual directories
- ability to include pages that are in a different branch than the one of the start page
- ability to generate sitemaps for mobile pages
- it also supports multi-site and multi-language environments
- ability to augment URL generation
See the editor guide for more information.
Installation
Version 5 requires Optimizely CMS 13.1 or later, and the Commerce package requires Optimizely Commerce 15. The packages are published to the Optimizely NuGet feed, https://api.nuget.optimizely.com/v3/index.json.
The command below will install Sitemaps into your Optimizely project.
dotnet add package Geta.Optimizely.Sitemaps
The command below will install Sitemaps Commerce support into your Optimizely Commerce project.
dotnet add package Geta.Optimizely.Sitemaps.Commerce
Configuration
For the Sitemaps to work, you have to call AddSitemaps extension method in Startup.ConfigureServices method. This method provides a configuration of default values. Below is a code with all possible configuration options:
services.AddSitemaps(x =>
{
x.EnableRealtimeSitemap = false;
x.EnableRealtimeCaching = true;
x.RealtimeCacheExpirationInMinutes = 60;
});
You can configure access to the sitemaps configuration tab by adding a custom policy (the default is WebAdmins):
services.AddSitemaps(x =>
{
x.EnableRealtimeSitemap = false;
x.EnableRealtimeCaching = true;
x.RealtimeCacheExpirationInMinutes = 60;
}, p => p.RequireRole(Roles.Administrators));
If your site uses Opti ID and the sitemaps tab redirects to a login page that refuses to load in the frame, or its buttons do nothing, the policy needs the Opti ID authentication scheme. The tab is hosted outside the CMS’s own paths, so it doesn’t get the scheme from the CMS:
services.AddSitemaps(x => { }, p =>
{
p.AddAuthenticationSchemes(OptimizelyIdentityDefaults.SchemeName);
p.RequireRole(Roles.CmsAdmins);
});
And for the Commerce support add a call to:
services.AddSitemapsCommerce();
In order to augment Urls for a given set of content one must prepare to build a service that identifies content to be augmented
and yields augmented Uris from IUriAugmenterService.GetAugmentUris(IContent content, CurrentLanguageContent languageContentInfo, Uri fullUri) method.
- Create a service that implements IUriAugmenterService yielding multiple Uris per single input content/language/Uri..
- Ensure the services is set, overring the default service, within the optionsAction of AddSitemaps. For example:
services.AddSitemaps(options =>
{
options.SetAugmenterService<SitemapUriParameterAugmenterService>();
});
The service is called for all content that goes into the sitemap, so return the original Uri for content it shouldn’t change. Content that gets no URLs from the service is left out of the sitemap.
It is also possible to configure the application in appsettings.json file. A configuration from the appsettings.json will override configuration configured in Startup. Below is an appsettings.json configuration example.
"Geta": {
"Sitemaps": {
"EnableRealtimeSitemap": true,
"RealtimeCacheExpirationInMinutes": 30
}
}
Also, you have to add Razor pages routing support. In a Startup class, map them in UseEndpoints:
app.UseEndpoints(endpoints =>
{
endpoints.MapContent();
endpoints.MapRazorPages();
});
With the minimal hosting model, where everything is in Program.cs, call app.MapRazorPages(); instead.
Usage
Adding Sitemap Properties to all content pages
Credits to jarihaa for contributing this.
using Geta.Optimizely.Sitemaps.SpecializedProperties;
[UIHint("SeoSitemap")]
[BackingType(typeof(PropertySEOSitemaps))]
public virtual string SEOSitemaps { get; set; }
Translate the editor
The property editor’s labels can be translated with a language file, for example an embedded XML file registered with AddEmbeddedLocalization. The editor uses the editor’s UI language, and keys that aren’t translated keep their English default. These are the keys and their defaults:
<languages>
<language name="Svenska" id="sv">
<seositemaps>
<editor>
<enabled>Enabled</enabled>
<changefrequency>Change frequency</changefrequency>
<priority>Priority</priority>
<always>Always</always>
<hourly>Hourly</hourly>
<daily>Daily</daily>
<weekly>Weekly</weekly>
<monthly>Monthly</monthly>
<yearly>Yearly</yearly>
<never>Never</never>
<low>Low</low>
<medium>Medium</medium>
<mediumhigh>Medium-High</mediumhigh>
<high>High</high>
</editor>
</seositemaps>
</language>
</languages>
Set default value
public override void SetDefaultValues(ContentType contentType)
{
base.SetDefaultValues(contentType);
var sitemap = new PropertySEOSitemaps
{
Enabled = false
};
sitemap.Serialize();
this.SEOSitemaps = sitemap.ToString();
}
Ignore page types
Implement the IExcludeFromSitemap interface to ignore page types in the sitemap.
using Geta.Optimizely.Sitemaps.Models;
public class OrderConfirmationPage : PageData, IExcludeFromSitemap
Exclude content
If you need more control to exclude content from the sitemap you can make your own implementation of IContentFilter. Make sure to inherit from ContentFilter and call the ShouldExcludeContent method of the base class.
using EPiServer.Web;
using Geta.Optimizely.Sitemaps.Configuration;
using Geta.Optimizely.Sitemaps.Utils;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
public class SiteContentFilter : ContentFilter
{
public SiteContentFilter(
TemplateResolver templateResolver,
ILogger<ContentFilter> logger,
IOptions<SitemapOptions> sitemapOptions)
: base(templateResolver, logger, sitemapOptions)
{
}
public override bool ShouldExcludeContent(IContent content)
{
if (base.ShouldExcludeContent(content))
{
return true;
}
// Custom logic here
return false;
}
}
Register in your DI container. Be sure to register you custom ContentFilter after calling services.AddSitemaps(), otherwise the default ContentFilter will be used.
services.AddTransient<IContentFilter, SiteContentFilter>();
Limitations
- Each sitemap will contain max 50k entries (according to sitemaps.org protocol). Sitemaps are not split automatically: entries over the limit are left out, and the scheduled job’s result says so. If the site in which you are using this plugin contains more active pages then you should split them over multiple sitemaps (by specifying a different root page or include/avoid paths for each).
🏁 Getting Started
📦 Prerequisites
Ensure your system is properly configured to meet all prerequisites for Geta Foundation Core listed here
🐑 Cloning the repository
git clone https://github.com/Geta/geta-optimizely-sitemaps.git
cd geta-optimizely-sitemaps
git submodule update --init
🚀 Running with Aspire (Recommended)
# Windows
cd sub/geta-foundation-core/src/Foundation.AppHost
dotnet run
# Linux / MacOS
sudo env "PATH=$PATH" bash
chmod +x sub/geta-foundation-core/src/Foundation/docker/build-script/*.sh
cd sub/geta-foundation-core/src/Foundation.AppHost
dotnet run
🖥️ Running as Standalone
# Windows
cd sub/geta-foundation-core
./setup.cmd
cd ../../src/Geta.Optimizely.Sitemaps.Web
dotnet run
# Linux / MacOS
sudo env "PATH=$PATH" bash
cd sub/geta-foundation-core
chmod +x *.sh
./setup.sh
cd ../../src/Geta.Optimizely.Sitemaps.Web
dotnet run
If you run into any issues, check the FAQ section here
CMS username: [email protected]
Password: Episerver123!
Contributing
See CONTRIBUTING.md
Package maintainer
https://github.com/marisks
Changelog
Changelog
评论