Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue 6: Introduce Markdown functionality #7

Merged
merged 4 commits into from
Sep 23, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -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/)
Expand All @@ -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
Expand All @@ -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)
44 changes: 35 additions & 9 deletions src/parsing/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,20 @@ pub fn finalize_dist(args: Vec<String>) -> Result<(), Box<dyn Error>> {
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(())
Expand Down Expand Up @@ -67,8 +76,16 @@ fn visit_dirs(dir: &Path, cb: &dyn Fn(&mut String, &str)) -> Result<(), Box<dyn
}

fn process(file: &mut String, filename: &str) {
//Create final file name: test.txt -> 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('/') {
Expand Down Expand Up @@ -155,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<p>".to_owned() + curr_line;
firstline = false;
if curr_line.contains("**") {
line = "\t<p><b>".to_owned() + curr_line + "</b>";
firstline = false;
} else {
line = "\t<p>".to_owned() + curr_line;
firstline = false;
}
} else {
line = "\n\t".to_owned() + curr_line;
if curr_line.contains("**") {
line = "\n\t<b>".to_owned() + curr_line + "</b>";
} else {
line = "\n\t".to_owned() + curr_line;
}
}
html.write_all(line.as_bytes())
.expect("Could not write to file");
Expand Down