diff --git a/Cargo.lock b/Cargo.lock index bc2460c..6b50b89 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2,24 +2,12 @@ # It is not intended for manual editing. version = 3 -[[package]] -name = "bitflags" -version = "1.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" - [[package]] name = "bitflags" version = "2.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cf4b9d6a944f767f8e5e0db018570623c85f3d925ac718db4e06d0187adb21c1" -[[package]] -name = "cfg-if" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" - [[package]] name = "console" version = "0.15.8" @@ -30,16 +18,7 @@ dependencies = [ "lazy_static", "libc", "unicode-width", - "windows-sys 0.52.0", -] - -[[package]] -name = "crossbeam-channel" -version = "0.5.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ab3db02a9c5b5121e1e42fbdb1aeb65f5e02624cc58c43f2884c6ccac0b82f95" -dependencies = [ - "crossbeam-utils", + "windows-sys", ] [[package]] @@ -85,27 +64,6 @@ version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" -[[package]] -name = "filetime" -version = "0.2.23" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1ee447700ac8aa0b2f2bd7bc4462ad686ba06baa6727ac149a2d6277f0d240fd" -dependencies = [ - "cfg-if", - "libc", - "redox_syscall", - "windows-sys 0.52.0", -] - -[[package]] -name = "fsevent-sys" -version = "4.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "76ee7a02da4d231650c7cea31349b889be2f45ddb3ef3032d2ec8185f6313fd2" -dependencies = [ - "libc", -] - [[package]] name = "getopts" version = "0.2.21" @@ -131,46 +89,6 @@ dependencies = [ "hashbrown", ] -[[package]] -name = "inotify" -version = "0.9.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f8069d3ec154eb856955c1c0fbffefbf5f3c40a104ec912d4797314c1801abff" -dependencies = [ - "bitflags 1.3.2", - "inotify-sys", - "libc", -] - -[[package]] -name = "inotify-sys" -version = "0.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e05c02b5e89bff3b946cedeca278abc628fe811e604f027c45a8aa3cf793d0eb" -dependencies = [ - "libc", -] - -[[package]] -name = "kqueue" -version = "1.0.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7447f1ca1b7b563588a205fe93dea8df60fd981423a768bc1c0ded35ed147d0c" -dependencies = [ - "kqueue-sys", - "libc", -] - -[[package]] -name = "kqueue-sys" -version = "1.0.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ed9625ffda8729b85e45cf04090035ac368927b8cebc34898e7c120f52e4838b" -dependencies = [ - "bitflags 1.3.2", - "libc", -] - [[package]] name = "lazy_static" version = "1.4.0" @@ -183,12 +101,6 @@ version = "0.2.154" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ae743338b92ff9146ce83992f766a31066a91a8c84a45e0e9f21e7cf6de6d346" -[[package]] -name = "log" -version = "0.4.21" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "90ed8c1e510134f979dbc4f070f87d4313098b704861a105fe34231c70a3901c" - [[package]] name = "memchr" version = "2.7.2" @@ -196,42 +108,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6c8640c5d730cb13ebd907d8d04b52f55ac9a2eec55b440c8892f40d56c76c1d" [[package]] -name = "mio" -version = "0.8.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a4a650543ca06a924e8b371db273b2756685faae30f8487da1b56505a8f78b0c" -dependencies = [ - "libc", - "log", - "wasi", - "windows-sys 0.48.0", -] - -[[package]] -name = "notify" -version = "6.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6205bd8bb1e454ad2e27422015fb5e4f2bcc7e08fa8f27058670d208324a4d2d" -dependencies = [ - "bitflags 2.5.0", - "crossbeam-channel", - "filetime", - "fsevent-sys", - "inotify", - "kqueue", - "libc", - "log", - "mio", - "walkdir", - "windows-sys 0.48.0", -] - -[[package]] -name = "pond-ssg" +name = "pond_ssg" version = "0.1.0" dependencies = [ "console", - "notify", "pulldown-cmark", "rayon", "serde", @@ -253,7 +133,7 @@ version = "0.9.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "57206b407293d2bcd3af849ce869d52068623f19e1b5ff8e8778e3309439682b" dependencies = [ - "bitflags 2.5.0", + "bitflags", "getopts", "memchr", "unicase", @@ -288,24 +168,6 @@ dependencies = [ "crossbeam-utils", ] -[[package]] -name = "redox_syscall" -version = "0.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4722d768eff46b75989dd134e5c353f0d6296e5aaa3132e776cbdb56be7731aa" -dependencies = [ - "bitflags 1.3.2", -] - -[[package]] -name = "same-file" -version = "1.0.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "93fc1dc3aaa9bfed95e02e6eadabb4baf7e3078b0bd1b4d7b6b0b68378900502" -dependencies = [ - "winapi-util", -] - [[package]] name = "serde" version = "1.0.201" @@ -407,62 +269,13 @@ version = "0.9.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" -[[package]] -name = "walkdir" -version = "2.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "29790946404f91d9c5d06f9874efddea1dc06c5efe94541a7d6863108e3a5e4b" -dependencies = [ - "same-file", - "winapi-util", -] - -[[package]] -name = "wasi" -version = "0.11.0+wasi-snapshot-preview1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" - -[[package]] -name = "winapi-util" -version = "0.1.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4d4cc384e1e73b93bafa6fb4f1df8c41695c8a91cf9c4c64358067d15a7b6c6b" -dependencies = [ - "windows-sys 0.52.0", -] - -[[package]] -name = "windows-sys" -version = "0.48.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" -dependencies = [ - "windows-targets 0.48.5", -] - [[package]] name = "windows-sys" version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" dependencies = [ - "windows-targets 0.52.5", -] - -[[package]] -name = "windows-targets" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" -dependencies = [ - "windows_aarch64_gnullvm 0.48.5", - "windows_aarch64_msvc 0.48.5", - "windows_i686_gnu 0.48.5", - "windows_i686_msvc 0.48.5", - "windows_x86_64_gnu 0.48.5", - "windows_x86_64_gnullvm 0.48.5", - "windows_x86_64_msvc 0.48.5", + "windows-targets", ] [[package]] @@ -471,46 +284,28 @@ version = "0.52.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6f0713a46559409d202e70e28227288446bf7841d3211583a4b53e3f6d96e7eb" dependencies = [ - "windows_aarch64_gnullvm 0.52.5", - "windows_aarch64_msvc 0.52.5", - "windows_i686_gnu 0.52.5", + "windows_aarch64_gnullvm", + "windows_aarch64_msvc", + "windows_i686_gnu", "windows_i686_gnullvm", - "windows_i686_msvc 0.52.5", - "windows_x86_64_gnu 0.52.5", - "windows_x86_64_gnullvm 0.52.5", - "windows_x86_64_msvc 0.52.5", + "windows_i686_msvc", + "windows_x86_64_gnu", + "windows_x86_64_gnullvm", + "windows_x86_64_msvc", ] -[[package]] -name = "windows_aarch64_gnullvm" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" - [[package]] name = "windows_aarch64_gnullvm" version = "0.52.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7088eed71e8b8dda258ecc8bac5fb1153c5cffaf2578fc8ff5d61e23578d3263" -[[package]] -name = "windows_aarch64_msvc" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" - [[package]] name = "windows_aarch64_msvc" version = "0.52.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9985fd1504e250c615ca5f281c3f7a6da76213ebd5ccc9561496568a2752afb6" -[[package]] -name = "windows_i686_gnu" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" - [[package]] name = "windows_i686_gnu" version = "0.52.5" @@ -523,48 +318,24 @@ version = "0.52.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "87f4261229030a858f36b459e748ae97545d6f1ec60e5e0d6a3d32e0dc232ee9" -[[package]] -name = "windows_i686_msvc" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" - [[package]] name = "windows_i686_msvc" version = "0.52.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "db3c2bf3d13d5b658be73463284eaf12830ac9a26a90c717b7f771dfe97487bf" -[[package]] -name = "windows_x86_64_gnu" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" - [[package]] name = "windows_x86_64_gnu" version = "0.52.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4e4246f76bdeff09eb48875a0fd3e2af6aada79d409d33011886d3e1581517d9" -[[package]] -name = "windows_x86_64_gnullvm" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" - [[package]] name = "windows_x86_64_gnullvm" version = "0.52.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "852298e482cd67c356ddd9570386e2862b5673c85bd5f88df9ab6802b334c596" -[[package]] -name = "windows_x86_64_msvc" -version = "0.48.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" - [[package]] name = "windows_x86_64_msvc" version = "0.52.5" diff --git a/Cargo.toml b/Cargo.toml index b684ce3..2727517 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "pond-ssg" +name = "pond_ssg" version = "0.1.0" edition = "2021" @@ -7,7 +7,6 @@ edition = "2021" [dependencies] console = "0.15.8" -notify = "6.1.1" pulldown-cmark = "0.9.3" rayon = "1.10.0" serde = { version="1.0.196", features = ["derive"] } diff --git a/content/deletethis.md b/content/deletethis.md new file mode 100644 index 0000000..84f2c5b --- /dev/null +++ b/content/deletethis.md @@ -0,0 +1,6 @@ +we can go over this +we can move back + +meww + + diff --git a/content/newest_blog.md b/content/newest_blog.md new file mode 100644 index 0000000..ceaa08f --- /dev/null +++ b/content/newest_blog.md @@ -0,0 +1,7 @@ +we can see that this is the one on top! +--- +we can go over this +we can move back this way +you can give some help for me + + diff --git a/dist/FiraMono-Regular.ttf b/dist/FiraMono-Regular.ttf deleted file mode 100644 index 67bbd42..0000000 Binary files a/dist/FiraMono-Regular.ttf and /dev/null differ diff --git a/dist/articles/deletethis.html b/dist/articles/deletethis.html new file mode 100644 index 0000000..a3ac6dd --- /dev/null +++ b/dist/articles/deletethis.html @@ -0,0 +1,18 @@ + + + + + + + deletethis + + +home +

