Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Components/App.razor
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<link rel="stylesheet" href="bootstrap/bootstrap.min.css" />
<link rel="stylesheet" href="app.css" />
<link rel="icon" type="image/png" href="favicon.png" />

<link href="https://fonts.googleapis.com/css2?family=Poppins&display=swap" rel="stylesheet">
<HeadOutlet />
</head>

Expand All @@ -34,7 +34,7 @@
}(window.location))
</script>
<!-- End Single Page Apps for GitHub Pages -->
@* <script src="_framework/blazor.web.js"></script> *@
<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js" integrity="sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js" integrity="sha384-B4gt1jrGC7Jh4AgTPSdUtOBvfO8shuf57BaghqFfPlYxofvL8/KUEfYiJOMMV+rV" crossorigin="anonymous"></script>

Expand Down
8 changes: 8 additions & 0 deletions Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,14 @@
app.UseStaticFiles();
app.UseAntiforgery();
app.MapRazorComponents<App>();
app.MapGet("/sitemap.xml", async (HttpContext context) =>
{
var blogService = context.RequestServices.GetRequiredService<BlogService>();
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: *
Expand Down
39 changes: 38 additions & 1 deletion Services/BlogService.cs
Original file line number Diff line number Diff line change
@@ -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<BlogPost> GetBlogPosts()
Expand Down Expand Up @@ -118,6 +121,40 @@ public IEnumerable<BlogPost> 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();
}

}
}
1 change: 1 addition & 0 deletions appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@
"Microsoft.AspNetCore": "Warning"
}
},
"BaseUrl": "https://example.com/",
"AllowedHosts": "*"
}
1 change: 1 addition & 0 deletions wwwroot/404.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
<body>
<div id="app">
<svg class="loading-progress">

<circle r="40%" cx="50%" cy="50%" />
<circle r="40%" cx="50%" cy="50%" />
</svg>
Expand Down
2 changes: 1 addition & 1 deletion wwwroot/app.css
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
html, body {
font-family: 'Roboto', sans-serif;
font-family: 'Poppins', sans-serif;
}
.bd-placeholder-img {
font-size: 1.125rem;
Expand Down
2 changes: 1 addition & 1 deletion wwwroot/blogs/The-Enigmatic-World-of-Carnivorous-Plants.md
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion wwwroot/blogs/The-Marvelous-World-of-Bonsai.md
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Binary file removed wwwroot/images/Compressed/Headphone.png
Binary file not shown.
Binary file removed wwwroot/images/Compressed/blog1.jpg
Binary file not shown.
Binary file removed wwwroot/images/Compressed/blog1_thumbnail.jpg
Binary file not shown.
Binary file removed wwwroot/images/Compressed/blog2.jpg
Binary file not shown.
Binary file removed wwwroot/images/Compressed/blog2_thumbnail.jpg
Binary file not shown.
Binary file removed wwwroot/images/Compressed/blog3.jpg
Binary file not shown.
Binary file removed wwwroot/images/Compressed/blog3_thumbnail.jpg
Binary file not shown.
Binary file removed wwwroot/images/Compressed/blog4.jpg
Binary file not shown.
Binary file removed wwwroot/images/Compressed/blog4_thumbnail.jpg
Binary file not shown.
Binary file removed wwwroot/images/Compressed/blog5.jpg
Binary file not shown.
Binary file removed wwwroot/images/Compressed/blog5_thumbnail.jpg
Binary file not shown.
Binary file removed wwwroot/images/Compressed/plant.jpg
Binary file not shown.
Binary file removed wwwroot/images/Compressed/plant1_thumnail.jpg
Binary file not shown.
Binary file removed wwwroot/images/Compressed/plant2.jpg
Binary file not shown.
Binary file removed wwwroot/images/Compressed/plant2_thumbnail.jpg
Binary file not shown.
Binary file removed wwwroot/images/Compressed/plant3.jpg
Binary file not shown.
Binary file removed wwwroot/images/Compressed/plant3_thumbnail.jpg
Binary file not shown.
Binary file removed wwwroot/images/Compressed/plant4.jpeg
Binary file not shown.
Binary file removed wwwroot/images/Compressed/plant4.jpg
Binary file not shown.
Binary file removed wwwroot/images/Compressed/plant4_thumbnail.jpeg
Binary file not shown.
Binary file removed wwwroot/images/Compressed/plant4_thumbnail.jpg
Binary file not shown.
Binary file removed wwwroot/images/Compressed/plant5.jpg
Binary file not shown.
Binary file removed wwwroot/images/Compressed/plant5_thumbnail.jpg
Binary file not shown.
Binary file removed wwwroot/images/Compressed/plant6.jpg
Binary file not shown.
Binary file removed wwwroot/images/Compressed/plant6_thumbnail.jpg
Binary file not shown.
Binary file removed wwwroot/images/Compressed/plant7.jpg
Diff not rendered.
Binary file removed wwwroot/images/Compressed/plant9.jpg
Diff not rendered.
Binary file removed wwwroot/images/Compressed/plant_hero.png
Diff not rendered.
Binary file removed wwwroot/images/Headphone.png
Diff not rendered.
Binary file removed wwwroot/images/blog1.jpg
Diff not rendered.
Binary file removed wwwroot/images/blog1_thumbnail.jpg
Diff not rendered.
Binary file removed wwwroot/images/blog2.jpg
Diff not rendered.
Binary file removed wwwroot/images/blog2_thumbnail.jpg
Diff not rendered.
Binary file removed wwwroot/images/blog3.jpg
Diff not rendered.
Binary file removed wwwroot/images/blog3_thumbnail.jpg
Diff not rendered.
Binary file removed wwwroot/images/blog4.jpg
Diff not rendered.
Binary file removed wwwroot/images/blog4_thumbnail.jpg
Diff not rendered.
Binary file removed wwwroot/images/blog5.jpg
Diff not rendered.
Binary file removed wwwroot/images/blog5_thumbnail.jpg
Diff not rendered.