@page "/examples.xml"
@inject RadzenBlazorDemos.ExampleService ExampleService
@{
    Layout = null;
    Response.ContentType = "text/xml";
}
<urlset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd">
    @foreach (var category in ExampleService.Examples)
    {
        @if (category.Path != null)
        {
            <url>
                <loc>@Location(category.Path)</loc>
                <lastmod>@lastmod</lastmod>
                <priority>1</priority>
            </url>
        }
        @if (category.Children != null)
        {
            @foreach (var example in category.Children)
            {
                if (example.Children != null)
                {
                    @foreach (var child in example.Children)
                    {
                        <url>
                            <loc>@Location(child.Path)</loc>
                            <lastmod>@lastmod</lastmod>
                            <priority>1</priority>
                        </url>
                    }
                }
                else
                {
                    <url>
                        <loc>@Location(example.Path)</loc>
                        <lastmod>@lastmod</lastmod>
                        <priority>1</priority>
                    </url>
                }
            }
        }
    }
</urlset>
@functions {
    string lastmod = DateTime.Today.ToString("yyyy-MM-dd");

    string Location(string path)
    {
        if (!path.StartsWith("/"))
        {
            path = $"/{path}";
        }

        return $"https://blazor.radzen.com{path}";
    }
}