specfold_core/plugins/
payload.rs1use crate::corpus::Corpus;
4use crate::graph::Graph;
5use serde_json::{Value, json};
6
7pub fn docs(c: &Corpus, only: Option<&[usize]>) -> Value {
8 let pick: Vec<usize> = match only {
9 Some(list) => list.to_vec(),
10 None => (0..c.docs.len()).collect(),
11 };
12 Value::Array(
13 pick.into_iter()
14 .map(|i| {
15 let d = &c.docs[i];
16 json!({
17 "id": d.id.to_string(),
18 "type": d.id.ty,
19 "owner": d.id.owner,
20 "path": d.path,
21 "chapters": d.chapters,
22 "title": d.title,
23 "status": d.status(),
24 "frontmatter": d.fm(),
25 "anchors": d.anchors.iter().map(|a| &a.item).collect::<Vec<_>>(),
26 })
27 })
28 .collect(),
29 )
30}
31
32pub fn edges(c: &Corpus, g: &Graph) -> Value {
33 Value::Array(g.edges.iter().map(|e| json!({"from": c.docs[e.from].id.to_string(), "to": c.docs[e.to].id.to_string(), "kind": e.kind, "anchor": e.anchor})).collect())
34}