diff --git a/components/library/src/content/page.rs b/components/library/src/content/page.rs index 05f2920..6bc5564 100644 --- a/components/library/src/content/page.rs +++ b/components/library/src/content/page.rs @@ -31,6 +31,8 @@ pub struct Page { pub raw_content: String, /// All the non-md files we found next to the .md file pub assets: Vec, + /// All the non-md files we found next to the .md file as string for use in templates + pub serialized_assets: Vec, /// The HTML rendered of the page pub content: String, /// The slug of that page. @@ -74,6 +76,7 @@ impl Page { ancestors: vec![], raw_content: "".to_string(), assets: vec![], + serialized_assets: vec![], content: "".to_string(), slug: "".to_string(), path: "".to_string(), @@ -168,6 +171,8 @@ impl Page { } else { page.assets = assets; } + + page.serialized_assets = page.serialize_assets(); } else { page.assets = vec![]; } @@ -222,7 +227,7 @@ impl Page { } /// Creates a vectors of asset URLs. - pub fn serialize_assets(&self) -> Vec { + fn serialize_assets(&self) -> Vec { self.assets.iter() .filter_map(|asset| asset.file_name()) .filter_map(|filename| filename.to_str()) @@ -247,6 +252,7 @@ impl Default for Page { ancestors: vec![], raw_content: "".to_string(), assets: vec![], + serialized_assets: vec![], content: "".to_string(), slug: "".to_string(), path: "".to_string(), diff --git a/components/library/src/content/section.rs b/components/library/src/content/section.rs index 4baea62..1b504fe 100644 --- a/components/library/src/content/section.rs +++ b/components/library/src/content/section.rs @@ -35,6 +35,8 @@ pub struct Section { pub content: String, /// All the non-md files we found next to the .md file pub assets: Vec, + /// All the non-md files we found next to the .md file as string for use in templates + pub serialized_assets: Vec, /// All direct pages of that section pub pages: Vec, /// All pages that cannot be sorted in this section @@ -65,6 +67,7 @@ impl Section { permalink: "".to_string(), raw_content: "".to_string(), assets: vec![], + serialized_assets: vec![], content: "".to_string(), pages: vec![], ignored_pages: vec![], @@ -119,6 +122,8 @@ impl Section { section.assets = assets; } + section.serialized_assets = section.serialize_assets(); + Ok(section) } @@ -179,7 +184,7 @@ impl Section { } /// Creates a vectors of asset URLs. - pub fn serialize_assets(&self) -> Vec { + fn serialize_assets(&self) -> Vec { self.assets.iter() .filter_map(|asset| asset.file_name()) .filter_map(|filename| filename.to_str()) @@ -208,6 +213,7 @@ impl Default for Section { permalink: "".to_string(), raw_content: "".to_string(), assets: vec![], + serialized_assets: vec![], content: "".to_string(), pages: vec![], ignored_pages: vec![], diff --git a/components/library/src/content/ser.rs b/components/library/src/content/ser.rs index c45e30d..cf7d97e 100644 --- a/components/library/src/content/ser.rs +++ b/components/library/src/content/ser.rs @@ -29,7 +29,7 @@ pub struct SerializingPage<'a> { word_count: Option, reading_time: Option, toc: &'a [Header], - assets: Vec, + assets: &'a [String], draft: bool, lighter: Option>>, heavier: Option>>, @@ -75,7 +75,7 @@ impl<'a> SerializingPage<'a> { word_count: page.word_count, reading_time: page.reading_time, toc: &page.toc, - assets: page.serialize_assets(), + assets: &page.serialized_assets, draft: page.is_draft(), lighter, heavier, @@ -120,7 +120,7 @@ impl<'a> SerializingPage<'a> { word_count: page.word_count, reading_time: page.reading_time, toc: &page.toc, - assets: page.serialize_assets(), + assets: &page.serialized_assets, draft: page.is_draft(), lighter: None, heavier: None, @@ -145,7 +145,7 @@ pub struct SerializingSection<'a> { word_count: Option, reading_time: Option, toc: &'a [Header], - assets: Vec, + assets: &'a [String], pages: Vec>, subsections: Vec<&'a str>, } @@ -178,7 +178,7 @@ impl<'a> SerializingSection<'a> { word_count: section.word_count, reading_time: section.reading_time, toc: §ion.toc, - assets: section.serialize_assets(), + assets: §ion.serialized_assets, pages, subsections, } @@ -205,7 +205,7 @@ impl<'a> SerializingSection<'a> { word_count: section.word_count, reading_time: section.reading_time, toc: §ion.toc, - assets: section.serialize_assets(), + assets: §ion.serialized_assets, pages: vec![], subsections: vec![], }