7
7
use crate :: rhai_engine:: custom_rhai_engine_init;
8
8
9
9
use super :: content:: { Content , Head } ;
10
+ use handlebars:: handlebars_helper;
10
11
use serde:: { Deserialize , Serialize } ;
11
12
12
13
/// The name of the default template.
@@ -81,9 +82,9 @@ pub struct PageValues {
81
82
}
82
83
83
84
impl From < Content > for PageValues {
84
- fn from ( mut c : Content ) -> Self {
85
+ fn from ( c : Content ) -> Self {
85
86
PageValues {
86
- body : c. render_markdown ( & None ) ,
87
+ body : c. body ,
87
88
head : c. head ,
88
89
published : c. published ,
89
90
}
@@ -102,6 +103,11 @@ pub struct Renderer<'a> {
102
103
handlebars : handlebars:: Handlebars < ' a > ,
103
104
}
104
105
106
+ handlebars_helper ! ( render_markdown: |content: Content |{
107
+ let mut content = content;
108
+ content. render_markdown( & None )
109
+ } ) ;
110
+
105
111
#[ cfg( feature = "server" ) ]
106
112
impl < ' a > Renderer < ' a > {
107
113
/// Create a new renderer with the necessary directories attached.
@@ -136,6 +142,7 @@ impl<'a> Renderer<'a> {
136
142
pub fn load_template_dir ( & mut self ) -> Result < ( ) , anyhow:: Error > {
137
143
#[ cfg( feature = "server" ) ]
138
144
self . register_helpers ( ) ;
145
+ self . handlebars . register_helper ( "render_markdown" , Box :: new ( render_markdown) ) ;
139
146
140
147
// If there is a theme, load the templates provided by it first
141
148
// Allows for user defined templates to take precedence
@@ -150,6 +157,7 @@ impl<'a> Renderer<'a> {
150
157
Ok ( ( ) )
151
158
}
152
159
160
+
153
161
/// Load the scripts directory
154
162
pub fn load_script_dir ( & mut self ) -> anyhow:: Result < ( ) > {
155
163
let mut theme_scripts: Vec < PathBuf > = Vec :: new ( ) ;
0 commit comments