use crate::meta::Section;
use anyhow::Result;
use serde::Serialize;
use std::{fs, path::Path};
#[derive(Serialize)]
struct IndexEntry<'a> {
id: &'a str,
file: &'a str,
title: &'a str,
tags: &'a [String],
perl: &'a Option<String>,
flags: &'a [String],
}
pub(super) fn write_flat_index(dir: &Path, sections: &[Section]) -> Result<()> {
let index: Vec<IndexEntry> = sections
.iter()
.map(|section| IndexEntry {
id: §ion.id,
file: §ion.file,
title: §ion.title,
tags: §ion.tags,
perl: §ion.perl,
flags: §ion.flags,
})
.collect();
let idx_path = dir.join("_index.json");
fs::write(&idx_path, serde_json::to_vec_pretty(&index)?)?;
Ok(())
}