2024-08-29 15:04:04 +00:00
---
title: Full website Re-Update
date: 2024-08-29
---
## New Website?
### Rust
The time has come and another re-write is upon us.
This time inspied by [this article ](https://blog.transrights.art/blogs/2024_Screw-Frameworks-New-Site-2 ),
[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.
2024-08-31 19:56:15 +00:00
Using only
2024-08-29 15:04:04 +00:00
```
[dependencies]
askama = { version = "0.12.1", features = ["with-axum"] }
askama_axum = "0.4.0"
axum = "0.7.5"
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"
tokio = { version = "1.39.3", features = ["macros", "rt-multi-thread"] }
tower-http = { version = "0.5.2", features = ["fs"] }
```
2024-08-31 19:56:15 +00:00
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.
2024-08-29 15:04:04 +00:00
2024-08-31 17:20:05 +00:00
```json
{
"firstName": "John",
"lastName": "Smith",
"age": 25
}
```
2024-08-31 19:56:15 +00:00
```rust
2024-08-29 15:04:04 +00:00
2024-08-31 19:56:15 +00:00
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");
2024-08-29 15:04:04 +00:00
2024-08-31 19:56:15 +00:00
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.
2024-08-29 15:04:04 +00:00