@@ -9,7 +9,6 @@ use rayon::prelude::*;
99use sass_rs:: { Options , compile_file} ;
1010use serde:: Serialize ;
1111use serde_json:: { Value , json} ;
12- use std:: collections:: HashMap ;
1312use std:: fs:: { self , File } ;
1413use std:: io:: { self , Write } ;
1514use std:: path:: { Path , PathBuf } ;
@@ -33,53 +32,12 @@ struct ReleasePost {
3332 url : String ,
3433}
3534
36- fn month_name ( month_num : & Value , _args : & HashMap < String , Value > ) -> tera:: Result < Value > {
37- let month_num = month_num
38- . as_u64 ( )
39- . expect ( "month_num should be an unsigned integer" ) ;
40- let name = match month_num {
41- 1 => "Jan." ,
42- 2 => "Feb." ,
43- 3 => "Mar." ,
44- 4 => "Apr." ,
45- 5 => "May" ,
46- 6 => "June" ,
47- 7 => "July" ,
48- 8 => "Aug." ,
49- 9 => "Sept." ,
50- 10 => "Oct." ,
51- 11 => "Nov." ,
52- 12 => "Dec." ,
53- _ => panic ! ( "invalid month! ({month_num})" ) ,
54- } ;
55- Ok ( name. into ( ) )
56- }
57-
58- // Tera and Handlebars escape HTML differently by default.
59- // Tera: &<>"'/
60- // Handlebars: &<>"'`=
61- // To make the transition testable, this function escapes just like Handlebars.
62- fn escape_hbs ( input : & Value , _args : & HashMap < String , Value > ) -> tera:: Result < Value > {
63- let input = input. as_str ( ) . expect ( "input should be a string" ) ;
64- Ok ( input
65- . replace ( "&" , "&" )
66- . replace ( "<" , "<" )
67- . replace ( ">" , ">" )
68- . replace ( "\" " , """ )
69- . replace ( "'" , "'" )
70- . replace ( "`" , "`" )
71- . replace ( "=" , "=" )
72- . into ( ) )
73- }
74-
7535impl Generator {
7636 fn new (
7737 out_directory : impl AsRef < Path > ,
7838 posts_directory : impl AsRef < Path > ,
7939 ) -> eyre:: Result < Self > {
8040 let mut tera = Tera :: new ( "templates/*" ) ?;
81- tera. register_filter ( "month_name" , month_name) ;
82- tera. register_filter ( "escape_hbs" , escape_hbs) ;
8341 tera. autoescape_on ( vec ! [ ] ) ; // disable auto-escape for .html templates
8442 Ok ( Generator {
8543 tera,
0 commit comments