Skip to content

Commit

Permalink
merge results
Browse files Browse the repository at this point in the history
  • Loading branch information
ysmoradi committed Oct 28, 2024
2 parents 65987a2 + 938bd8c commit 1fe4920
Show file tree
Hide file tree
Showing 4 changed files with 124 additions and 4 deletions.
31 changes: 31 additions & 0 deletions src/BlazorUI/Demo/Bit.BlazorUI.Demo.Server/Startup/Middlewares.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Runtime.Loader;
using Bit.BlazorUI.Demo.Server.Components;
using HealthChecks.UI.Client;
using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Components.Endpoints;
using Microsoft.AspNetCore.Diagnostics.HealthChecks;
using Microsoft.AspNetCore.Http.Extensions;
Expand Down Expand Up @@ -81,6 +82,8 @@ public static void Use(WebApplication app, IWebHostEnvironment env, IConfigurati
});
}

UseSiteMap(app);

// Handle the rest of requests with blazor
app.MapStaticAssets();
app.MapRazorComponents<App>()
Expand Down Expand Up @@ -141,4 +144,32 @@ private static void Configure_401_403_404_Pages(WebApplication app)
}
});
}

private static void UseSiteMap(WebApplication app)
{
var urls = Assembly.Load("Bit.BlazorUI.Demo.Client.Core")
.ExportedTypes
.Where(t => typeof(IComponent).IsAssignableFrom(t))
.SelectMany(t => t.GetCustomAttributes<Microsoft.AspNetCore.Components.RouteAttribute>())
.Select(r => r.Template)
.ToList();

const string siteMapHeader = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n<urlset\r\n xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\"\r\n xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\r\n xsi:schemaLocation=\"http://www.sitemaps.org/schemas/sitemap/0.9\r\n http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd\">";

app.MapGet("/sitemap.xml", async context =>
{
if (siteMap is null)
{
var baseUrl = context.Request.GetBaseUrl();

siteMap = $"{siteMapHeader}{string.Join(Environment.NewLine, urls.Select(u => $"<url><loc>{new Uri(baseUrl, u)}</loc></url>"))}</urlset>";
}

context.Response.Headers.ContentType = "application/xml";

await context.Response.WriteAsync(siteMap, context.RequestAborted);
});
}

private static string? siteMap;
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@
using System.Runtime.Loader;
using Bit.Websites.Careers.Server.Components;
using HealthChecks.UI.Client;
using Microsoft.AspNetCore.Components.Endpoints;
using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Diagnostics.HealthChecks;
using Microsoft.AspNetCore.Http.Extensions;
using Microsoft.Net.Http.Headers;

namespace Bit.Websites.Careers.Server.Startup;

Expand Down Expand Up @@ -73,6 +72,8 @@ public static void Use(WebApplication app, IWebHostEnvironment env, IConfigurati
app.MapHealthChecksUI();
}

UseSiteMap(app);

app.MapStaticAssets();
app.MapRazorComponents<App>()
.AddInteractiveServerRenderMode()
Expand Down Expand Up @@ -113,4 +114,32 @@ private static void Configure_404_Page(WebApplication app)
}
});
}

private static void UseSiteMap(WebApplication app)
{
var urls = Assembly.Load("Bit.Websites.Careers.Client")
.ExportedTypes
.Where(t => typeof(IComponent).IsAssignableFrom(t))
.SelectMany(t => t.GetCustomAttributes<Microsoft.AspNetCore.Components.RouteAttribute>())
.Select(r => r.Template)
.ToList();

const string siteMapHeader = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n<urlset\r\n xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\"\r\n xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\r\n xsi:schemaLocation=\"http://www.sitemaps.org/schemas/sitemap/0.9\r\n http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd\">";

app.MapGet("/sitemap.xml", async context =>
{
if (siteMap is null)
{
var baseUrl = new Uri(context.Request.GetBaseUrl());

siteMap = $"{siteMapHeader}{string.Join(Environment.NewLine, urls.Select(u => $"<url><loc>{new Uri(baseUrl, u)}</loc></url>"))}</urlset>";
}

context.Response.Headers.ContentType = "application/xml";

await context.Response.WriteAsync(siteMap, context.RequestAborted);
});
}

