template logic
This commit is contained in:
parent
d2d0aebecd
commit
5d526af0ac
|
@ -140,6 +140,7 @@ enum LinkType<'a> {
|
||||||
Title(&'a str),
|
Title(&'a str),
|
||||||
Template(PathBuf, HashMap<String, String>),
|
Template(PathBuf, HashMap<String, String>),
|
||||||
Title(&'a str),
|
Title(&'a str),
|
||||||
|
Template(PathBuf, HashMap<String, String>),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(PartialEq, Debug, Clone)]
|
#[derive(PartialEq, Debug, Clone)]
|
||||||
|
@ -213,6 +214,7 @@ impl<'a> LinkType<'a> {
|
||||||
LinkType::Title(_) => None,
|
LinkType::Title(_) => None,
|
||||||
LinkType::Template(p, _) => Some(return_relative_path(base, &p)),
|
LinkType::Template(p, _) => Some(return_relative_path(base, &p)),
|
||||||
LinkType::Title(_) => None,
|
LinkType::Title(_) => None,
|
||||||
|
LinkType::Template(p, _) => Some(return_relative_path(base, &p)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -431,6 +433,23 @@ impl<'a> Link<'a> {
|
||||||
*chapter_title = title.to_owned();
|
*chapter_title = title.to_owned();
|
||||||
Ok(String::new())
|
Ok(String::new())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
LinkType::Template(ref pat, ref dict) => {
|
||||||
|
let target = base.join(pat);
|
||||||
|
fs::read_to_string(&target)
|
||||||
|
.map(|s| {
|
||||||
|
dict.iter().fold(s, |r, (key, value)| {
|
||||||
|
r.replace(format!("{{ {} }}", key).as_str(), value)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
.with_context(|| {
|
||||||
|
format!(
|
||||||
|
"Could not read file for template {} ({})",
|
||||||
|
self.link_text,
|
||||||
|
target.display(),
|
||||||
|
)
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue