From eb006486021298c98fe51aa4f7c9886cf5a3a3d3 Mon Sep 17 00:00:00 2001 From: 404salad <404salad@gmail.com> Date: Thu, 7 Nov 2024 17:09:22 +0530 Subject: [PATCH] Refactored paths --- content/deletethis.md | 6 ----- content/moo.md | 4 +++ content/new_blog.md | 5 ---- dist/articles/Cronjobs.html | 4 +-- .../Debugging C++ Programs with GDB.html | 4 +-- ...uld Watch Conference Talks on YouTube.html | 4 +-- dist/articles/Makefiles:).html | 4 +-- dist/articles/On Logging.html | 4 +-- dist/articles/deletethis.html | 18 ------------- dist/articles/file_for_testing2.html | 4 +-- dist/articles/image.html | 4 +-- dist/articles/image2.html | 4 +-- dist/articles/moo.html | 8 ++++-- dist/articles/new_blog.html | 19 -------------- dist/articles/newest_blog.html | 4 +-- dist/articles/readme.html | 4 +-- dist/index.html | 20 ++++++-------- src/consolidate_into_homepage.rs | 18 ++++++++++--- src/file_utils.rs | 2 ++ src/main.rs | 26 +++++++------------ src/parse_one_article.rs | 14 +++++----- 21 files changed, 73 insertions(+), 107 deletions(-) delete mode 100644 content/deletethis.md delete mode 100644 content/new_blog.md delete mode 100644 dist/articles/deletethis.html delete mode 100644 dist/articles/new_blog.html diff --git a/content/deletethis.md b/content/deletethis.md deleted file mode 100644 index 84f2c5b..0000000 --- a/content/deletethis.md +++ /dev/null @@ -1,6 +0,0 @@ -we can go over this -we can move back - -meww - - diff --git a/content/moo.md b/content/moo.md index e69de29..4dab724 100644 --- a/content/moo.md +++ b/content/moo.md @@ -0,0 +1,4 @@ +kon talha kon talha +rap aliah +toh jon talha +yes diff --git a/content/new_blog.md b/content/new_blog.md deleted file mode 100644 index 5719986..0000000 --- a/content/new_blog.md +++ /dev/null @@ -1,5 +0,0 @@ -# this is a new blog -i wonder if the feature is working -i guess the only way to tell is more testing - -I really love how powerful pattern matching is diff --git a/dist/articles/Cronjobs.html b/dist/articles/Cronjobs.html index a2fd75d..e3fc590 100644 --- a/dist/articles/Cronjobs.html +++ b/dist/articles/Cronjobs.html @@ -4,11 +4,11 @@ - Cronjobs + Cronjobs.md home -

Cronjobs

+

Cronjobs.md


running stuff in the background at a specified time is awesome

diff --git a/dist/articles/Debugging C++ Programs with GDB.html b/dist/articles/Debugging C++ Programs with GDB.html index 871eaea..cbabd09 100644 --- a/dist/articles/Debugging C++ Programs with GDB.html +++ b/dist/articles/Debugging C++ Programs with GDB.html @@ -4,11 +4,11 @@ - Debugging C++ Programs with GDB + Debugging C++ Programs with GDB.md home -

Debugging C++ Programs with GDB

+

Debugging C++ Programs with GDB.md


If you don’t use GDB but program in C/C++, you are missing out on a powerful debugging tool. Here’s a quick 5-minute tutorial to get you started.

Step 1: Compile with Debug Symbols

diff --git a/dist/articles/Every Programmer Should Watch Conference Talks on YouTube.html b/dist/articles/Every Programmer Should Watch Conference Talks on YouTube.html index 9094413..d3c851f 100644 --- a/dist/articles/Every Programmer Should Watch Conference Talks on YouTube.html +++ b/dist/articles/Every Programmer Should Watch Conference Talks on YouTube.html @@ -4,11 +4,11 @@ - Every Programmer Should Watch Conference Talks on YouTube + Every Programmer Should Watch Conference Talks on YouTube.md home -

Every Programmer Should Watch Conference Talks on YouTube

+

Every Programmer Should Watch Conference Talks on YouTube.md


I was going to write a longer article to convince everyone to watch the conferences but Its much better to give a summary of my favorite talks and hopefully that will be persuasive enough~

“The Tragedy of systemd” - Benno Rice

diff --git a/dist/articles/Makefiles:).html b/dist/articles/Makefiles:).html index 29478bb..e9f0e31 100644 --- a/dist/articles/Makefiles:).html +++ b/dist/articles/Makefiles:).html @@ -4,11 +4,11 @@ - Makefiles:) + Makefiles:).md home -

