2023-10-27 12:47:12 -04:00
|
|
|
use std::path::Path;
|
|
|
|
|
2023-10-24 00:01:40 -04:00
|
|
|
use serde::Serialize;
|
|
|
|
|
2023-10-27 12:47:12 -04:00
|
|
|
use crate::config::Config;
|
|
|
|
use crate::error::CustomError;
|
2023-10-27 13:05:34 -04:00
|
|
|
use crate::intermediate::IHeading;
|
2023-10-27 12:47:12 -04:00
|
|
|
|
2023-10-24 00:36:08 -04:00
|
|
|
use super::RenderObject;
|
|
|
|
|
2023-10-24 00:01:40 -04:00
|
|
|
#[derive(Debug, Serialize)]
|
|
|
|
#[serde(tag = "type")]
|
|
|
|
#[serde(rename = "heading")]
|
2023-10-24 00:36:08 -04:00
|
|
|
pub(crate) struct RenderHeading {
|
2023-10-27 12:47:12 -04:00
|
|
|
level: organic::types::HeadlineLevel,
|
2023-10-24 00:36:08 -04:00
|
|
|
title: Vec<RenderObject>,
|
|
|
|
}
|
2023-10-27 12:47:12 -04:00
|
|
|
|
|
|
|
impl RenderHeading {
|
|
|
|
pub(crate) fn new<D: AsRef<Path>, F: AsRef<Path>>(
|
|
|
|
config: &Config,
|
|
|
|
output_directory: D,
|
|
|
|
output_file: F,
|
2023-10-27 13:05:34 -04:00
|
|
|
heading: &IHeading,
|
2023-10-27 12:47:12 -04:00
|
|
|
) -> Result<RenderHeading, CustomError> {
|
|
|
|
let title = heading
|
|
|
|
.title
|
|
|
|
.iter()
|
|
|
|
.map(|obj| RenderObject::new(config, &output_directory, &output_file, obj))
|
|
|
|
.collect::<Result<Vec<_>, _>>()?;
|
|
|
|
Ok(RenderHeading {
|
|
|
|
level: heading.level,
|
|
|
|
title,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|