markupwright 0.1.3

Template-driven workspace documentation generator
Documentation
use serde::Serialize;

use crate::{RenderCtx, domain};

#[derive(Debug, Serialize)]
pub(super) struct Child {
    pub(crate) name: String,
    pub(crate) description: String,
}

pub(super) fn gather(ctx: &RenderCtx<'_>) -> Vec<Child> {
    let mut children: Vec<Child> = ctx
        .workspace
        .child_dirs(ctx.dir)
        .filter_map(|path| {
            let name = path.file_name()?.to_string_lossy().to_string();

            if !ctx.workspace.has_navigation_document(path) {
                return None;
            }

            let meta = domain::load(&ctx.workspace, path);

            Some(Child {
                name,
                description: meta.description.clone().unwrap_or_default(),
            })
        })
        .collect();

    children.sort_by(|left, right| left.name.cmp(&right.name));

    children
}