Skip to content

Commit c595083

Browse files
committed
feat(page_template): add raw annotations
1 parent de6f88a commit c595083

File tree

4 files changed

+14
-6
lines changed

4 files changed

+14
-6
lines changed

Cargo.lock

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,8 @@ The following keys can be used inside the template:
255255
* `{{ relative_path }}` - path relative to KB directory
256256
* `{{ absolute_path }}` - full path on filesystem
257257
* `annotations` - a list of *rendered* annotations (according to the annotation template)
258+
* `raw_annotations` - a list of annotations (in case you need info for the page about the annotations -
259+
e.g. `{{raw_annotations.0.title}}`)
258260

259261
The default template is:
260262

src/configuration.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -633,10 +633,14 @@ file_extension = '{}'
633633
relative_path: "relative/path/to/page.md".to_string(),
634634
absolute_path: "absolute/path/to/page.md".to_string(),
635635
},
636-
annotations: vec![test_annotation_1, test_annotation_2]
636+
annotations: vec![test_annotation_1.clone(), test_annotation_2.clone()]
637637
.into_iter()
638638
.map(|a| hbs.render("annotation", &AnnotationTemplate::from_annotation(a)))
639639
.collect::<Result<Vec<String>, _>>()?,
640+
raw_annotations: vec![
641+
AnnotationTemplate::from_annotation(test_annotation_1),
642+
AnnotationTemplate::from_annotation(test_annotation_2),
643+
],
640644
};
641645

642646
self.page_template = loop {

src/gooseberry/knowledge_base.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@ pub struct PageTemplate {
154154
#[serde(flatten)]
155155
pub link_data: LinkTemplate,
156156
pub annotations: Vec<String>,
157+
pub raw_annotations: Vec<AnnotationTemplate>,
157158
}
158159

159160
/// ## Markdown generation
@@ -360,9 +361,10 @@ impl Gooseberry {
360361
let page_data = PageTemplate {
361362
link_data,
362363
annotations: inner_annotations
363-
.into_iter()
364+
.iter()
364365
.map(|a| hbs.render("annotation", &a))
365366
.collect::<Result<Vec<String>, _>>()?,
367+
raw_annotations: inner_annotations,
366368
};
367369
fs::File::create(&path)?
368370
.write_all(hbs.render("page", &page_data)?.as_bytes())?;

0 commit comments

Comments
 (0)