2024-04-01 19:05:53 +02:00
|
|
|
use std::fs::read_to_string;
|
|
|
|
mod config;
|
2024-04-02 21:48:02 +02:00
|
|
|
mod emoji;
|
2024-04-06 21:39:27 +02:00
|
|
|
mod index;
|
2024-04-01 19:05:53 +02:00
|
|
|
use mlem::*;
|
2024-03-31 20:08:43 +02:00
|
|
|
fn main() {
|
2024-04-01 19:05:53 +02:00
|
|
|
let config = config::read_config();
|
|
|
|
let raw_files = read_src_files(&config.src_dir);
|
2024-04-06 21:39:27 +02:00
|
|
|
let mut post_index: Vec<index::BlogPost> = Vec::new();
|
|
|
|
|
2024-04-01 19:05:53 +02:00
|
|
|
for file in raw_files {
|
2024-04-02 21:48:02 +02:00
|
|
|
let mut markdown = read_to_string(file.path).expect("File does not exist");
|
|
|
|
markdown = emoji::emoji_pass(
|
|
|
|
&markdown,
|
|
|
|
&config.emoji_web_directory,
|
|
|
|
&config.emoji_local_directory,
|
|
|
|
);
|
2024-04-06 21:39:27 +02:00
|
|
|
|
|
|
|
let (html, index_content) = generate_blog_entry(markdown, &config.templates_dir);
|
2024-04-02 21:48:02 +02:00
|
|
|
write_to_fs(
|
|
|
|
html,
|
|
|
|
&config.output_dir,
|
2024-04-06 21:39:27 +02:00
|
|
|
&file.file_name.clone().into_string().unwrap(),
|
2024-04-02 21:48:02 +02:00
|
|
|
);
|
2024-04-06 21:39:27 +02:00
|
|
|
|
|
|
|
post_index.push(index::BlogPost::new(
|
|
|
|
file.title,
|
|
|
|
file.date.format("%Y-%m-%d").to_string(),
|
|
|
|
file.date.timestamp(),
|
|
|
|
index_content,
|
|
|
|
format!("{}.html", file.file_name.to_str().unwrap()),
|
|
|
|
));
|
2024-03-31 20:08:43 +02:00
|
|
|
}
|
2024-04-06 21:39:27 +02:00
|
|
|
let index = index::generate(post_index, &config.templates_dir);
|
|
|
|
|
|
|
|
std::fs::write(format!("{}/index.html", config.output_dir), index)
|
|
|
|
.unwrap_or_else(|_| panic!("Error writing index"));
|
2024-03-31 20:08:43 +02:00
|
|
|
}
|