Skip to content

Commit

Permalink
Refactored paths
Browse files Browse the repository at this point in the history
  • Loading branch information
404salad committed Nov 7, 2024
1 parent 0704d3b commit eb00648
Show file tree
Hide file tree
Showing 21 changed files with 73 additions and 107 deletions.
6 changes: 0 additions & 6 deletions content/deletethis.md

This file was deleted.

4 changes: 4 additions & 0 deletions content/moo.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
kon talha kon talha
rap aliah
toh jon talha
yes
5 changes: 0 additions & 5 deletions content/new_blog.md

This file was deleted.

4 changes: 2 additions & 2 deletions dist/articles/Cronjobs.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
<head>
<meta charset="UTF-8">
<link rel="stylesheet" href="../style.css">
<title>Cronjobs</title>
<title>Cronjobs.md</title>
</head>
<body class="container">
<a href='../index.html'>home</a>
<h1> Cronjobs </h1>
<h1> Cronjobs.md </h1>
<hr>
<blockquote>
<p>running stuff in the background at a specified time is awesome</p>
Expand Down
4 changes: 2 additions & 2 deletions dist/articles/Debugging C++ Programs with GDB.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
<head>
<meta charset="UTF-8">
<link rel="stylesheet" href="../style.css">
<title>Debugging C++ Programs with GDB</title>
<title>Debugging C++ Programs with GDB.md</title>
</head>
<body class="container">
<a href='../index.html'>home</a>
<h1> Debugging C++ Programs with GDB </h1>
<h1> Debugging C++ Programs with GDB.md </h1>
<hr>
<p>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.</p>
<h2>Step 1: Compile with Debug Symbols</h2>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
<head>
<meta charset="UTF-8">
<link rel="stylesheet" href="../style.css">
<title>Every Programmer Should Watch Conference Talks on YouTube</title>
<title>Every Programmer Should Watch Conference Talks on YouTube.md</title>
</head>
<body class="container">
<a href='../index.html'>home</a>
<h1> Every Programmer Should Watch Conference Talks on YouTube </h1>
<h1> Every Programmer Should Watch Conference Talks on YouTube.md </h1>
<hr>
<p>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~</p>
<h3><a href="https://www.youtube.com/watch?v=o_AIw9bGogo">“The Tragedy of systemd” - Benno Rice</a></h3>
Expand Down
4 changes: 2 additions & 2 deletions dist/articles/Makefiles:).html
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
<head>
<meta charset="UTF-8">
<link rel="stylesheet" href="../style.css">
<title>Makefiles:)</title>
<title>Makefiles:).md</title>
</head>
<body class="container">
<a href='../index.html'>home</a>
<h1> Makefiles:) </h1>
<h1> Makefiles:).md </h1>
<hr>
<h2>Quick and Easy Makefile Guide</h2>
<p>Begin by crafting a file named <code>Makefile</code> – the control center for your project’s build rules.</p>
Expand Down
4 changes: 2 additions & 2 deletions dist/articles/On Logging.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
<head>
<meta charset="UTF-8">
<link rel="stylesheet" href="../style.css">
<title>On Logging</title>
<title>On Logging.md</title>
</head>
<body class="container">
<a href='../index.html'>home</a>
<h1> On Logging </h1>
<h1> On Logging.md </h1>
<hr>
<blockquote>
<p>just log everything </p>
Expand Down
18 changes: 0 additions & 18 deletions dist/articles/deletethis.html

This file was deleted.

4 changes: 2 additions & 2 deletions dist/articles/file_for_testing2.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
<head>
<meta charset="UTF-8">
<link rel="stylesheet" href="../style.css">
<title>file_for_testing2</title>
<title>file_for_testing2.md</title>
</head>
<body class="container">
<a href='../index.html'>home</a>
<h1> file_for_testing2 </h1>
<h1> file_for_testing2.md </h1>
<hr>
<p>sometimes i think about how some feature is working</p>

Expand Down
4 changes: 2 additions & 2 deletions dist/articles/image.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions dist/articles/image2.html

Large diffs are not rendered by default.

8 changes: 6 additions & 2 deletions dist/articles/moo.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,16 @@
<head>
<meta charset="UTF-8">
<link rel="stylesheet" href="../style.css">
<title>moo</title>
<title>moo.md</title>
</head>
<body class="container">
<a href='../index.html'>home</a>
<h1> moo </h1>
<h1> moo.md </h1>
<hr>
<p>kon talha kon talha
rap aliah
toh jon talha
yes</p>