Makefiles:)

+

Makefiles:).md


Quick and Easy Makefile Guide

Begin by crafting a file named Makefile – the control center for your project’s build rules.

diff --git a/dist/articles/On Logging.html b/dist/articles/On Logging.html index b886c91..1264ebb 100644 --- a/dist/articles/On Logging.html +++ b/dist/articles/On Logging.html @@ -4,11 +4,11 @@ - On Logging + On Logging.md home -

On Logging

+

On Logging.md


just log everything

diff --git a/dist/articles/deletethis.html b/dist/articles/deletethis.html deleted file mode 100644 index a3ac6dd..0000000 --- a/dist/articles/deletethis.html +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - - deletethis - - -home -

deletethis

-
-

we can go over this -we can move back

-

meww

- - - diff --git a/dist/articles/file_for_testing2.html b/dist/articles/file_for_testing2.html index 5b3f44c..ada9a40 100644 --- a/dist/articles/file_for_testing2.html +++ b/dist/articles/file_for_testing2.html @@ -4,11 +4,11 @@ - file_for_testing2 + file_for_testing2.md home -

file_for_testing2

+

file_for_testing2.md


sometimes i think about how some feature is working

diff --git a/dist/articles/image.html b/dist/articles/image.html index db502ca..6e864fb 100644 --- a/dist/articles/image.html +++ b/dist/articles/image.html @@ -4,11 +4,11 @@ - image + image.md home -

image

+

image.md


Hello World

Alt text

diff --git a/dist/articles/image2.html b/dist/articles/image2.html index 8f7646e..ed8eb94 100644 --- a/dist/articles/image2.html +++ b/dist/articles/image2.html @@ -4,11 +4,11 @@ - image2 + image2.md home -

image2

+

image2.md


Hello World

Alt text

diff --git a/dist/articles/moo.html b/dist/articles/moo.html index 2b8d8c2..42865a2 100644 --- a/dist/articles/moo.html +++ b/dist/articles/moo.html @@ -4,12 +4,16 @@ - moo + moo.md home -

moo

+

moo.md


+

kon talha kon talha +rap aliah +toh jon talha +yes

diff --git a/dist/articles/new_blog.html b/dist/articles/new_blog.html deleted file mode 100644 index a67e8d0..0000000 --- a/dist/articles/new_blog.html +++ /dev/null @@ -1,19 +0,0 @@ - - - - - - - new_blog - - -home -

new_blog

-
-

this is a new blog

-

i wonder if the feature is working
-i guess the only way to tell is more testing

-

I really love how powerful pattern matching is

- - - diff --git a/dist/articles/newest_blog.html b/dist/articles/newest_blog.html index d9ea843..60c21ff 100644 --- a/dist/articles/newest_blog.html +++ b/dist/articles/newest_blog.html @@ -4,11 +4,11 @@ - newest_blog + newest_blog.md home -

newest_blog

+

newest_blog.md


we can see that this is the one on top!

we can go over this
diff --git a/dist/articles/readme.html b/dist/articles/readme.html index 98457ed..77d03df 100644 --- a/dist/articles/readme.html +++ b/dist/articles/readme.html @@ -4,11 +4,11 @@ - readme + readme.md home -

readme

+

readme.md


this is a blog and a static site generator
simply converts a folder of markdown files to a blog webpage

diff --git a/dist/index.html b/dist/index.html index 3e1b179..043c584 100644 --- a/dist/index.html +++ b/dist/index.html @@ -37,31 +37,27 @@
sahil

