diff --git a/Components/App.razor b/Components/App.razor index 02c2d33..8ba057e 100644 --- a/Components/App.razor +++ b/Components/App.razor @@ -8,7 +8,7 @@ - + @@ -34,7 +34,7 @@ }(window.location)) - @* *@ + diff --git a/Program.cs b/Program.cs index f0c5326..198df5b 100644 --- a/Program.cs +++ b/Program.cs @@ -23,6 +23,14 @@ app.UseStaticFiles(); app.UseAntiforgery(); app.MapRazorComponents(); +app.MapGet("/sitemap.xml", async (HttpContext context) => +{ + var blogService = context.RequestServices.GetRequiredService(); + var sitemap = blogService.GenerateSitemap(); + + context.Response.Headers.Add(HeaderNames.ContentType, "application/xml"); + await context.Response.WriteAsync(sitemap); +}); app.MapGet("/robots.txt", // ?? return a valid robots.txt () => """ User-agent: * diff --git a/Services/BlogService.cs b/Services/BlogService.cs index d4e4954..fdc9e6c 100644 --- a/Services/BlogService.cs +++ b/Services/BlogService.cs @@ -1,11 +1,14 @@ using Markdig; using StaticBlog3.Models; +using System.Text; using System.Text.Json; - +using System.Xml; +using Microsoft.Extensions.Configuration; namespace StaticBlog3.Services { public class BlogService { + private readonly string _blogDirectory = "wwwroot/blogs"; public IEnumerable GetBlogPosts() @@ -118,6 +121,40 @@ public IEnumerable GetPopularBlogPostsByViews(int numberOfPosts) return topBlogPosts; } + public string GenerateSitemap() + { + + var blogPosts = GetBlogPosts(); + + var sitemap = new StringBuilder(); + var settings = new XmlWriterSettings + { + Indent = true + }; + + using (var writer = XmlWriter.Create(sitemap, settings)) + { + writer.WriteStartDocument(); + writer.WriteStartElement("urlset", "http://www.sitemaps.org/schemas/sitemap/0.9"); + + foreach (var blogPost in blogPosts) + { + writer.WriteStartElement("url"); + + writer.WriteElementString("loc", "https://example.com/" + blogPost.Slug); // Replace with your actual blog URL + writer.WriteElementString("lastmod", blogPost.Date.ToString("yyyy-MM-ddTHH:mm:sszzz")); + writer.WriteElementString("changefreq", "monthly"); // You can adjust this frequency as needed + writer.WriteElementString("priority", "0.8"); // You can adjust this priority as needed + + writer.WriteEndElement(); // Close the "url" element + } + + writer.WriteEndElement(); // Close the "urlset" element + writer.WriteEndDocument(); + } + + return sitemap.ToString(); + } } } diff --git a/appsettings.json b/appsettings.json index 10f68b8..b9af2c1 100644 --- a/appsettings.json +++ b/appsettings.json @@ -5,5 +5,6 @@ "Microsoft.AspNetCore": "Warning" } }, + "BaseUrl": "https://example.com/", "AllowedHosts": "*" } diff --git a/wwwroot/404.html b/wwwroot/404.html index 29100db..375bef6 100644 --- a/wwwroot/404.html +++ b/wwwroot/404.html @@ -16,6 +16,7 @@
+ diff --git a/wwwroot/app.css b/wwwroot/app.css index c67a41d..7331f44 100644 --- a/wwwroot/app.css +++ b/wwwroot/app.css @@ -1,5 +1,5 @@ html, body { - font-family: 'Roboto', sans-serif; + font-family: 'Poppins', sans-serif; } .bd-placeholder-img { font-size: 1.125rem; diff --git a/wwwroot/blogs/The-Enigmatic-World-of-Carnivorous-Plants.md b/wwwroot/blogs/The-Enigmatic-World-of-Carnivorous-Plants.md index 680a34d..ef65e53 100644 --- a/wwwroot/blogs/The-Enigmatic-World-of-Carnivorous-Plants.md +++ b/wwwroot/blogs/The-Enigmatic-World-of-Carnivorous-Plants.md @@ -7,7 +7,7 @@ "Content": null, "Slug": "The-Enigmatic-World-of-Carnivorous-Plants", "FeaturedImage": "https://images.unsplash.com/photo-1538358519265-586278a34106?q=60\u0026w=780", - "Views": 179, + "Views": 180, "Author": "abkhan", "AuthorImg": "/profile/user1.png", "Thumbnail": "/images/plant6_thumbnail.jpg", diff --git a/wwwroot/blogs/The-Marvelous-World-of-Bonsai.md b/wwwroot/blogs/The-Marvelous-World-of-Bonsai.md index 3ab8006..a2a4431 100644 --- a/wwwroot/blogs/The-Marvelous-World-of-Bonsai.md +++ b/wwwroot/blogs/The-Marvelous-World-of-Bonsai.md @@ -7,7 +7,7 @@ "Content": null, "Slug": "The-Marvelous-World-of-Bonsai", "FeaturedImage": "/images/plant5.jpg", - "Views": 227, + "Views": 230, "Author": "DesertDreamer", "AuthorImg": "/profile/user2.png", "Thumbnail": "/images/plant5_thumbnail.jpg", diff --git a/wwwroot/images/Compressed/Headphone.png b/wwwroot/images/Compressed/Headphone.png deleted file mode 100644 index ea6cd61..0000000 Binary files a/wwwroot/images/Compressed/Headphone.png and /dev/null differ diff --git a/wwwroot/images/Compressed/blog1.jpg b/wwwroot/images/Compressed/blog1.jpg deleted file mode 100644 index b222267..0000000 Binary files a/wwwroot/images/Compressed/blog1.jpg and /dev/null differ diff --git a/wwwroot/images/Compressed/blog1_thumbnail.jpg b/wwwroot/images/Compressed/blog1_thumbnail.jpg deleted file mode 100644 index 1dd3c83..0000000 Binary files a/wwwroot/images/Compressed/blog1_thumbnail.jpg and /dev/null differ diff --git a/wwwroot/images/Compressed/blog2.jpg b/wwwroot/images/Compressed/blog2.jpg deleted file mode 100644 index 27dbd7e..0000000 Binary files a/wwwroot/images/Compressed/blog2.jpg and /dev/null differ diff --git a/wwwroot/images/Compressed/blog2_thumbnail.jpg b/wwwroot/images/Compressed/blog2_thumbnail.jpg deleted file mode 100644 index f56e8c0..0000000 Binary files a/wwwroot/images/Compressed/blog2_thumbnail.jpg and /dev/null differ diff --git a/wwwroot/images/Compressed/blog3.jpg b/wwwroot/images/Compressed/blog3.jpg deleted file mode 100644 index 4f5bc2b..0000000 Binary files a/wwwroot/images/Compressed/blog3.jpg and /dev/null differ diff --git a/wwwroot/images/Compressed/blog3_thumbnail.jpg b/wwwroot/images/Compressed/blog3_thumbnail.jpg deleted file mode 100644 index 8dd96df..0000000 Binary files a/wwwroot/images/Compressed/blog3_thumbnail.jpg and /dev/null differ diff --git a/wwwroot/images/Compressed/blog4.jpg b/wwwroot/images/Compressed/blog4.jpg deleted file mode 100644 index eae520b..0000000 Binary files a/wwwroot/images/Compressed/blog4.jpg and /dev/null differ diff --git a/wwwroot/images/Compressed/blog4_thumbnail.jpg b/wwwroot/images/Compressed/blog4_thumbnail.jpg deleted file mode 100644 index 3896210..0000000 Binary files a/wwwroot/images/Compressed/blog4_thumbnail.jpg and /dev/null differ diff --git a/wwwroot/images/Compressed/blog5.jpg b/wwwroot/images/Compressed/blog5.jpg deleted file mode 100644 index b222267..0000000 Binary files a/wwwroot/images/Compressed/blog5.jpg and /dev/null differ diff --git a/wwwroot/images/Compressed/blog5_thumbnail.jpg b/wwwroot/images/Compressed/blog5_thumbnail.jpg deleted file mode 100644 index 1dd3c83..0000000 Binary files a/wwwroot/images/Compressed/blog5_thumbnail.jpg and /dev/null differ diff --git a/wwwroot/images/Compressed/plant.jpg b/wwwroot/images/Compressed/plant.jpg deleted file mode 100644 index 0634eba..0000000 Binary files a/wwwroot/images/Compressed/plant.jpg and /dev/null differ diff --git a/wwwroot/images/Compressed/plant1_thumnail.jpg b/wwwroot/images/Compressed/plant1_thumnail.jpg deleted file mode 100644 index 126d926..0000000 Binary files a/wwwroot/images/Compressed/plant1_thumnail.jpg and /dev/null differ diff --git a/wwwroot/images/Compressed/plant2.jpg b/wwwroot/images/Compressed/plant2.jpg deleted file mode 100644 index ad332a1..0000000 Binary files a/wwwroot/images/Compressed/plant2.jpg and /dev/null differ diff --git a/wwwroot/images/Compressed/plant2_thumbnail.jpg b/wwwroot/images/Compressed/plant2_thumbnail.jpg deleted file mode 100644 index cb462b9..0000000 Binary files a/wwwroot/images/Compressed/plant2_thumbnail.jpg and /dev/null differ diff --git a/wwwroot/images/Compressed/plant3.jpg b/wwwroot/images/Compressed/plant3.jpg deleted file mode 100644 index 142666c..0000000 Binary files a/wwwroot/images/Compressed/plant3.jpg and /dev/null differ diff --git a/wwwroot/images/Compressed/plant3_thumbnail.jpg b/wwwroot/images/Compressed/plant3_thumbnail.jpg deleted file mode 100644 index f866c00..0000000 Binary files a/wwwroot/images/Compressed/plant3_thumbnail.jpg and /dev/null differ diff --git a/wwwroot/images/Compressed/plant4.jpeg b/wwwroot/images/Compressed/plant4.jpeg deleted file mode 100644 index 9ad03be..0000000 Binary files a/wwwroot/images/Compressed/plant4.jpeg and /dev/null differ diff --git a/wwwroot/images/Compressed/plant4.jpg b/wwwroot/images/Compressed/plant4.jpg deleted file mode 100644 index d8bdcaa..0000000 Binary files a/wwwroot/images/Compressed/plant4.jpg and /dev/null differ diff --git a/wwwroot/images/Compressed/plant4_thumbnail.jpeg b/wwwroot/images/Compressed/plant4_thumbnail.jpeg deleted file mode 100644 index 9ad03be..0000000 Binary files a/wwwroot/images/Compressed/plant4_thumbnail.jpeg and /dev/null differ diff --git a/wwwroot/images/Compressed/plant4_thumbnail.jpg b/wwwroot/images/Compressed/plant4_thumbnail.jpg deleted file mode 100644 index f6f6132..0000000 Binary files a/wwwroot/images/Compressed/plant4_thumbnail.jpg and /dev/null differ diff --git a/wwwroot/images/Compressed/plant5.jpg b/wwwroot/images/Compressed/plant5.jpg deleted file mode 100644 index a5efaca..0000000 Binary files a/wwwroot/images/Compressed/plant5.jpg and /dev/null differ diff --git a/wwwroot/images/Compressed/plant5_thumbnail.jpg b/wwwroot/images/Compressed/plant5_thumbnail.jpg deleted file mode 100644 index a5efaca..0000000 Binary files a/wwwroot/images/Compressed/plant5_thumbnail.jpg and /dev/null differ diff --git a/wwwroot/images/Compressed/plant6.jpg b/wwwroot/images/Compressed/plant6.jpg deleted file mode 100644 index de64532..0000000 Binary files a/wwwroot/images/Compressed/plant6.jpg and /dev/null differ diff --git a/wwwroot/images/Compressed/plant6_thumbnail.jpg b/wwwroot/images/Compressed/plant6_thumbnail.jpg deleted file mode 100644 index de64532..0000000 Binary files a/wwwroot/images/Compressed/plant6_thumbnail.jpg and /dev/null differ diff --git a/wwwroot/images/Compressed/plant7.jpg b/wwwroot/images/Compressed/plant7.jpg deleted file mode 100644 index 79335ec..0000000 Binary files a/wwwroot/images/Compressed/plant7.jpg and /dev/null differ diff --git a/wwwroot/images/Compressed/plant9.jpg b/wwwroot/images/Compressed/plant9.jpg deleted file mode 100644 index ad73a54..0000000 Binary files a/wwwroot/images/Compressed/plant9.jpg and /dev/null differ diff --git a/wwwroot/images/Compressed/plant_hero.png b/wwwroot/images/Compressed/plant_hero.png deleted file mode 100644 index 662d30e..0000000 Binary files a/wwwroot/images/Compressed/plant_hero.png and /dev/null differ diff --git a/wwwroot/images/Headphone.png b/wwwroot/images/Headphone.png deleted file mode 100644 index 32f4904..0000000 Binary files a/wwwroot/images/Headphone.png and /dev/null differ diff --git a/wwwroot/images/blog1.jpg b/wwwroot/images/blog1.jpg deleted file mode 100644 index fbeef4e..0000000 Binary files a/wwwroot/images/blog1.jpg and /dev/null differ diff --git a/wwwroot/images/blog1_thumbnail.jpg b/wwwroot/images/blog1_thumbnail.jpg deleted file mode 100644 index c06421b..0000000 Binary files a/wwwroot/images/blog1_thumbnail.jpg and /dev/null differ diff --git a/wwwroot/images/blog2.jpg b/wwwroot/images/blog2.jpg deleted file mode 100644 index 421f3dc..0000000 Binary files a/wwwroot/images/blog2.jpg and /dev/null differ diff --git a/wwwroot/images/blog2_thumbnail.jpg b/wwwroot/images/blog2_thumbnail.jpg deleted file mode 100644 index 0e670f1..0000000 Binary files a/wwwroot/images/blog2_thumbnail.jpg and /dev/null differ diff --git a/wwwroot/images/blog3.jpg b/wwwroot/images/blog3.jpg deleted file mode 100644 index f0ba024..0000000 Binary files a/wwwroot/images/blog3.jpg and /dev/null differ diff --git a/wwwroot/images/blog3_thumbnail.jpg b/wwwroot/images/blog3_thumbnail.jpg deleted file mode 100644 index 2699508..0000000 Binary files a/wwwroot/images/blog3_thumbnail.jpg and /dev/null differ diff --git a/wwwroot/images/blog4.jpg b/wwwroot/images/blog4.jpg deleted file mode 100644 index 223bee3..0000000 Binary files a/wwwroot/images/blog4.jpg and /dev/null differ diff --git a/wwwroot/images/blog4_thumbnail.jpg b/wwwroot/images/blog4_thumbnail.jpg deleted file mode 100644 index 503c23d..0000000 Binary files a/wwwroot/images/blog4_thumbnail.jpg and /dev/null differ diff --git a/wwwroot/images/blog5.jpg b/wwwroot/images/blog5.jpg deleted file mode 100644 index fbeef4e..0000000 Binary files a/wwwroot/images/blog5.jpg and /dev/null differ diff --git a/wwwroot/images/blog5_thumbnail.jpg b/wwwroot/images/blog5_thumbnail.jpg deleted file mode 100644 index c06421b..0000000 Binary files a/wwwroot/images/blog5_thumbnail.jpg and /dev/null differ