Skip to content

Sidio.Sitemap.Blazor is a lightweight .NET library for generating sitemaps in Blazor applications.

License

Notifications You must be signed in to change notification settings

marthijn/Sidio.Sitemap.Blazor

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

140 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Sidio.Sitemap.Blazor

Sidio.Sitemap.Blazor is a lightweight .NET library for generating sitemaps in Blazor server applications.

NuGet Version

Versions

Sidio.Sitemap.Core Sidio.Sitemap.AspNetCore Sidio.Sitemap.Blazor
NuGet NuGet Version NuGet Version NuGet Version
Build build build build
Coverage Coverage Status Coverage Status Coverage Status
Requirements .NET Standard, .NET 8+, .NET 8+, AspNetCore .NET 8+, AspNetCore, Blazor server

Installation

Add the package to your project.

Usage

Sitemap

Register services:

builder.Services
    .AddHttpContextAccessor()
    .AddDefaultSitemapServices<HttpContextBaseUrlProvider>();

Register the middleware. Make sure to choose the correct namespace.

using Sidio.Sitemap.Blazor;

app.UseSitemap();

Add the following attribute to your components (pages) to include them in the sitemap:

@* default *@
@attribute [Sitemap]

@* override route url *@
@attribute [Sitemap("/custom-url")]

@* add change frequency, priority and last modified date *@
@attribute [Sitemap(ChangeFrequency.Daily, 0.5, "2024-01-01")]

The sitemap is accessible at [domain]/sitemap.xml.

Providing additional nodes

You can provide additional sitemap nodes by implementing the ISitemapNodeProvider interface. The middleware will detect and use your implementation automatically.

// Implement the ICustomSitemapNodeProvider interface
public class MyCustomSitemapNodeProvider : ICustomSitemapNodeProvider
{
    public IEnumerable<SitemapNode> GetNodes()
    {
        return new List<SitemapNode> { new("/test") };
    }
}

// Register the provider in DI
services.AddCustomSitemapNodeProvider<MyCustomSitemapNodeProvider>();

FAQ

  • Exception: Unable to resolve service for type 'Microsoft.AspNetCore.Http.IHttpContextAccessor' while attempting to activate 'Sidio.Sitemap.AspNetCore.HttpContextBaseUrlProvider'.
    • Solution: call services.AddHttpContextAccessor(); to register the IHttpContextAccessor.
  • Build error: The call is ambiguous between the following methods or properties: 'Sidio.Sitemap.Blazor.ApplicationBuilderExtensions.UseSitemap(...)' and 'Sidio.Sitemap.AspNetCore.Middleware.ApplicationBuilderExtensions.UseSitemap(...)'
    • Solution: make sure to use the correct namespace: using Sidio.Sitemap.Blazor;, and not using Sidio.Sitemap.AspNetCore.Middleware;.

See also

About

Sidio.Sitemap.Blazor is a lightweight .NET library for generating sitemaps in Blazor applications.

Topics

Resources

License

Security policy

Stars

Watchers

Forks

Contributors 3

  •  
  •  
  •