1
- use crate :: {
2
- error:: Result ,
3
- utils:: { get_config, ConfigName } ,
4
- } ;
1
+ use crate :: error:: Result ;
5
2
use anyhow:: Context ;
6
3
use chrono:: { DateTime , Utc } ;
7
4
use path_slash:: PathExt ;
8
- use postgres:: Client ;
9
5
use serde_json:: Value ;
10
6
use std:: { collections:: HashMap , fmt, path:: PathBuf , sync:: Arc } ;
11
7
use tera:: { Result as TeraResult , Tera } ;
12
- use tracing:: { error , trace} ;
8
+ use tracing:: trace;
13
9
use walkdir:: WalkDir ;
14
10
15
11
const TEMPLATES_DIRECTORY : & str = "templates" ;
@@ -31,11 +27,11 @@ pub(crate) struct TemplateData {
31
27
}
32
28
33
29
impl TemplateData {
34
- pub ( crate ) fn new ( conn : & mut Client , num_threads : usize ) -> Result < Self > {
30
+ pub ( crate ) fn new ( num_threads : usize ) -> Result < Self > {
35
31
trace ! ( "Loading templates" ) ;
36
32
37
33
let data = Self {
38
- templates : load_templates ( conn ) ?,
34
+ templates : load_templates ( ) ?,
39
35
rendering_threadpool : rayon:: ThreadPoolBuilder :: new ( )
40
36
. num_threads ( num_threads)
41
37
. thread_name ( move |idx| format ! ( "docsrs-render {idx}" ) )
@@ -77,15 +73,7 @@ impl TemplateData {
77
73
}
78
74
}
79
75
80
- fn load_rustc_resource_suffix ( conn : & mut Client ) -> Result < String > {
81
- if let Some ( vers_str) = get_config :: < String > ( conn, ConfigName :: RustcVersion ) ? {
82
- return crate :: utils:: parse_rustc_version ( vers_str) ;
83
- }
84
-
85
- anyhow:: bail!( "failed to parse the rustc version" ) ;
86
- }
87
-
88
- fn load_templates ( conn : & mut Client ) -> Result < Tera > {
76
+ fn load_templates ( ) -> Result < Tera > {
89
77
// This uses a custom function to find the templates in the filesystem instead of Tera's
90
78
// builtin way (passing a glob expression to Tera::new), speeding up the startup of the
91
79
// application and running the tests.
@@ -115,19 +103,6 @@ fn load_templates(conn: &mut Client) -> Result<Tera> {
115
103
"docsrs_version" ,
116
104
Value :: String ( crate :: BUILD_VERSION . into ( ) ) ,
117
105
) ;
118
- // This function will return the resource suffix of the latest nightly used to build
119
- // documentation on docs.rs, or ??? if no resource suffix was found.
120
- ReturnValue :: add_function_to (
121
- & mut tera,
122
- "rustc_resource_suffix" ,
123
- Value :: String ( load_rustc_resource_suffix ( conn) . unwrap_or_else ( |err| {
124
- error ! ( "Failed to load rustc resource suffix: {:?}" , err) ;
125
- // This is not fatal because the server might be started before essential files are
126
- // generated during development. Returning "???" provides a degraded UX, but allows the
127
- // server to start every time.
128
- String :: from ( "???" )
129
- } ) ) ,
130
- ) ;
131
106
132
107
// Custom filters
133
108
tera. register_filter ( "timeformat" , timeformat) ;
@@ -376,10 +351,8 @@ mod tests {
376
351
377
352
#[ test]
378
353
fn test_templates_are_valid ( ) {
379
- crate :: test:: wrapper ( |env| {
380
- let db = env. db ( ) ;
381
-
382
- let tera = load_templates ( & mut db. conn ( ) ) . unwrap ( ) ;
354
+ crate :: test:: wrapper ( |_| {
355
+ let tera = load_templates ( ) . unwrap ( ) ;
383
356
tera. check_macro_files ( ) . unwrap ( ) ;
384
357
385
358
Ok ( ( ) )
0 commit comments