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