Skip to content

Commit 1539d21

Browse files
committed
src:migrate:intermediate:working
1 parent 3e9b7a7 commit 1539d21

File tree

2 files changed

+18
-61
lines changed

2 files changed

+18
-61
lines changed

src/lib.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
//! cargo run --example scrollable
33
//!
44
use clap::Parser;
5-
use pulldown_cmark::{html, Parser as HTMLParser};
65
use pulldown_cmark::Options;
6+
use pulldown_cmark::{html, Parser as HTMLParser};
77
use rust_embed::Embed;
88

99
use std::io;
@@ -22,8 +22,6 @@ use tokio::fs;
2222
use tokio::fs::File;
2323
use tokio::io::AsyncWriteExt;
2424

25-
26-
2725
pub mod path;
2826

2927
#[derive(Embed)]
@@ -94,7 +92,6 @@ pub struct Args {
9492
pub export_path: Option<PathBuf>,
9593
}
9694

97-
9895
pub async fn extract(filename: &str, output_dir: &Path) -> io::Result<()> {
9996
match Template::get(filename) {
10097
Some(embedded_file) => {
@@ -118,7 +115,7 @@ pub async fn extract(filename: &str, output_dir: &Path) -> io::Result<()> {
118115
}
119116
}
120117

121-
async fn extract_html(filename: &str, output_dir: &Path) -> io::Result<()> {
118+
pub async fn extract_html(filename: &str, output_dir: &Path) -> io::Result<()> {
122119
match Template::get(filename) {
123120
Some(embedded_file) => {
124121
let output_path = output_dir
@@ -133,9 +130,12 @@ async fn extract_html(filename: &str, output_dir: &Path) -> io::Result<()> {
133130

134131
//std::str::from_utf8(embedded_file_data)
135132
//outfile.write_all(markdown_to_html(&std::str::from_utf8(embedded_file_data).expect("")).as_bytes())?;
136-
outfile.write_all(
137-
markdown_to_html(&std::str::from_utf8(&embedded_file_data).expect("")).as_bytes(),
138-
).await?;
133+
outfile
134+
.write_all(
135+
markdown_to_html(&std::str::from_utf8(&embedded_file_data).expect(""))
136+
.as_bytes(),
137+
)
138+
.await?;
139139

140140
//outfile.write_all(markdown_to_html(embedded_file_data[0..5]));
141141
tracing::debug!(
@@ -152,7 +152,7 @@ async fn extract_html(filename: &str, output_dir: &Path) -> io::Result<()> {
152152
}
153153
}
154154

155-
fn view_area() -> Area {
155+
pub fn view_area() -> Area {
156156
let mut area = Area::full_screen();
157157
area.pad_for_max_width(120); // we don't want a too wide text column
158158
area

src/main.rs

Lines changed: 9 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
11
use axum::response::Redirect;
2-
use nips::{Args, Template};
3-
use nips::*;
4-
use nips::path::canonicalize_path;
52
use nips::extract;
3+
use nips::extract_html;
64
use 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;
99
use axum::{
1010
extract::Request, /*handler::HandlerWithoutStateExt, http::StatusCode, */ routing::get,
1111
Router,
1212
};
1313
use clap::Parser;
1414
use pulldown_cmark::Options;
1515
use pulldown_cmark::{html, Parser as HTMLParser};
16+
use std::env;
1617
//use rust_embed::RustEmbed;
1718
use sha2::{Digest, Sha256};
1819
use std::fs::File;
@@ -31,13 +32,13 @@ use termimad::crossterm::{
3132
terminal::{self, Clear, ClearType, EnterAlternateScreen, LeaveAlternateScreen},
3233
};
3334
use termimad::*;
35+
use tokio::fs;
3436
use tower::ServiceExt;
3537
use tower_http::{
3638
services::{ServeDir, ServeFile},
3739
trace::TraceLayer,
3840
};
3941
use 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)]
12379
fn 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-
161116
fn 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

Comments
 (0)