</body>
</html>
19 changes: 0 additions & 19 deletions dist/articles/new_blog.html

This file was deleted.

4 changes: 2 additions & 2 deletions dist/articles/newest_blog.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
<head>
<meta charset="UTF-8">
<link rel="stylesheet" href="../style.css">
<title>newest_blog</title>
<title>newest_blog.md</title>
</head>
<body class="container">
<a href='../index.html'>home</a>
<h1> newest_blog </h1>
<h1> newest_blog.md </h1>
<hr>
<h2>we can see that this is the one on top!</h2>
<p>we can go over this<br />
Expand Down
4 changes: 2 additions & 2 deletions dist/articles/readme.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
<head>
<meta charset="UTF-8">
<link rel="stylesheet" href="../style.css">
<title>readme</title>
<title>readme.md</title>
</head>
<body class="container">
<a href='../index.html'>home</a>
<h1> readme </h1>
<h1> readme.md </h1>
<hr>
<p>this is a blog and a static site generator<br />
simply converts a folder of markdown files to a blog webpage</p>
Expand Down
20 changes: 8 additions & 12 deletions dist/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -37,31 +37,27 @@ <h6>sahil
<br>
<br>
<section id="articleList"><article>
<a href="articles/deletethis.html"> deletethis </a>
<a href="articles/image.html"> image </a>
</article><article>
<a href="articles/newest_blog.html"> newest_blog </a>
<a href="articles/Every Programmer Should Watch Conference Talks on YouTube.html"> Every Programmer Should Watch Conference Talks on YouTube </a>
</article><article>
<a href="articles/readme.html"> readme </a>
<a href="articles/Cronjobs.html"> Cronjobs </a>
</article><article>
<a href="articles/new_blog.html"> new_blog </a>
<a href="articles/Makefiles:).html"> Makefiles:) </a>
</article><article>
<a href="articles/moo.html"> moo </a>
</article><article>
<a href="articles/On Logging.html"> On Logging </a>
<a href="articles/image2.html"> image2 </a>
</article><article>
<a href="articles/file_for_testing2.html"> file_for_testing2 </a>
</article><article>
<a href="articles/image2.html"> image2 </a>
<a href="articles/newest_blog.html"> newest_blog </a>
</article><article>
<a href="articles/Cronjobs.html"> Cronjobs </a>
<a href="articles/On Logging.html"> On Logging </a>
</article><article>
<a href="articles/Every Programmer Should Watch Conference Talks on YouTube.html"> Every Programmer Should Watch Conference Talks on YouTube </a>
<a href="articles/readme.html"> readme </a>
</article><article>
<a href="articles/Debugging C++ Programs with GDB.html"> Debugging C++ Programs with GDB </a>
</article><article>
<a href="articles/image.html"> image </a>
</article><article>
<a href="articles/Makefiles:).html"> Makefiles:) </a>
</article>
</section>
</body>
Expand Down
18 changes: 15 additions & 3 deletions src/consolidate_into_homepage.rs
Original file line number Diff line number Diff line change
@@ -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<String> = 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!(
"<!DOCTYPE html>
Expand Down
2 changes: 2 additions & 0 deletions src/file_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ pub fn content_directory_files() -> Vec<PathBuf> {
.collect();
paths
}
/*
pub fn read_directory_content() -> Vec<String> {
let mut article_names: Vec<String> = vec![];
let paths_result = fs::read_dir("content");
Expand Down Expand Up @@ -54,6 +55,7 @@ pub fn read_directory_content() -> Vec<String> {
article_names.reverse();
article_names
}
*/

pub fn time_of_creation(path: String) -> SystemTime {
let time: SystemTime = SystemTime::now();
Expand Down
26 changes: 10 additions & 16 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
/*
Expand Down Expand Up @@ -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
Expand All @@ -80,6 +82,7 @@ fn main() {
} else {
render_all(&user_config);
}
sleep(Duration::from_secs(1));
}
}

Expand All @@ -88,26 +91,17 @@ fn render_some(user_config: &UserConfig, files_changed: &Vec<PathBuf>) {
// 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<String> = 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)
}
}
});
Expand All @@ -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)
Expand All @@ -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)
}
}
});
Expand Down
14 changes: 8 additions & 6 deletions src/parse_one_article.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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(())
}
Expand Down

0 comments on commit eb00648

Please sign in to comment.