From 02863a462bd466a26ceab8ff5f02200ed2be8a77 Mon Sep 17 00:00:00 2001 From: roman-rezinkin Date: Thu, 23 Sep 2021 00:43:00 -0400 Subject: [PATCH 1/4] Added initial md support --- src/parsing/input.rs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/parsing/input.rs b/src/parsing/input.rs index 523abb1..d49be16 100644 --- a/src/parsing/input.rs +++ b/src/parsing/input.rs @@ -67,8 +67,16 @@ fn visit_dirs(dir: &Path, cb: &dyn Fn(&mut String, &str)) -> Result<(), Box test.html - let mut name = filename.replace(".txt", ".html"); + //Create name array containing filname string array + let mut name = filename.repeat(1); + + //Check to see if the filename contains extension .txt or .md + if filename.contains(".txt") { + //Create final file name: test.txt -> test.html + name = name.replace(".txt", ".html"); + } else if filename.contains(".md") { + name = name.replace(".md", ".html"); + } //When doing nested subdirectories a / would left from the subirectory name ex. /test.html if name.starts_with('/') { From 1f4cd92d09dff72864bbd00695b387defccc9763 Mon Sep 17 00:00:00 2001 From: roman-rezinkin Date: Thu, 23 Sep 2021 00:45:14 -0400 Subject: [PATCH 2/4] Fixed a small issue with md identification --- src/parsing/input.rs | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/parsing/input.rs b/src/parsing/input.rs index d49be16..7e64a4a 100644 --- a/src/parsing/input.rs +++ b/src/parsing/input.rs @@ -16,11 +16,20 @@ pub fn finalize_dist(args: Vec) -> Result<(), Box> { recursive(file.into()); } else { //Otherwise basic file movement to dist - let html = file.strip_suffix(".txt").unwrap().to_owned() + ".html"; - let new_location = "./dist/".to_owned() + &html; - fs::copy(&html, new_location).unwrap(); - fs::remove_file(html).unwrap(); + //Quick Check to see if file extension is .txt or .md + if file.contains(".txt") { + let html = file.strip_suffix(".txt").unwrap().to_owned() + ".html"; + let new_location = "./dist/".to_owned() + &html; + fs::copy(&html, new_location).unwrap(); + fs::remove_file(html).unwrap(); + } else { + let md = file.strip_suffix(".md").unwrap().to_owned() + ".html"; + let new_location = "./dist/".to_owned() + &md; + fs::copy(&md, new_location).unwrap(); + fs::remove_file(md).unwrap(); + } } + }); Ok(()) From 575e465ebef1a3fdd8ac92822a45e429edfa4dac Mon Sep 17 00:00:00 2001 From: roman-rezinkin Date: Thu, 23 Sep 2021 00:47:31 -0400 Subject: [PATCH 3/4] Added bold syntax from markdown --- src/parsing/input.rs | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/parsing/input.rs b/src/parsing/input.rs index 7e64a4a..03562a5 100644 --- a/src/parsing/input.rs +++ b/src/parsing/input.rs @@ -172,10 +172,19 @@ fn process(file: &mut String, filename: &str) { vec_lines.into_iter().for_each(|curr_line| { if !curr_line.is_empty() { if firstline { - line = "\t

".to_owned() + curr_line; - firstline = false; + if curr_line.contains("**") { + line = "\t

".to_owned() + curr_line + ""; + firstline = false; + } else { + line = "\t

".to_owned() + curr_line; + firstline = false; + } } else { - line = "\n\t".to_owned() + curr_line; + if curr_line.contains("**") { + line = "\n\t".to_owned() + curr_line + ""; + } else { + line = "\n\t".to_owned() + curr_line; + } } html.write_all(line.as_bytes()) .expect("Could not write to file"); From d128cbcfeea6b6aab3026b971c9520692d73ca81 Mon Sep 17 00:00:00 2001 From: roman-rezinkin Date: Thu, 23 Sep 2021 00:50:32 -0400 Subject: [PATCH 4/4] Fixed README to include markdown feature --- README.md | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 04ef400..18f6114 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ ### What is this project? -This is a simple [Static Site Generator](https://www.cloudflare.com/en-ca/learning/performance/static-site-generator/#:~:text=A%20static%20site%20generator%20is,and%20a%20set%20of%20templates.&text=Static%20site%20generators%20are%20an,generating%20webpages%2C%20and%20implementing%20templates.) that converts txt files to html +This is a simple [Static Site Generator](https://www.cloudflare.com/en-ca/learning/performance/static-site-generator/#:~:text=A%20static%20site%20generator%20is,and%20a%20set%20of%20templates.&text=Static%20site%20generators%20are%20an,generating%20webpages%2C%20and%20implementing%20templates.) that converts txt and md files to html ## Sample Site [Rssg Sample](https://antonio-bennett.github.io/) @@ -24,7 +24,9 @@ By using the -h or --help flag user is able to see help information ### Input -The program accepts inputs from the user using the -i or --input flag. Acceptable inputs are files and or folders +The program accepts inputs from the user using the -i or --input flag. Acceptable inputs are files and or folders. The program allows for the input for txt and md file extensions. + +Currently, the only working Markdown syntax is bold. ### Output Output is stored in a current directory in folder named dist @@ -48,4 +50,4 @@ is converted to # USAGE -![image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jiekksl0twj6ehxpwl6r.png) +![image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jiekksl0twj6ehxpwl6r.png) \ No newline at end of file