Skip to content

Commit

Permalink
feat(page_template): add raw annotations
Browse files Browse the repository at this point in the history
  • Loading branch information
Ninjani committed Mar 29, 2021
1 parent de6f88a commit c595083
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 6 deletions.
8 changes: 4 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,8 @@ The following keys can be used inside the template:
* `{{ relative_path }}` - path relative to KB directory
* `{{ absolute_path }}` - full path on filesystem
* `annotations` - a list of *rendered* annotations (according to the annotation template)
* `raw_annotations` - a list of annotations (in case you need info for the page about the annotations -
e.g. `{{raw_annotations.0.title}}`)

The default template is:

Expand Down
6 changes: 5 additions & 1 deletion src/configuration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -633,10 +633,14 @@ file_extension = '{}'
relative_path: "relative/path/to/page.md".to_string(),
absolute_path: "absolute/path/to/page.md".to_string(),
},
annotations: vec![test_annotation_1, test_annotation_2]
annotations: vec![test_annotation_1.clone(), test_annotation_2.clone()]
.into_iter()
.map(|a| hbs.render("annotation", &AnnotationTemplate::from_annotation(a)))
.collect::<Result<Vec<String>, _>>()?,
raw_annotations: vec![
AnnotationTemplate::from_annotation(test_annotation_1),
AnnotationTemplate::from_annotation(test_annotation_2),
],
};

self.page_template = loop {
Expand Down
4 changes: 3 additions & 1 deletion src/gooseberry/knowledge_base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ pub struct PageTemplate {
#[serde(flatten)]
pub link_data: LinkTemplate,
pub annotations: Vec<String>,
pub raw_annotations: Vec<AnnotationTemplate>,
}

/// ## Markdown generation
Expand Down Expand Up @@ -360,9 +361,10 @@ impl Gooseberry {
let page_data = PageTemplate {
link_data,
annotations: inner_annotations
.into_iter()
.iter()
.map(|a| hbs.render("annotation", &a))
.collect::<Result<Vec<String>, _>>()?,
raw_annotations: inner_annotations,
};
fs::File::create(&path)?
.write_all(hbs.render("page", &page_data)?.as_bytes())?;
Expand Down

0 comments on commit c595083

Please sign in to comment.