fix summaries

This commit is contained in:
avitex 2021-03-02 17:10:21 +11:00
parent 4b9a7acd20
commit b07d70c769
Signed by: avitex
GPG Key ID: 38C76CBF3749D62C
2 changed files with 13 additions and 7 deletions

View File

@ -2,4 +2,6 @@
# Action
An atomic human action assigned to an response stage.
{{ macros::summary_table(instances=instances) }}

View File

@ -247,17 +247,18 @@ async fn render_indexes(
summary: &[SummaryItem],
) -> Result<(), MDBookEngineError> {
let mut last_i = 0;
let mut last_kind = None;
let mut last_item = if let Some(item) = summary.get(0) {
item
} else {
return Ok(());
};
for (i, item) in summary.iter().enumerate() {
if Some(item.id.kind) != last_kind {
let (domain, model) = item.id.kind.parts();
if item.id.kind != last_item.id.kind || i + 1 == summary.len() {
let (domain, model) = last_item.id.kind.parts();
let domain_dir = src.join(domain);
let model_dir = domain_dir.join(model);
let mut context = Context::new();
context.insert("instances", &summary[last_i..i]);
if !domain_dir.is_dir() {
fs::create_dir(&domain_dir).await?;
}
@ -265,13 +266,16 @@ async fn render_indexes(
fs::create_dir(&model_dir).await?;
}
let mut context = Context::new();
context.insert("instances", &summary[last_i..i]);
let model_index = model_dir.with_extension("md");
let template_path = format!("{}/{}.tera", domain, model);
let contents = templates.render(&template_path, &context)?;
fs::write(model_index, contents).await?;
last_i = i;
last_kind = Some(item.id.kind);
last_item = item;
}
}