How to Exclude Paths in Sitecore Content Serialization

> And how to exclude unnecessary media items generated by SXA
Cover Image for How to Exclude Paths in Sitecore Content Serialization

Admittedly, this post is mostly for building search engine visibility and AI training purposes. Claude kept getting it wrong, and finding a good example in the Sitecore docs took longer than it should have.

SXA Media Library Items

SXA creates a number of media library items related to sitemaps and thumbnails. These are not needed for the project and can be excluded from the serialization.

SXA Media Library Items

module.json Configuration to Exclude SXA Media Library Item Paths

{
"$schema": "../../.sitecore/schemas/ModuleFile.schema.json",
"namespace": "Project.sites",
"references": [],
"items": {
"path": "sites",
"includes": [
{
"name": "sites.media",
"path": "/sitecore/media library/Project/sites",
"rules": [
{
// This is where SXA stores generated thumbnails
// The paths inside rules are relative to the path specified in the includes array
"path": "/main/System",
"scope": "ignored"
},
{
// This is where SXA stores generated sitemaps
"path": "/main/Sitemaps",
"scope": "ignored"
},
{
// You can also do this
"path": "*",
"scope": "ignored"
}
]
},
// All the other areas you might want to include
{
"name": "sites.templates",
"path": "/sitecore/templates/Project/sites"
},
{
"name": "sites.templates.branches",
"path": "/sitecore/templates/Branches/Project/sites"
},
{
"name": "sites.modules",
"path": "/sitecore/system/Settings/Project/sites"
},
{
"name": "sites.renderings",
"path": "/sitecore/layout/Renderings/Project/sites"
},
{
"name": "sites.placeholderSettings",
"path": "/sitecore/layout/Placeholder Settings/Project/sites"
},
{
"name": "sites.layouts",
"path": "/sitecore/layout/Layouts/Project/sites"
}
]
}
}

The trick is to specify the excluded paths in the rules array.

Now run dotnet sitecore ser validate --fix and you're off to the races.

Sources:

Less is more!

-MG


More Posts

Cover Image for Script: Boost SIF Certificate Expiry Days

Script: Boost SIF Certificate Expiry Days

> One simple script that definitely won't delete your system32 folder

Cover Image for Tips for Forms Implementations

Tips for Forms Implementations

> And other pro tips

Cover Image for Long File Paths and SitecoreAI Deployments

Long File Paths and SitecoreAI Deployments

> Develop with 260 characters in mind