Skip to content

Commit 9a873e7

Browse files
committed
Auto Generate Channels Sitemap
1 parent ff3197f commit 9a873e7

File tree

3 files changed

+150
-74
lines changed

3 files changed

+150
-74
lines changed

CommonComponents/CommonComponents.csproj

+13
Original file line numberDiff line numberDiff line change
@@ -51,4 +51,17 @@
5151
</ItemGroup>
5252
</Target>
5353

54+
<Target Name="GenerateSitemapXml" BeforeTargets="PreBuildEvent" Condition="'$(Configuration)'!='Release'">
55+
<PropertyGroup>
56+
<SitemapXmlFilePath>$([System.IO.Path]::Combine('wwwroot', 'sitemap-channels.xml'))</SitemapXmlFilePath>
57+
</PropertyGroup>
58+
59+
<Exec Command="dotnet run --project &quot;$(ProjectDir)../SitemapGenerator&quot; -p BuildScope=$(ProjectName) -o &quot;$(ProjectDir)$(SitemapXmlFilePath)&quot; --channel &quot;Channel&quot;" />
60+
61+
<ItemGroup>
62+
<Content Remove="$(SitemapXmlFilePath)" />
63+
<Content Include="$(SitemapXmlFilePath)" />
64+
</ItemGroup>
65+
</Target>
66+
5467
</Project>
+121-67
Original file line numberDiff line numberDiff line change
@@ -1,69 +1,123 @@
1-
<?xml version="1.0" encoding="UTF-8"?>
1+
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
22
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
3-
<url>
4-
<loc>https://ilovedotnet.org/channels/blazor</loc>
5-
<lastmod>2022-03-01T22:30:00+05:30</lastmod>
6-
<changefreq>weekly</changefreq>
7-
<priority>0.5</priority>
8-
</url>
9-
<url>
10-
<loc>https://ilovedotnet.org/channels/webapi</loc>
11-
<lastmod>2022-03-06T22:30:00+05:30</lastmod>
12-
<changefreq>weekly</changefreq>
13-
<priority>0.5</priority>
14-
</url>
15-
<url>
16-
<loc>https://ilovedotnet.org/channels/talk</loc>
17-
<lastmod>2022-03-13T22:30:00+05:30</lastmod>
18-
<changefreq>weekly</changefreq>
19-
<priority>0.5</priority>
20-
</url>
21-
<url>
22-
<loc>https://ilovedotnet.org/channels/tdd</loc>
23-
<lastmod>2022-03-27T22:30:00+05:30</lastmod>
24-
<changefreq>weekly</changefreq>
25-
<priority>0.5</priority>
26-
</url>
27-
<url>
28-
<loc>https://ilovedotnet.org/channels/oops</loc>
29-
<lastmod>2022-05-01T22:30:00+05:30</lastmod>
30-
<changefreq>weekly</changefreq>
31-
<priority>0.5</priority>
32-
</url>
33-
<url>
34-
<loc>https://ilovedotnet.org/channels/middleware</loc>
35-
<lastmod>2022-06-19T22:30:00+05:30</lastmod>
36-
<changefreq>weekly</changefreq>
37-
<priority>0.5</priority>
38-
</url>
39-
<url>
40-
<loc>https://ilovedotnet.org/channels/dependency-injection</loc>
41-
<lastmod>2022-07-24T22:30:00+05:30</lastmod>
42-
<changefreq>weekly</changefreq>
43-
<priority>0.5</priority>
44-
</url>
45-
<url>
46-
<loc>https://ilovedotnet.org/channels/linq</loc>
47-
<lastmod>2022-08-14T22:30:00+05:30</lastmod>
48-
<changefreq>weekly</changefreq>
49-
<priority>0.5</priority>
50-
</url>
51-
<url>
52-
<loc>https://ilovedotnet.org/channels/python</loc>
53-
<lastmod>2022-09-11T22:30:00+05:30</lastmod>
54-
<changefreq>weekly</changefreq>
55-
<priority>0.5</priority>
56-
</url>
57-
<url>
58-
<loc>https://ilovedotnet.org/channels/design-pattern</loc>
59-
<lastmod>2023-03-12T22:30:00+05:30</lastmod>
60-
<changefreq>weekly</changefreq>
61-
<priority>0.5</priority>
62-
</url>
63-
<url>
64-
<loc>https://ilovedotnet.org/channels/solid</loc>
65-
<lastmod>2023-04-02T22:30:00+05:30</lastmod>
66-
<changefreq>weekly</changefreq>
67-
<priority>0.5</priority>
68-
</url>
3+
<url>
4+
<loc>https://ilovedotnet.org/channels/blazor</loc>
5+
<lastmod>2025-01-19T22:30:00+00:00</lastmod>
6+
<changefreq>weekly</changefreq>
7+
<priority>0.5</priority>
8+
</url>
9+
<url>
10+
<loc>https://ilovedotnet.org/channels/dependency-injection</loc>
11+
<lastmod>2024-10-13T22:30:00+00:00</lastmod>
12+
<changefreq>weekly</changefreq>
13+
<priority>0.5</priority>
14+
</url>
15+
<url>
16+
<loc>https://ilovedotnet.org/channels/design-pattern</loc>
17+
<lastmod>2025-02-16T22:30:00+00:00</lastmod>
18+
<changefreq>weekly</changefreq>
19+
<priority>0.5</priority>
20+
</url>
21+
<url>
22+
<loc>https://ilovedotnet.org/channels/http-client</loc>
23+
<lastmod>2024-12-08T22:30:00+00:00</lastmod>
24+
<changefreq>weekly</changefreq>
25+
<priority>0.5</priority>
26+
</url>
27+
<url>
28+
<loc>https://ilovedotnet.org/channels/linq</loc>
29+
<lastmod>2023-03-05T22:30:00+00:00</lastmod>
30+
<changefreq>weekly</changefreq>
31+
<priority>0.5</priority>
32+
</url>
33+
<url>
34+
<loc>https://ilovedotnet.org/channels/maui</loc>
35+
<lastmod>2025-03-02T22:30:00+00:00</lastmod>
36+
<changefreq>weekly</changefreq>
37+
<priority>0.5</priority>
38+
</url>
39+
<url>
40+
<loc>https://ilovedotnet.org/channels/middleware</loc>
41+
<lastmod>2024-10-27T22:30:00+00:00</lastmod>
42+
<changefreq>weekly</changefreq>
43+
<priority>0.5</priority>
44+
</url>
45+
<url>
46+
<loc>https://ilovedotnet.org/channels/mlnet</loc>
47+
<lastmod>2025-03-09T22:30:00+00:00</lastmod>
48+
<changefreq>weekly</changefreq>
49+
<priority>0.5</priority>
50+
</url>
51+
<url>
52+
<loc>https://ilovedotnet.org/channels/msbuild</loc>
53+
<lastmod>2025-02-02T22:30:00+00:00</lastmod>
54+
<changefreq>weekly</changefreq>
55+
<priority>0.5</priority>
56+
</url>
57+
<url>
58+
<loc>https://ilovedotnet.org/channels/oops</loc>
59+
<lastmod>2022-05-15T22:30:00+00:00</lastmod>
60+
<changefreq>weekly</changefreq>
61+
<priority>0.5</priority>
62+
</url>
63+
<url>
64+
<loc>https://ilovedotnet.org/channels/owasp</loc>
65+
<lastmod>2024-06-16T22:30:00+00:00</lastmod>
66+
<changefreq>weekly</changefreq>
67+
<priority>0.5</priority>
68+
</url>
69+
<url>
70+
<loc>https://ilovedotnet.org/channels/python</loc>
71+
<lastmod>2022-09-11T22:30:00+00:00</lastmod>
72+
<changefreq>weekly</changefreq>
73+
<priority>0.5</priority>
74+
</url>
75+
<url>
76+
<loc>https://ilovedotnet.org/channels/regex</loc>
77+
<lastmod>2025-02-09T22:30:00+00:00</lastmod>
78+
<changefreq>weekly</changefreq>
79+
<priority>0.5</priority>
80+
</url>
81+
<url>
82+
<loc>https://ilovedotnet.org/channels/report</loc>
83+
<lastmod>2025-01-26T22:30:00+00:00</lastmod>
84+
<changefreq>weekly</changefreq>
85+
<priority>0.5</priority>
86+
</url>
87+
<url>
88+
<loc>https://ilovedotnet.org/channels/signalr</loc>
89+
<lastmod>2024-06-09T22:30:00+00:00</lastmod>
90+
<changefreq>weekly</changefreq>
91+
<priority>0.5</priority>
92+
</url>
93+
<url>
94+
<loc>https://ilovedotnet.org/channels/solid</loc>
95+
<lastmod>2023-05-14T22:30:00+00:00</lastmod>
96+
<changefreq>weekly</changefreq>
97+
<priority>0.5</priority>
98+
</url>
99+
<url>
100+
<loc>https://ilovedotnet.org/channels/talk</loc>
101+
<lastmod>2022-03-13T22:30:00+00:00</lastmod>
102+
<changefreq>weekly</changefreq>
103+
<priority>0.5</priority>
104+
</url>
105+
<url>
106+
<loc>https://ilovedotnet.org/channels/tdd</loc>
107+
<lastmod>2024-09-29T22:30:00+00:00</lastmod>
108+
<changefreq>weekly</changefreq>
109+
<priority>0.5</priority>
110+
</url>
111+
<url>
112+
<loc>https://ilovedotnet.org/channels/testing</loc>
113+
<lastmod>2025-03-24T23:30:00+00:00</lastmod>
114+
<changefreq>weekly</changefreq>
115+
<priority>0.5</priority>
116+
</url>
117+
<url>
118+
<loc>https://ilovedotnet.org/channels/web-api</loc>
119+
<lastmod>2025-02-23T22:30:00+00:00</lastmod>
120+
<changefreq>weekly</changefreq>
121+
<priority>0.5</priority>
122+
</url>
69123
</urlset>

