Skip to content

Commit

Permalink
Add alternative_paths variable to pages
Browse files Browse the repository at this point in the history
  • Loading branch information
grego committed May 23, 2021
1 parent fa2006c commit 008193f
Showing 1 changed file with 20 additions and 6 deletions.
26 changes: 20 additions & 6 deletions src/page.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ pub struct Page<'p> {
#[serde(borrow, default)]
path: Ancestors<'p>,
#[serde(default)]
alternative_paths: Cow<'p, [&'p str]>,
#[serde(default)]
#[ramhorns(skip)]
pub(crate) weight: i64,
#[serde(borrow, default)]
Expand Down Expand Up @@ -281,7 +283,7 @@ impl<'p> Page<'p> {
/// they will be rendered to.
#[inline]
pub fn prepare(mut pages: Vec<Self>, config: &Config) -> Result<Vec<Self>> {
let output = Path::new(config.output_dir.as_ref());
let output_dir = Path::new(config.output_dir.as_ref());
for i in 0..pages.len() {
let page = &pages[i];

Expand Down Expand Up @@ -313,11 +315,16 @@ impl<'p> Page<'p> {

let page = &pages[i];
if page.is_section || !page.pictures.is_empty() {
let mut path = output.join(page.path.as_ref());
let mut path = output_dir.join(page.path.as_ref());
path.push(page.slug.as_ref());
create_dir_all(path)?;
}

for path in page.alternative_paths.iter() {
let path = output_dir.join(path);
create_dir_all(path)?;
}

// Assign a unique identifier
pages[i].id = i;
}
Expand Down Expand Up @@ -377,7 +384,8 @@ impl<'p> Page<'p> {
classification: &Classification<'p, '_>,
rendered: &MutSet,
) -> Result {
let mut output = Path::new(config.output_dir.as_ref()).join(self.path.as_ref());
let output_dir = Path::new(config.output_dir.as_ref());
let mut output = output_dir.join(self.path.as_ref());
output.push(self.slug.as_ref());
if self.is_section {
output.push("index");
Expand All @@ -399,7 +407,7 @@ impl<'p> Page<'p> {
let by = self.paginate_by.map(NonZeroUsize::get).unwrap_or(0);
if by > 0 && self.pages.len() > by {
let (start, end) = (self.pages.start, self.pages.end);
page.render_paginated(start, end, by, &mut output, &template, rendered)
page.render_paginated(start, end, by, &mut output, &template, rendered)?
} else if !self.pictures.is_empty() {
render(template, &output, &page, rendered)?;

Expand Down Expand Up @@ -428,10 +436,16 @@ impl<'p> Page<'p> {
render(template, &output, &page, rendered)?;
output.pop();
}
Ok(())
} else {
render(template, output, &page, rendered)
render(template, output, &page, rendered)?;
}

for path in self.alternative_paths.iter() {
let mut output = output_dir.join(path);
output.push("index.html");
render(template, output, &page, rendered)?;
}
Ok(())
}
}

Expand Down

0 comments on commit 008193f

Please sign in to comment.