@@ -26,36 +26,18 @@ use tokio::sync::mpsc;
2626#[ prefix = "static/" ]
2727struct Static ;
2828
29- impl Static {
30- fn get_styles ( ) -> String {
31- match Static :: get ( "static/global.css" ) {
32- Some ( file) => match std:: str:: from_utf8 ( & file. data ) {
33- Ok ( css) => css. to_string ( ) ,
34- Err ( e) => {
35- eprintln ! ( "Failed to read CSS file: {e}" ) ;
36- String :: new ( )
37- }
38- } ,
39- None => {
40- eprintln ! ( "CSS file not found in embedded assets." ) ;
41- String :: new ( )
42- }
43- }
44- }
45-
46- fn get_scripts ( ) -> String {
47- match Static :: get ( "static/client.js" ) {
48- Some ( file) => match std:: str:: from_utf8 ( & file. data ) {
49- Ok ( js) => js. to_string ( ) ,
50- Err ( e) => {
51- eprintln ! ( "Failed to read JS file: {e}" ) ;
52- String :: new ( )
53- }
54- } ,
55- None => {
56- eprintln ! ( "JS file not found in embedded assets." ) ;
29+ fn get_embedded_file ( file_path : & str ) -> String {
30+ match Static :: get ( file_path) {
31+ Some ( file) => match std:: str:: from_utf8 ( & file. data ) {
32+ Ok ( content) => content. to_string ( ) ,
33+ Err ( e) => {
34+ eprintln ! ( "Failed to read embedded file: {e}" ) ;
5735 String :: new ( )
5836 }
37+ } ,
38+ None => {
39+ eprintln ! ( "File not found in embedded files." ) ;
40+ String :: new ( )
5941 }
6042 }
6143}
@@ -134,6 +116,23 @@ struct Mdwatch {
134116 title : String ,
135117 style : String ,
136118 script : String ,
119+ lib : Libs ,
120+ }
121+
122+ struct Libs {
123+ hljs_theme_dark : String ,
124+ hljs_theme_light : String ,
125+ hljs_script : String ,
126+ }
127+
128+ impl Default for Libs {
129+ fn default ( ) -> Self {
130+ Self {
131+ hljs_theme_dark : get_embedded_file ( "static/lib/github-dark.min.css" ) ,
132+ hljs_theme_light : get_embedded_file ( "static/lib/github-light.min.css" ) ,
133+ hljs_script : get_embedded_file ( "static/lib/highlight.min.js" ) ,
134+ }
135+ }
137136}
138137
139138#[ get( "/" ) ]
@@ -174,8 +173,9 @@ async fn home(file: web::Data<String>) -> actix_web::Result<HttpResponse> {
174173 let template = Mdwatch {
175174 content : html_output,
176175 title : file_name. to_string_lossy ( ) . to_string ( ) ,
177- style : Static :: get_styles ( ) ,
178- script : Static :: get_scripts ( ) ,
176+ style : get_embedded_file ( "static/global.css" ) ,
177+ script : get_embedded_file ( "static/client.js" ) ,
178+ lib : Libs :: default ( ) ,
179179 } ;
180180
181181 match template. render ( ) {
0 commit comments