Read route metadata

List every route Bevel maps with BevelEndpointRegistry, for example to build a custom sitemap or check links.

On this page
csharp
var routes = await registry.GetRoutesAsync(serviceProvider);
var pages = routes.Where(r => r is { IsPage: true, IsExported: true });

Call GetRoutesAsync on BevelEndpointRegistry to see every route. Use it for a sitemap, a search index or a link check.

Build a custom sitemap

This sitemap keeps exported pages and skips the 404 page:

Program.cscsharp
app.MapStatic("/sitemap.xml", async (ISiteData data, BevelEndpointRegistry registry, IServiceProvider sp) =>
{
    var routes = await registry.GetRoutesAsync(sp);
    var pages = routes
        .Where(r => r is { IsPage: true, IsExported: true } && r.Path != "/404.html")
        .Select(r => data.Site.BaseUrl.TrimEnd('/') + r.Path);
    return BevelResults.Xml(BuildSitemap(pages));
});

What a route holds

csharp
public sealed record BevelRouteInfo(
    string Path, bool IsPage, string? ContentType, bool IsExported,
    Type? PageType, Type? ItemType, object? Item);

Task<IReadOnlyList<BevelRouteInfo>> BevelEndpointRegistry.GetRoutesAsync(
    IServiceProvider, CancellationToken = default)
  • There is one entry per route. .html and /index.html aliases are not listed. A paged root route appears once.
  • Path is route-relative and never includes PathBase.
  • IsPage is true for MapStatic<TPage> and MapStaticPaged. /404.html is a page, so skip it yourself.
  • ContentType is text/html for pages. For handler routes it is inferred from the file extension (/rss.xml) and may be null.
  • IsExported is false for routes with ExcludeFromStaticExport(). Those routes are still listed.
  • GetAllRoutesAsync returns the paths of exported routes only.