private static string? siteMap;
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Runtime.Loader;
using Bit.Websites.Platform.Server.Components;
using HealthChecks.UI.Client;
using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Diagnostics.HealthChecks;
using Microsoft.AspNetCore.Http.Extensions;

Expand Down Expand Up @@ -71,6 +72,8 @@ public static void Use(WebApplication app, IWebHostEnvironment env, IConfigurati
app.MapHealthChecksUI();
}

UseSiteMap(app);

app.MapStaticAssets();
app.MapRazorComponents<App>()
.AddInteractiveServerRenderMode()
Expand Down Expand Up @@ -111,4 +114,32 @@ private static void Configure_404_Page(WebApplication app)
}
});
}

private static void UseSiteMap(WebApplication app)
{
var urls = Assembly.Load("Bit.Websites.Platform.Client")
.ExportedTypes
.Where(t => typeof(IComponent).IsAssignableFrom(t))
.SelectMany(t => t.GetCustomAttributes<Microsoft.AspNetCore.Components.RouteAttribute>())
.Select(r => r.Template)
.ToList();

const string siteMapHeader = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n<urlset\r\n xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\"\r\n xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\r\n xsi:schemaLocation=\"http://www.sitemaps.org/schemas/sitemap/0.9\r\n http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd\">";

app.MapGet("/sitemap.xml", async context =>
{
if (siteMap is null)
{
var baseUrl = new Uri(context.Request.GetBaseUrl());

siteMap = $"{siteMapHeader}{string.Join(Environment.NewLine, urls.Select(u => $"<url><loc>{new Uri(baseUrl, u)}</loc></url>"))}</urlset>";
}

context.Response.Headers.ContentType = "application/xml";

await context.Response.WriteAsync(siteMap, context.RequestAborted);
});
}

private static string? siteMap;
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@
using HealthChecks.UI.Client;
using Microsoft.AspNetCore.Diagnostics.HealthChecks;
using Microsoft.AspNetCore.Http.Extensions;
using Microsoft.Net.Http.Headers;
using Bit.Websites.Sales.Server.Components;
using System.Net;
using Microsoft.AspNetCore.Components.Endpoints;
using System.Runtime.Loader;
using Microsoft.AspNetCore.Components;

namespace Bit.Websites.Sales.Server.Startup;

Expand Down Expand Up @@ -73,6 +72,8 @@ public static void Use(WebApplication app, IWebHostEnvironment env, IConfigurati
app.MapHealthChecksUI();
}

UseSiteMap(app);

app.MapStaticAssets();
app.MapRazorComponents<App>()
.AddInteractiveServerRenderMode()
Expand Down Expand Up @@ -113,4 +114,32 @@ private static void Configure_404_Page(WebApplication app)
}
});
}

private static void UseSiteMap(WebApplication app)
{
var urls = Assembly.Load("Bit.Websites.Sales.Client")
.ExportedTypes
.Where(t => typeof(IComponent).IsAssignableFrom(t))
.SelectMany(t => t.GetCustomAttributes<Microsoft.AspNetCore.Components.RouteAttribute>())
.Select(r => r.Template)
.ToList();

const string siteMapHeader = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n<urlset\r\n xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\"\r\n xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\r\n xsi:schemaLocation=\"http://www.sitemaps.org/schemas/sitemap/0.9\r\n http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd\">";

app.MapGet("/sitemap.xml", async context =>
{
if (siteMap is null)
{
var baseUrl = new Uri(context.Request.GetBaseUrl());

siteMap = $"{siteMapHeader}{string.Join(Environment.NewLine, urls.Select(u => $"<url><loc>{new Uri(baseUrl, u)}</loc></url>"))}</urlset>";
}

context.Response.Headers.ContentType = "application/xml";

await context.Response.WriteAsync(siteMap, context.RequestAborted);
});
}

private static string? siteMap;
}

0 comments on commit 1fe4920

Please sign in to comment.