lib/contexts/
annotation.rs1use std::collections::BTreeSet;
4
5use serde::Serialize;
6
7use crate::models::annotation::{Annotation, AnnotationMetadata, AnnotationStyle};
8use crate::strings;
9
10#[derive(Debug, Serialize)]
14pub struct AnnotationContext<'a> {
15 #[allow(missing_docs)]
16 pub body: &'a str,
17 #[allow(missing_docs)]
18 pub style: &'a AnnotationStyle,
19 #[allow(missing_docs)]
20 pub notes: &'a str,
21 #[allow(missing_docs)]
22 pub tags: &'a BTreeSet<String>,
23 #[allow(missing_docs)]
24 pub metadata: &'a AnnotationMetadata,
25
26 pub slugs: AnnotationSlugs,
28}
29
30impl<'a> From<&'a Annotation> for AnnotationContext<'a> {
31 fn from(annotation: &'a Annotation) -> Self {
32 Self {
33 body: &annotation.body,
34 style: &annotation.style,
35 notes: &annotation.notes,
36 tags: &annotation.tags,
37 metadata: &annotation.metadata,
38 slugs: AnnotationSlugs {
39 metadata: AnnotationMetadataSlugs {
40 created: strings::to_slug_date(&annotation.metadata.created),
41 modified: strings::to_slug_date(&annotation.metadata.modified),
42 },
43 },
44 }
45 }
46}
47
48#[derive(Debug, Serialize)]
50pub struct AnnotationSlugs {
51 #[allow(missing_docs)]
52 metadata: AnnotationMetadataSlugs,
53}
54
55#[derive(Debug, Serialize)]
59pub struct AnnotationMetadataSlugs {
60 #[allow(missing_docs)]
61 created: String,
62 #[allow(missing_docs)]
63 modified: String,
64}