logicaffeine_web/
sitemap.rs1use std::fmt::Write;
17
18const BASE_URL: &str = "https://logicaffeine.com";
19const CURRENT_DATE: &str = "2026-11-02";
20
21pub struct SitemapEntry {
23 pub path: String,
24 pub changefreq: &'static str,
25 pub priority: f32,
26}
27
28pub fn get_static_routes() -> Vec<SitemapEntry> {
30 [
31 ("/", "weekly", 1.0),
32 ("/guide", "monthly", 0.9),
33 ("/learn", "monthly", 0.9),
34 ("/crates", "monthly", 0.8),
35 ("/studio", "weekly", 0.8),
36 ("/benchmarks", "weekly", 0.8),
37 ("/contact", "monthly", 0.8),
38 ("/roadmap", "monthly", 0.7),
39 ("/news", "weekly", 0.7),
40 ("/registry", "weekly", 0.6),
41 ("/privacy", "yearly", 0.3),
42 ("/terms", "yearly", 0.3),
43 ]
44 .into_iter()
45 .map(|(path, changefreq, priority)| SitemapEntry {
46 path: path.to_string(),
47 changefreq,
48 priority,
49 })
50 .collect()
51}
52
53pub fn get_news_routes() -> Vec<SitemapEntry> {
56 crate::ui::pages::news::get_articles()
57 .into_iter()
58 .map(|article| SitemapEntry {
59 path: format!("/news/{}", article.slug),
60 changefreq: "monthly",
61 priority: 0.6,
62 })
63 .collect()
64}
65
66pub fn prerender_routes() -> Vec<String> {
69 get_static_routes()
70 .into_iter()
71 .chain(get_news_routes())
72 .map(|entry| entry.path)
73 .collect()
74}
75
76pub fn generate_sitemap() -> String {
78 let mut xml = String::new();
79
80 writeln!(xml, r#"<?xml version="1.0" encoding="UTF-8"?>"#).unwrap();
81 writeln!(
82 xml,
83 r#"<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">"#
84 )
85 .unwrap();
86
87 writeln!(xml, " <!-- Main Pages -->").unwrap();
88 for entry in get_static_routes() {
89 write_url_entry(&mut xml, entry);
90 }
91
92 writeln!(xml, "\n <!-- News Articles -->").unwrap();
93 for entry in get_news_routes() {
94 write_url_entry(&mut xml, entry);
95 }
96
97 writeln!(xml, "</urlset>").unwrap();
98
99 xml
100}
101
102fn write_url_entry(xml: &mut String, entry: SitemapEntry) {
103 writeln!(xml, " <url>").unwrap();
104 writeln!(xml, " <loc>{}{}</loc>", BASE_URL, entry.path).unwrap();
105 writeln!(xml, " <lastmod>{}</lastmod>", CURRENT_DATE).unwrap();
106 writeln!(xml, " <changefreq>{}</changefreq>", entry.changefreq).unwrap();
107 writeln!(xml, " <priority>{:.1}</priority>", entry.priority).unwrap();
108 writeln!(xml, " </url>").unwrap();
109}
110
111#[cfg(test)]
112#[path = "../../../crates/logicaffeine_tests/unit/logicaffeine_web/sitemap/tests.rs"]
113mod tests;