Static site generator + my presonnal website written in rust for some reason.

rewrite to be impromptu Saait

Changed files
+74 -12
posts
src
+1 -1
Cargo.toml
···
[dependencies]
askama = { version = "0.12.1" }
-
comrak = "0.27.0"
+
comrak = { version = "0.27.0", features = ["syntect"] }
markdown-parser = "0.1.2"
rand = "0.8.5"
serde = { version = "1.0.209", features = ["derive"] }
+67 -5
posts/005-regenesis.md
···
[theprimeagen](https://www.youtube.com/watch?v=rcZSOLAI1lM), and everpresent desire to rewrite everything in Rust,
the new website is a complete rewrite using rust and adjacent techniques.
-
Using only
+
Using only
```
[dependencies]
askama = { version = "0.12.1", features = ["with-axum"] }
···
tokio = { version = "1.39.3", features = ["macros", "rt-multi-thread"] }
tower-http = { version = "0.5.2", features = ["fs"] }
```
+
as dependencies in the end we get a clean~ish, 2.8MB executable.
+
+
All markdown compilation gets done every time page is loaded, which is sub-optimal,
+
But reading time for all posts is non-significant compared to other loading times.
+
+
And voila, there is the new post.
+
+
## Update
+
+
This approach however had few issues.
+
As fun as it is writing your own routing logic, It feels purely unnecessary.
+
+
Even scaling down from `axum` to `tiny_http`, it doesn't change the binary size, and because of the limited resources and location of the VPS,
+
it does not affect the load times.
+
+
Short of rewriting it all in [Yew](yew.rs) and loading the wasm as a SPA (which comes with it's own complexity) loading times would not improve.
+
+
Therefore the goal has been slightly changed.
+
From serving the files the goal is now using askama like a sort of static site generator.
+
+
# DIY Hugo?
+
+
Not exactly. In the current state it is basically Saait again, but with extra steps.
+
Additional pages require source code intervention, which isn't hard, but tidious.
+
+
//TODO: use some enum for pages, with derive as EnumString, so new pages can be added simply by adding a template.
+
+
+
But for now, the new dependencies now look like this:
+
+
```toml
+
[dependencies]
+
askama = { version = "0.12.1" }
+
comrak = "0.27.0"
+
markdown-parser = "0.1.2"
+
rand = "0.8.5"
+
serde = { version = "1.0.209", features = ["derive"] }
+
serde_yaml = "0.9.34"
+
syntect = "5.2.0"
+
```
+
+
Syntect providing oh so nice code highlighting in the markdown.
+
```json
{
···
}
```
-
as dependancies in the end we get a clean~ish, 2.8MB executable.
+
```rust
+
+
std::fs::write(format!("{output_path}/index.html"), handlers::index().as_bytes()).expect("Couldnt write index file");
+
std::fs::write(format!("{output_path}/about.html"), handlers::about().as_bytes()).expect("Couldnt write about file");
+
std::fs::write(format!("{output_path}/404.html"), handlers::not_found().as_bytes()).expect("Couldnt write 404 file");
-
All markdown compilation gets done every time page is loaded, which is sub-optimal,
-
But reading time for all posts is non-significant compared to other loading times.
-
And voila, there is the new post.
+
for entry in post_dir_iter {
+
if let Ok(entry) = entry {
+
+
let filename = entry.file_name().into_string().unwrap().split(".").collect::<Vec<_>>()[0].to_string();
+
+
fs::write(format!("{output_path}/blog/{filename}.html"), handlers::blog(filename).as_bytes()).expect("Couldnt write blog entry");
+
};
+
+
}
+
+
```
+
+
For now, I am rather happy with the result.
+
+
Built for release profile, binary is just 3.1M (majority of it is syntact), and produces a output folder with it's contents in a rather pleasant amount of time.
+
> ./target/release/rusty_duck 0.03s user 0.01s system 97% cpu 0.035 total
+
+
This is no **BLAZING** speed, but it's honest work.
+1 -1
src/handlers.rs
···
options.extension.strikethrough = true;
let mut plugins = comrak::Plugins::default();
let adapter = comrak::plugins::syntect::SyntectAdapterBuilder::new()
-
.theme("base16-ocean.dark")
+
.theme("base16-mocha.dark")
.build();
plugins.render.codefence_syntax_highlighter = Some(&adapter);
+5 -5
src/main.rs
···
-
use std::{fs::{self, read_dir, DirBuilder},path::Path};
+
use std::{fs::{write, read_dir, DirBuilder},path::Path};
mod handlers;
mod structs;
···
-
fs::write(format!("{output_path}/index.html"), handlers::index().as_bytes()).expect("Couldnt write index file");
-
fs::write(format!("{output_path}/about.html"), handlers::about().as_bytes()).expect("Couldnt write about file");
-
fs::write(format!("{output_path}/404.html"), handlers::not_found().as_bytes()).expect("Couldnt write 404 file");
+
write(format!("{output_path}/index.html"), handlers::index().as_bytes()).expect("Couldnt write index file");
+
write(format!("{output_path}/about.html"), handlers::about().as_bytes()).expect("Couldnt write about file");
+
write(format!("{output_path}/404.html"), handlers::not_found().as_bytes()).expect("Couldnt write 404 file");
match DirBuilder::new()
.create(format!("{output_path}/blog")) {
···
let filename = entry.file_name().into_string().unwrap().split(".").collect::<Vec<_>>()[0].to_string();
-
fs::write(format!("{output_path}/blog/{filename}.html"), handlers::blog(filename).as_bytes()).expect("Couldnt write blog entry");
+
write(format!("{output_path}/blog/{filename}.html"), handlers::blog(filename).as_bytes()).expect("Couldnt write blog entry");
};
}