@@ -60,12 +60,13 @@ struct RenderedMarkdown {
6060}
6161
6262impl RenderedMarkdown {
63- fn new ( path : & Path ) -> Result < Self > {
63+ fn new ( path : & Path , light : bool ) -> Result < Self > {
6464 let markdown_content = fs:: read_to_string ( path) . context ( "Failed to read markdown file" ) ?;
6565
6666 let rendered_markdown = render_markdown (
6767 & markdown_content,
6868 path. file_name ( ) . unwrap ( ) . to_str ( ) . unwrap ( ) ,
69+ light,
6970 ) ?;
7071
7172 Ok ( Self {
@@ -74,13 +75,14 @@ impl RenderedMarkdown {
7475 } )
7576 }
7677
77- fn rebuild ( & mut self ) -> Result < ( ) > {
78+ fn rebuild ( & mut self , light : bool ) -> Result < ( ) > {
7879 let markdown_content =
7980 fs:: read_to_string ( & self . path ) . context ( "Failed to read markdown file" ) ?;
8081
8182 self . content = render_markdown (
8283 & markdown_content,
8384 self . path . file_name ( ) . unwrap ( ) . to_str ( ) . unwrap ( ) ,
85+ light,
8486 ) ?;
8587
8688 Ok ( ( ) )
@@ -144,6 +146,7 @@ async fn main() -> Result<()> {
144146 let rendered_html = render_markdown (
145147 & markdown_content,
146148 markdown_file_path. file_name ( ) . unwrap ( ) . to_str ( ) . unwrap ( ) , // FIXME: horrible unwrap chain..
149+ args. light ,
147150 ) ?;
148151
149152 fs:: create_dir_all ( export_dir) . context ( "Failed to create export directory" ) ?;
@@ -161,7 +164,10 @@ async fn main() -> Result<()> {
161164 return Ok ( ( ) ) ;
162165 }
163166
164- let state = Arc :: new ( RwLock :: new ( RenderedMarkdown :: new ( & markdown_file_path) ?) ) ;
167+ let state = Arc :: new ( RwLock :: new ( RenderedMarkdown :: new (
168+ & markdown_file_path,
169+ args. light ,
170+ ) ?) ) ;
165171
166172 use notify:: EventKind :: { Create , Modify , Remove } ;
167173 use notify_debouncer_full:: { DebounceEventResult , new_debouncer} ;
@@ -185,7 +191,7 @@ async fn main() -> Result<()> {
185191 let state = Arc :: clone ( & state) ;
186192
187193 rt. spawn ( async move {
188- match state. write ( ) . await . rebuild ( ) {
194+ match state. write ( ) . await . rebuild ( args . light ) {
189195 Ok ( _) => {
190196 let _ = RELOAD_TX . send ( "reload" . to_string ( ) ) ;
191197 }
@@ -204,7 +210,7 @@ async fn main() -> Result<()> {
204210 . watch ( root_path. as_path ( ) , notify:: RecursiveMode :: Recursive )
205211 . with_context ( || format ! ( "Failed to watch path: {}" , root_path. display( ) ) ) ?;
206212
207- state. write ( ) . await . rebuild ( ) ?;
213+ state. write ( ) . await . rebuild ( args . light ) ?;
208214
209215 let app = Router :: new ( )
210216 . route ( "/" , get ( serve) )
@@ -268,6 +274,7 @@ async fn append_livereload_script(request: Request, next: Next) -> Response {
268274struct HtmlTemplate < ' a > {
269275 title : & ' a str ,
270276 contents : & ' a str ,
277+ light : bool ,
271278}
272279
273280struct ComrakConfig {
@@ -333,7 +340,11 @@ fn init_comrak_config(light: bool) {
333340 let _ = COMRAK_CONFIG . set ( ComrakConfig { options, plugins } ) ;
334341}
335342
336- fn render_markdown ( markdown_content : & str , title : & str ) -> Result < String , askama:: Error > {
343+ fn render_markdown (
344+ markdown_content : & str ,
345+ title : & str ,
346+ light : bool ,
347+ ) -> Result < String , askama:: Error > {
337348 let comrak_config = COMRAK_CONFIG . get ( ) . unwrap ( ) ;
338349
339350 let rendered_markdown = comrak:: markdown_to_html_with_plugins (
@@ -345,6 +356,7 @@ fn render_markdown(markdown_content: &str, title: &str) -> Result<String, askama
345356 HtmlTemplate {
346357 title,
347358 contents : & rendered_markdown,
359+ light,
348360 }
349361 . render ( )
350362}
0 commit comments