@@ -32,14 +32,12 @@ const PATH_PREFIX_CRATES: &str = "/crates/";
3232type TemplateEnvFut = Shared < BoxFuture < ' static , Arc < minijinja:: Environment < ' static > > > > ;
3333type TemplateCache = moka:: future:: Cache < Cow < ' static , str > , String > ;
3434
35- /// Initialize [`minijinja::Environment`] given the path to the index.html file. This should
36- /// only be done once as it will load said file from persistent storage.
37- async fn init_template_env (
38- index_html_template_path : impl AsRef < Path > ,
39- ) -> Arc < minijinja:: Environment < ' static > > {
40- let template_j2 = tokio:: fs:: read_to_string ( index_html_template_path. as_ref ( ) )
35+ /// Initialize [`minijinja::Environment`] given the index.html file at `dist/index.html`.
36+ /// This should only be done once as it will load said file from persistent storage.
37+ async fn init_template_env ( ) -> Arc < minijinja:: Environment < ' static > > {
38+ let template_j2 = tokio:: fs:: read_to_string ( "dist/index.html" )
4139 . await
42- . expect ( "Error loading index.html template. Is the frontend package built yet?" ) ;
40+ . expect ( "Error loading dist/ index.html template. Is the frontend package built yet?" ) ;
4341
4442 let mut env = Environment :: empty ( ) ;
4543 env. add_template_owned ( INDEX_TEMPLATE_NAME , template_j2)
@@ -75,7 +73,7 @@ pub async fn serve_html(state: AppState, request: Request, next: Next) -> Respon
7573 }
7674
7775 // `state.config.og_image_base_url` will always be `Some` as that's required
78- // if `state.config.index_html_template_path ` is `Some `, and otherwise this
76+ // if `state.config.serve_html ` is `true `, and otherwise this
7977 // middleware won't be executed; see `crate::middleware::apply_axum_middleware`.
8078 let og_image_base_url = state. config . og_image_base_url . as_ref ( ) . unwrap ( ) ;
8179 let og_image_url = generate_og_image_url ( path, og_image_base_url) ;
@@ -87,13 +85,8 @@ pub async fn serve_html(state: AppState, request: Request, next: Next) -> Respon
8785 // `OnceLock::get_or_init` blocks as long as its intializer is running in another thread.
8886 // Note that this won't take long, as the constructed Futures are not awaited
8987 // during initialization.
90- let template_env = TEMPLATE_ENV . get_or_init ( || {
91- // At this point we can safely assume `state.config.index_html_template_path` is `Some`,
92- // as this middleware won't be executed otherwise; see `crate::middleware::apply_axum_middleware`.
93- init_template_env ( state. config . index_html_template_path . clone ( ) . unwrap ( ) )
94- . boxed ( )
95- . shared ( )
96- } ) ;
88+ let template_env =
89+ TEMPLATE_ENV . get_or_init ( || init_template_env ( ) . boxed ( ) . shared ( ) ) ;
9790
9891 // Render the HTML given the OG image URL
9992 let env = template_env. clone ( ) . await ;
0 commit comments