diff --git a/src/consolidate_into_homepage.rs b/src/consolidate_into_homepage.rs index 5247036..2f7321f 100644 --- a/src/consolidate_into_homepage.rs +++ b/src/consolidate_into_homepage.rs @@ -1,12 +1,24 @@ use super::config; -use crate::file_utils::read_directory_content; +use crate::file_utils::content_directory_files; use std::fs::File; use std::io::Write; pub fn create_homepage(user_config: &config::UserConfig) -> std::io::Result<()> { - let article_names = read_directory_content(); - let output_path = String::from("dist/index.html"); + let article_paths = content_directory_files(); + let article_names: Vec = article_paths + .into_iter() + .map(|path| { + path.file_name() + .and_then(|name| name.to_str()) + .unwrap_or_default() + .trim_end_matches(".md") + .to_string() + }) + .collect(); + + println!("{article_names:?}"); + let output_path = String::from("dist/index.html"); let mut document = String::new(); document.push_str(&format!( " diff --git a/src/file_utils.rs b/src/file_utils.rs index ba1bb83..87d7fc1 100644 --- a/src/file_utils.rs +++ b/src/file_utils.rs @@ -19,6 +19,7 @@ pub fn content_directory_files() -> Vec { .collect(); paths } +/* pub fn read_directory_content() -> Vec { let mut article_names: Vec = vec![]; let paths_result = fs::read_dir("content"); @@ -54,6 +55,7 @@ pub fn read_directory_content() -> Vec { article_names.reverse(); article_names } +*/ pub fn time_of_creation(path: String) -> SystemTime { let time: SystemTime = SystemTime::now(); diff --git a/src/main.rs b/src/main.rs index aee4b58..b65218c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -9,7 +9,8 @@ use rayon::prelude::*; use std::collections::HashMap; use std::fs; use std::path::PathBuf; -use std::time::SystemTime; +use std::thread::sleep; +use std::time::{Duration, SystemTime}; fn main() { /* @@ -60,6 +61,7 @@ fn main() { }) .collect(); + render_all(&user_config); // loop this based on file changes // TODO: make it in a seperate thread? but then have to deal with communicating bw threads // ie a thread to just check if changes have been made so that parsing can be non blocking @@ -80,6 +82,7 @@ fn main() { } else { render_all(&user_config); } + sleep(Duration::from_secs(1)); } } @@ -88,26 +91,17 @@ fn render_some(user_config: &UserConfig, files_changed: &Vec) { // no need of deleting old since we will overwrite them // this is different since we are doing it for each file atomically - let article_names: Vec = files_changed - .iter() - .filter_map(|path| path.file_name()) - .filter_map(|osstr| osstr.to_str()) - .map(|path| path.trim_end_matches(".md")) - .map(String::from) - .collect(); - println!("RENDERING SOME"); - println!("generated {article_names:?} blogs"); println!("---"); - article_names.par_iter().for_each(|article_name| { + files_changed.par_iter().for_each(|article_name| { let user_config_for_threads = user_config.clone(); - match parse_one_article::markdown_to_styled_html(&article_name, &user_config_for_threads) { + match parse_one_article::markdown_to_styled_html(article_name, &user_config_for_threads) { Ok(_) => { - println!("succesful parse for {article_name}") + println!("succesful parse for {}", article_name.display()) } Err(e) => { - eprintln!(" unsuccesful parse for {article_name}: {}", e) + eprintln!(" unsuccesful parse for {}: {}", article_name.display(), e) } } }); @@ -129,7 +123,7 @@ fn render_all(user_config: &UserConfig) { let article_dir = fs::read_dir("dist/articles"); file_utils::delete_dir_contents(article_dir); - let article_names = file_utils::read_directory_content(); + let article_names = file_utils::content_directory_files(); // println!("{:?}", article_names); // rebuilding all the articles in content directory (parallely) @@ -139,7 +133,7 @@ fn render_all(user_config: &UserConfig) { match parse_one_article::markdown_to_styled_html(&article_name, &user_config_for_threads) { Ok(_) => {} Err(e) => { - eprintln!("unsuccesful parse for {article_name} {}", e) + eprintln!("unsuccesful parse for {} {}", article_name.display(), e) } } }); diff --git a/src/parse_one_article.rs b/src/parse_one_article.rs index 9dd4741..aacd6c9 100644 --- a/src/parse_one_article.rs +++ b/src/parse_one_article.rs @@ -4,6 +4,7 @@ use std::fs::File; use std::io::prelude::*; use std::io::{BufReader, Error, Write}; use std::path::Path; +use std::path::PathBuf; // parse markdown to html fn parse_markdown(input: &str) -> String { @@ -49,17 +50,18 @@ fn wrap_html(markdown_output: &str, article: &str, _user_config: &config::UserCo /// convert a single .md file to html pub fn markdown_to_styled_html( - article: &str, + article_path: &PathBuf, user_config: &config::UserConfig, ) -> std::io::Result<()> { - println!("parsing - {article}"); - let mut input_path = String::from("content/") + &article.to_owned(); - let mut output_path = String::from("dist/articles/") + &article.to_owned(); - input_path.push_str(".md"); + let article = article_path.file_name().unwrap().to_string_lossy(); + println!("kparsing - {article}"); + let input_path = String::from("content/") + &article.to_owned(); + let mut output_path = + String::from("dist/articles/") + &article.to_owned().trim_end_matches(".md"); output_path.push_str(".html"); let html_from_md = parse_markdown(&read_markdown(input_path)?); let mut file = File::create(output_path)?; - let wrapped_html = wrap_html(&html_from_md, article, user_config); + let wrapped_html = wrap_html(&html_from_md, &article, user_config); write!(file, "{wrapped_html}")?; Ok(()) }