1
Fork 0

Replace manual mod link frontmatter with filter.

This commit is contained in:
Bauke 2023-01-08 12:45:53 +01:00
parent ce8be9e120
commit 4f206aa95e
Signed by: Bauke
GPG Key ID: C1C0F29952BCF558
3 changed files with 17 additions and 3 deletions

View File

@ -26,9 +26,10 @@
{% if let Some(mods) = speedrun.mods %}
<h2>Mods</h2>
<ul>
{% for (name, id) in mods %}
{% for id in mods %}
{% let (mod_link, mod_title) = id|drg_mod %}
<li>
<a href="https://drg.mod.io/{{ id }}" target="_blank">{{ name }}</a>
<a href="{{ mod_link }}" target="_blank">{{ mod_title }}</a>
</li>
{% endfor %}
</ul>

View File

@ -2,6 +2,19 @@
Filters for Askama templates.
*/
/**
Get the DRG mod link and title from a given ID.
*/
pub fn drg_mod(mod_id: &str) -> askama::Result<(String, &str)> {
let mods = std::collections::HashMap::<_, _>::from_iter([
("drglib", "DRGLib"),
("simplemissiontimer", "SimpleMissionTimer"),
]);
let mod_title = mods.get(mod_id).unwrap();
Ok((format!("https://drg.mod.io/{mod_id}"), mod_title))
}
/**
Turn a timestamp with format `mm:ss` into its total seconds.

View File

@ -25,7 +25,7 @@ pub struct SpeedrunData {
pub chapters: Option<Vec<(String, String)>>,
pub entry: String,
pub leaderboard: String,
pub mods: Option<Vec<(String, String)>>,
pub mods: Option<Vec<String>>,
}
pub fn write_all(public_dir: &Path) -> Result<()> {