SitemapGenerator/Sitemap.cs

+16-7
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,22 @@ namespace SitemapGenerator;
66
public class Sitemap(TableOfContents tableOfContents, string channel)
77
{
88
private XDocument? _sitemap;
9-
private readonly List<Url> _urls = [.. tableOfContents.GetContentsByChannel(channel).Select(content => new Url
10-
{
11-
Loc = $"https://ilovedotnet.org/blogs/{content.Slug}",
12-
LastMod = new DateTime(content.ModifiedOn.Year, content.ModifiedOn.Month, content.ModifiedOn.Day, content.ModifiedOn.Hour, content.ModifiedOn.Minute, content.ModifiedOn.Second),
13-
ChangeFreq = "weekly",
14-
Priority = 0.5
15-
})];
9+
private readonly List<Url> _urls =
10+
channel.Equals("Channel")
11+
? [.. tableOfContents.AvailableContentTypes.Select(contentType => new Url
12+
{
13+
Loc = $"https://ilovedotnet.org/channels/{contentType.ToLower().Replace(" ", "-")}",
14+
LastMod = tableOfContents.GetContentsByChannel(contentType)[0].ModifiedOn,
15+
ChangeFreq = "weekly",
16+
Priority = 0.5
17+
})]
18+
: [.. tableOfContents.GetContentsByChannel(channel).Select(content => new Url
19+
{
20+
Loc = $"https://ilovedotnet.org/blogs/{content.Slug}",
21+
LastMod = new DateTime(content.ModifiedOn.Year, content.ModifiedOn.Month, content.ModifiedOn.Day, content.ModifiedOn.Hour, content.ModifiedOn.Minute, content.ModifiedOn.Second),
22+
ChangeFreq = "weekly",
23+
Priority = 0.5
24+
})];
1625

1726
public void GenerateSitemap(string filePath)
1827
{

0 commit comments

Comments
 (0)