98 lines
2.6 KiB
Rust
98 lines
2.6 KiB
Rust
use super::blog_post_page::get_date;
|
|
use super::blog_post_page::get_title;
|
|
use super::footnote_definition::IRealFootnoteDefinition;
|
|
use super::macros::intermediate;
|
|
use super::IDocumentElement;
|
|
use super::IHeading;
|
|
use super::ISection;
|
|
use crate::error::CustomError;
|
|
use std::path::PathBuf;
|
|
|
|
#[derive(Debug)]
|
|
pub(crate) struct IPage {
|
|
/// Relative path from the root of the pages directory.
|
|
pub(crate) path: PathBuf,
|
|
|
|
pub(crate) title: Option<String>,
|
|
|
|
#[allow(dead_code)]
|
|
pub(crate) date: Option<String>,
|
|
|
|
pub(crate) children: Vec<IDocumentElement>,
|
|
|
|
pub(crate) footnotes: Vec<IRealFootnoteDefinition>,
|
|
}
|
|
|
|
intermediate!(
|
|
IPage,
|
|
PageInput<'orig, 'parse>,
|
|
original,
|
|
intermediate_context,
|
|
{
|
|
let mut children = Vec::new();
|
|
if let Some(section) = original.document.zeroth_section.as_ref() {
|
|
children.push(IDocumentElement::Section(
|
|
ISection::new(intermediate_context.clone(), section).await?,
|
|
));
|
|
}
|
|
for heading in original.document.children.iter() {
|
|
children.push(IDocumentElement::Heading(
|
|
IHeading::new(intermediate_context.clone(), heading).await?,
|
|
));
|
|
}
|
|
|
|
let footnotes = {
|
|
let footnote_definitions: Vec<_> = {
|
|
let registry = intermediate_context.registry.lock().unwrap();
|
|
let ret = registry
|
|
.get_footnote_ids()
|
|
.map(|(id, def)| (id, def.clone()))
|
|
.collect();
|
|
ret
|
|
};
|
|
let mut ret = Vec::new();
|
|
for (id, def) in footnote_definitions.into_iter() {
|
|
ret.push(
|
|
IRealFootnoteDefinition::new(intermediate_context.clone(), id, def).await?,
|
|
);
|
|
}
|
|
ret
|
|
};
|
|
|
|
Ok(IPage {
|
|
path: original.path,
|
|
title: get_title(original.document),
|
|
date: get_date(original.document),
|
|
children,
|
|
footnotes,
|
|
})
|
|
}
|
|
);
|
|
|
|
impl IPage {
|
|
/// Get the output path relative to the pages directory.
|
|
pub(crate) fn get_output_path(&self) -> PathBuf {
|
|
let mut ret = self.path.clone();
|
|
ret.set_extension("html");
|
|
ret
|
|
}
|
|
}
|
|
|
|
#[derive(Debug)]
|
|
pub(crate) struct PageInput<'b, 'parse> {
|
|
path: PathBuf,
|
|
document: &'b organic::types::Document<'parse>,
|
|
}
|
|
|
|
impl<'b, 'parse> PageInput<'b, 'parse> {
|
|
pub(crate) fn new<P: Into<PathBuf>>(
|
|
path: P,
|
|
document: &'b organic::types::Document<'parse>,
|
|
) -> PageInput<'b, 'parse> {
|
|
PageInput {
|
|
path: path.into(),
|
|
document,
|
|
}
|
|
}
|
|
}
|