1
Fork 0
tildes-wiki-sitemap/source/templates/mod.rs

78 lines
2.2 KiB
Rust

//! Askama templates.
use {askama::Template, tildes_parser::Group};
/// The template for `sitemap.md`.
#[derive(Debug, Template)]
#[template(path = "sitemap.md")]
pub struct SitemapTemplate {
/// All groups to render in the sitemap.
pub groups: Vec<Group>,
}
#[test]
fn test_sitemap_template() -> color_eyre::Result<()> {
let groups = vec![
Group {
description: Some("Example group description.".to_string()),
name: "~example".to_string(),
sub_groups: vec![],
subscribers: 12345,
wiki_links: vec![
tildes_parser::GroupWikiLink {
name: "Example Page".to_string(),
url: "https://example.org/~example/wiki/example_page".to_string(),
},
tildes_parser::GroupWikiLink {
name: "Example Page".to_string(),
url: "https://example.org/~example/wiki/example_page".to_string(),
},
],
},
Group {
description: Some("Example group description.".to_string()),
name: "~example".to_string(),
sub_groups: vec![],
subscribers: 12345,
wiki_links: vec![
tildes_parser::GroupWikiLink {
name: "Example Page".to_string(),
url: "https://example.org/~example/wiki/example_page".to_string(),
},
tildes_parser::GroupWikiLink {
name: "Example Page".to_string(),
url: "https://example.org/~example/wiki/example_page".to_string(),
},
],
},
Group {
description: None,
name: "~example".to_string(),
sub_groups: vec![],
subscribers: 12345,
wiki_links: vec![],
},
Group {
description: None,
name: "~example".to_string(),
sub_groups: vec![],
subscribers: 12345,
wiki_links: vec![
tildes_parser::GroupWikiLink {
name: "Example Page".to_string(),
url: "https://example.org/~example/wiki/example_page".to_string(),
},
tildes_parser::GroupWikiLink {
name: "Example Page".to_string(),
url: "https://example.org/~example/wiki/example_page".to_string(),
},
],
},
];
std::fs::create_dir_all("output")?;
std::fs::write("output/sitemap-test.md", crate::render_sitemap(groups)?)?;
Ok(())
}