From b07d70c769bdf611fd7d5ca4d88eb8d9a42864e8 Mon Sep 17 00:00:00 2001 From: avitex Date: Tue, 2 Mar 2021 17:10:21 +1100 Subject: [PATCH] fix summaries --- book/react/action.tera | 2 ++ src/generator/mdbook.rs | 18 +++++++++++------- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/book/react/action.tera b/book/react/action.tera index 0077f47..359764a 100644 --- a/book/react/action.tera +++ b/book/react/action.tera @@ -2,4 +2,6 @@ # Action +An atomic human action assigned to an response stage. + {{ macros::summary_table(instances=instances) }} diff --git a/src/generator/mdbook.rs b/src/generator/mdbook.rs index f47473e..0b1e206 100644 --- a/src/generator/mdbook.rs +++ b/src/generator/mdbook.rs @@ -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; } }