Don't save the HTML in the struct, add a to_html method instead

This commit is contained in:
Paul van Tilburg 2017-12-23 22:03:25 +01:00
parent 5862a89357
commit c67ff0a78a
1 changed files with 6 additions and 3 deletions

View File

@ -14,6 +14,11 @@ pub struct List {
}
impl List {
pub fn to_html(&self) -> String {
comrak::markdown_to_html(&self.data,
&comrak::ComrakOptions::default())
}
pub fn load_all() -> Vec<Self> {
let mut lists : Vec<List> = vec![];
for entry in glob("lists/*.list").unwrap().filter_map(Result::ok) {
@ -28,11 +33,9 @@ impl List {
file.read_to_string(&mut data)
.expect(&format!("Cannot read list file {}", file_name));
let html = comrak::markdown_to_html(&data,
&comrak::ComrakOptions::default());
let list = List {
id: String::from(name),
data: data,
html: html,
name: String::from(name).to_title_case(),
path: entry.clone()
};