11use axum:: response:: Redirect ;
2- use nips:: { Args , Template } ;
3- use nips:: * ;
4- use nips:: path:: canonicalize_path;
52use nips:: extract;
3+ use nips:: extract_html;
64use nips:: markdown_to_html;
5+ use nips:: path:: canonicalize_path;
6+ use nips:: * ;
7+ use nips:: { Args , Template } ;
78//use tower_http::services::Redirect;
8- use std:: env;
99use axum:: {
1010 extract:: Request , /*handler::HandlerWithoutStateExt, http::StatusCode, */ routing:: get,
1111 Router ,
1212} ;
1313use clap:: Parser ;
1414use pulldown_cmark:: Options ;
1515use pulldown_cmark:: { html, Parser as HTMLParser } ;
16+ use std:: env;
1617//use rust_embed::RustEmbed;
1718use sha2:: { Digest , Sha256 } ;
1819use std:: fs:: File ;
@@ -31,13 +32,13 @@ use termimad::crossterm::{
3132 terminal:: { self , Clear , ClearType , EnterAlternateScreen , LeaveAlternateScreen } ,
3233} ;
3334use termimad:: * ;
35+ use tokio:: fs;
3436use tower:: ServiceExt ;
3537use tower_http:: {
3638 services:: { ServeDir , ServeFile } ,
3739 trace:: TraceLayer ,
3840} ;
3941use tracing_subscriber:: { fmt, layer:: SubscriberExt , EnvFilter , Registry } ;
40- use tokio:: fs;
4142//fn _make_executable(script_path: &Path) -> io::Result<()> {
4243// let mut permissions = fs::metadata(script_path)?.permissions();
4344// permissions.set_mode(permissions.mode() | 0o111);
@@ -74,51 +75,6 @@ use tokio::fs;
7475// }
7576//}
7677
77-
78- fn remove_md_extension ( filename : & str ) -> & str {
79- filename. strip_suffix ( ".md" ) . unwrap_or ( filename)
80- }
81-
82- async fn extract_html ( filename : & str , output_dir : & Path ) -> io:: Result < ( ) > {
83- match Template :: get ( filename) {
84- Some ( embedded_file) => {
85- let output_path = output_dir
86- . join ( "docs" )
87- . join ( remove_md_extension ( filename) . to_owned ( ) + ".html" ) ;
88- if let Some ( parent) = output_path. parent ( ) {
89- fs:: create_dir_all ( parent) . await . expect ( "" ) ;
90- }
91- let mut outfile = File :: create ( & output_path) ?;
92- // let embedded_file_data: &'static [u8] = embedded_file.data.as_ref();
93- let embedded_file_data: Vec < u8 > = embedded_file. data . as_ref ( ) . to_vec ( ) ; // Create an owned Vec
94-
95- //std::str::from_utf8(embedded_file_data)
96- //outfile.write_all(markdown_to_html(&std::str::from_utf8(embedded_file_data).expect("")).as_bytes())?;
97- outfile. write_all (
98- markdown_to_html ( & std:: str:: from_utf8 ( & embedded_file_data) . expect ( "" ) ) . as_bytes ( ) ,
99- ) ?;
100-
101- //outfile.write_all(markdown_to_html(embedded_file_data[0..5]));
102- tracing:: debug!(
103- "Successfully exported '{}' to '{}'" ,
104- filename,
105- output_path. display( )
106- ) ;
107- Ok ( ( ) )
108- }
109- None => Err ( io:: Error :: new (
110- io:: ErrorKind :: NotFound ,
111- format ! ( "Embedded file '{}' not found!" , filename) ,
112- ) ) ,
113- }
114- }
115-
116- fn view_area ( ) -> Area {
117- let mut area = Area :: full_screen ( ) ;
118- area. pad_for_max_width ( 120 ) ;
119- area
120- }
121-
12278#[ allow( unused_variables) ]
12379fn run_app ( skin : MadSkin , nip : String ) -> Result < ( ) , Error > {
12480 let res = markdown_to_html ( & nip) ;
@@ -157,7 +113,6 @@ fn run_app(skin: MadSkin, nip: String) -> Result<(), Error> {
157113 Ok ( ( ) )
158114}
159115
160-
161116fn calculate_sha256 ( data : & [ u8 ] ) -> String {
162117 let mut hasher = Sha256 :: new ( ) ;
163118 hasher. update ( data) ;
@@ -313,7 +268,9 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
313268 tracing:: debug!(
314269 "Canonical path of '{}': {}" ,
315270 absolute_path_str,
316- canonicalize_path( Path :: new( absolute_path_str) ) . await ?. display( )
271+ canonicalize_path( Path :: new( absolute_path_str) )
272+ . await ?
273+ . display( )
317274 ) ;
318275
319276 if args. serve {
0 commit comments