deletethis

+
+

we can go over this +we can move back

+

meww

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

newest_blog

+
+

we can see that this is the one on top!

+

we can go over this
+we can move back this way +you can give some help for me

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

diff --git a/readme.md b/readme.md index ca3c648..a240311 100644 --- a/readme.md +++ b/readme.md @@ -18,3 +18,9 @@ state? - maintaing an internal state could be useful in some cases but using the content folder as the single source of truth is very powerful - FEATURE IDEA -> a period '.' in front of the filename for drafts or hidden articles +deploying +currently using a github workflow to deploy on push +should write a script to set up a web server, install pond +then you can ssh into your vpc and write +or can i use ftp just to send the new blogs + diff --git a/src/consolidate_into_homepage.rs b/src/consolidate_into_homepage.rs index eb49f62..5247036 100644 --- a/src/consolidate_into_homepage.rs +++ b/src/consolidate_into_homepage.rs @@ -1,5 +1,5 @@ use super::config; -use crate::utils::read_directory_content; +use crate::file_utils::read_directory_content; use std::fs::File; use std::io::Write; diff --git a/src/utils.rs b/src/file_utils.rs similarity index 88% rename from src/utils.rs rename to src/file_utils.rs index 61dca70..ba1bb83 100644 --- a/src/utils.rs +++ b/src/file_utils.rs @@ -1,7 +1,6 @@ use std::collections::HashMap; use std::env; use std::fs; -use std::fs::metadata; use std::fs::ReadDir; use std::io::Error; use std::path::PathBuf; @@ -51,9 +50,21 @@ pub fn read_directory_content() -> Vec { eprintln!("Error reading directory: {}", err); } }; + article_names.sort_by_key(|k| time_of_creation(format!("content/{k}.md"))); + article_names.reverse(); article_names } +pub fn time_of_creation(path: String) -> SystemTime { + let time: SystemTime = SystemTime::now(); + match fs::metadata(path) { + Ok(data) => data + .created() + .expect("chrnological sorting not supported on this platform"), + Err(_) => time, + } +} + pub fn files_changed(latest_change_times: &mut HashMap) -> Vec { let individual_files = content_directory_files(); @@ -138,3 +149,14 @@ pub fn delete_dir_contents(read_dir_res: Result) { }; println!("successfully removed previous content"); } + +// unit tests +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn test_has_content_dir() { + assert_eq!(has_content_dir(), true); + } +} diff --git a/src/main.rs b/src/main.rs index 4dbdf0c..aee4b58 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,7 +1,7 @@ pub mod config; pub mod consolidate_into_homepage; +pub mod file_utils; pub mod parse_one_article; -pub mod utils; use config::UserConfig; use console::Term; @@ -12,6 +12,13 @@ use std::path::PathBuf; use std::time::SystemTime; fn main() { + /* + * CHECK FOR THIS + unsuccesful parse for parsing - image2 + deletethis.md~ No such file or directoryparsing - moo + (os error 2) + parsing - On Logging + */ let term = Term::stdout(); let _ = term.clear_screen(); let _ = term.write_line( @@ -25,7 +32,7 @@ fn main() { ); let _ = term.write_line(" A simple cli tool to convert markdown to blog"); - if utils::has_content_dir() { + if file_utils::has_content_dir() { println!("content/ found"); } else { println!("kindly make a content/ directory"); @@ -38,7 +45,7 @@ fn main() { // setting intial time for watching changes let mut folder_level_change_time = SystemTime::now(); - let individual_files = utils::content_directory_files(); + let individual_files = file_utils::content_directory_files(); let mut file_level_change_times: HashMap = individual_files .into_iter() .filter_map(|path| { @@ -57,8 +64,15 @@ fn main() { // 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 loop { - if utils::no_folder_level_changes(&mut folder_level_change_time) { - let files_changed = utils::files_changed(&mut file_level_change_times); + /* + let files_changed = file_utils::files_changed(&mut file_level_change_times); + if files_changed.is_empty() { + continue; + } + render_some(&user_config, &files_changed); + */ + if file_utils::no_folder_level_changes(&mut folder_level_change_time) { + let files_changed = file_utils::files_changed(&mut file_level_change_times); if files_changed.is_empty() { continue; } @@ -78,21 +92,25 @@ fn render_some(user_config: &UserConfig, files_changed: &Vec) { .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| { let user_config_for_threads = user_config.clone(); match parse_one_article::markdown_to_styled_html(&article_name, &user_config_for_threads) { Ok(_) => { - println!("1 succesful parse for {article_name}") + println!("succesful parse for {article_name}") } Err(e) => { - eprintln!("1 unsuccesful parse for {article_name}: {}", e) + eprintln!(" unsuccesful parse for {article_name}: {}", e) } } }); - println!("generated all blogs"); match consolidate_into_homepage::create_homepage(&user_config) { Ok(_) => { @@ -105,11 +123,13 @@ fn render_some(user_config: &UserConfig, files_changed: &Vec) { } fn render_all(user_config: &UserConfig) { + println!("RENDERING ALL"); + println!("---"); // remove previous content (clean) let article_dir = fs::read_dir("dist/articles"); - utils::delete_dir_contents(article_dir); + file_utils::delete_dir_contents(article_dir); - let article_names = utils::read_directory_content(); + let article_names = file_utils::read_directory_content(); // println!("{:?}", article_names); // rebuilding all the articles in content directory (parallely) diff --git a/src/parse_one_article.rs b/src/parse_one_article.rs index bb16b89..9dd4741 100644 --- a/src/parse_one_article.rs +++ b/src/parse_one_article.rs @@ -63,3 +63,16 @@ pub fn markdown_to_styled_html( write!(file, "{wrapped_html}")?; Ok(()) } + +// unit tests +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn test_parse_markdown() { + let markdown_input = "# moon"; + let html_output = parse_markdown(&markdown_input); + assert_eq!(html_output, "

moon

\n"); + } +}