Pour tout problème contactez-nous par mail : support@froggit.fr | La FAQ :grey_question: | Rejoignez-nous sur le Chat :speech_balloon:

Skip to content
Snippets Groups Projects
Commit 26f14273 authored by Pierre Jarriges's avatar Pierre Jarriges
Browse files

dyn_sitemap.xml

parent f1da2b41
No related branches found
No related tags found
1 merge request!1Dev
...@@ -8,4 +8,4 @@ target ...@@ -8,4 +8,4 @@ target
public/**/*.js public/**/*.js
public/**/view/* public/**/view/*
public/standard/test_sitemap.xml public/standard/test_sitemap.xml
public/standard/sitemap.xml public/standard/dyn_sitemap.xml
\ No newline at end of file \ No newline at end of file
User-agent: * User-agent: *
Sitemap: https://kuadrado-software.fr/sitemap.xml Sitemap: https://kuadrado-software.fr/sitemap.xml
Sitemap: https://kuadrado-software.fr/dyn_sitemap.xml
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="utf-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"> <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
<url> <url>
<loc>https://kuadrado-software.fr</loc> <loc>https://kuadrado-software.fr/</loc>
<lastmod>2021-11-19</lastmod> <lastmod>2022-05-25T00:00:00+00:00</lastmod>
</url> </url>
<url> <url>
<loc>https://kuadrado-software.fr/games/</loc> <loc>https://kuadrado-software.fr/games/</loc>
<lastmod>2021-11-19</lastmod> <lastmod>2022-05-25T00:00:00+00:00</lastmod>
</url> </url>
<url> <url>
<loc>https://kuadrado-software.fr/education/</loc> <loc>https://kuadrado-software.fr/education/</loc>
<lastmod>2021-11-19</lastmod> <lastmod>2022-05-25T00:00:00+00:00</lastmod>
</url> </url>
<url> <url>
<loc>https://kuadrado-software.fr/software-development/</loc> <loc>https://kuadrado-software.fr/software-development/</loc>
<lastmod>2021-11-19</lastmod> <lastmod>2022-05-25T00:00:00+00:00</lastmod>
</url> </url>
</urlset> <url>
<loc>https://localhost/games/view/fr/glitch/</loc>
<lastmod>2022-05-25T00:00:00+00:00</lastmod>
</url>
</urlset>
\ No newline at end of file
...@@ -118,7 +118,7 @@ pub async fn post_article( ...@@ -118,7 +118,7 @@ pub async fn post_article(
} }
} }
_ => { _ => {
return HttpResponse::InternalServerError().body("Error creating article page") return HttpResponse::InternalServerError().body("Error creating article page");
} }
} }
HttpResponse::Created().json(res) HttpResponse::Created().json(res)
......
...@@ -118,6 +118,21 @@ pub fn delete_static_view( ...@@ -118,6 +118,21 @@ pub fn delete_static_view(
Ok(()) Ok(())
} }
fn init_sitemap(sitemap_path: &PathBuf) -> Result<(), String> {
File::create(sitemap_path).expect("Couldn't create sitemap");
let sm = File::open(sitemap_path).unwrap();
let writer = SiteMapWriter::new(&sm);
match writer.start_urlset() {
Ok(url_w) => {
if let Err(e) = url_w.end() {
return Err(format!("Couldn't write new sitemap closing tags. {}", e));
}
Ok(())
}
Err(e) => Err(format!("Couldn't create new sitemap urlset. {}", e)),
}
}
fn update_sitemap( fn update_sitemap(
app_state: &AppState, app_state: &AppState,
uri: &Option<String>, uri: &Option<String>,
...@@ -132,17 +147,24 @@ fn update_sitemap( ...@@ -132,17 +147,24 @@ fn update_sitemap(
if value.eq("testing") { if value.eq("testing") {
String::from("test_sitemap.xml") String::from("test_sitemap.xml")
} else { } else {
String::from("sitemap.xml") String::from("dyn_sitemap.xml")
} }
} }
Err(_) => String::from("sitemap.xml"), Err(_) => String::from("dyn_sitemap.xml"),
}; };
let standard_dir_pth = app_state.env.public_dir.join("standard"); let standard_dir_pth = app_state.env.public_dir.join("standard");
let uri = uri.as_ref().unwrap().to_owned(); let uri = uri.as_ref().unwrap().to_owned();
let sitemap = let sitemap_path = standard_dir_pth.join(&sitemap_name);
File::open(standard_dir_pth.join(&sitemap_name)).expect("Couldn't open file sitemap.xml");
if !sitemap_path.exists() {
if let Err(e) = init_sitemap(&sitemap_path) {
return Err(e);
}
}
let sitemap = File::open(&sitemap_path).expect("Couldn't open file sitemap.xml");
let mut urls = Vec::new(); let mut urls = Vec::new();
...@@ -155,7 +177,7 @@ fn update_sitemap( ...@@ -155,7 +177,7 @@ fn update_sitemap(
let updated_sitemap = File::create(standard_dir_pth.join("tmp_sitemap.xml")) let updated_sitemap = File::create(standard_dir_pth.join("tmp_sitemap.xml"))
.expect("Couldn't create temporary sitemap"); .expect("Couldn't create temporary sitemap");
let writer = SiteMapWriter::new(updated_sitemap); let writer = SiteMapWriter::new(&updated_sitemap);
let mut url_writer = writer let mut url_writer = writer
.start_urlset() .start_urlset()
.expect("Unable to write sitemap urlset"); .expect("Unable to write sitemap urlset");
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment