···12121313[dependencies]
1414askama = { version = "0.12.1" }
1515-comrak = "0.27.0"
1515+comrak = { version = "0.27.0", features = ["syntect"] }
1616markdown-parser = "0.1.2"
1717rand = "0.8.5"
1818serde = { version = "1.0.209", features = ["derive"] }
+67-5
posts/005-regenesis.md
···1212[theprimeagen](https://www.youtube.com/watch?v=rcZSOLAI1lM), and everpresent desire to rewrite everything in Rust,
1313the new website is a complete rewrite using rust and adjacent techniques.
14141515-Using only
1515+Using only
1616```
1717[dependencies]
1818askama = { version = "0.12.1", features = ["with-axum"] }
···2626tokio = { version = "1.39.3", features = ["macros", "rt-multi-thread"] }
2727tower-http = { version = "0.5.2", features = ["fs"] }
2828```
2929+as dependencies in the end we get a clean~ish, 2.8MB executable.
3030+3131+All markdown compilation gets done every time page is loaded, which is sub-optimal,
3232+But reading time for all posts is non-significant compared to other loading times.
3333+3434+And voila, there is the new post.
3535+3636+## Update
3737+3838+This approach however had few issues.
3939+As fun as it is writing your own routing logic, It feels purely unnecessary.
4040+4141+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,
4242+it does not affect the load times.
4343+4444+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.
4545+4646+Therefore the goal has been slightly changed.
4747+From serving the files the goal is now using askama like a sort of static site generator.
4848+4949+# DIY Hugo?
5050+5151+Not exactly. In the current state it is basically Saait again, but with extra steps.
5252+Additional pages require source code intervention, which isn't hard, but tidious.
5353+5454+//TODO: use some enum for pages, with derive as EnumString, so new pages can be added simply by adding a template.
5555+5656+5757+But for now, the new dependencies now look like this:
5858+5959+```toml
6060+[dependencies]
6161+askama = { version = "0.12.1" }
6262+comrak = "0.27.0"
6363+markdown-parser = "0.1.2"
6464+rand = "0.8.5"
6565+serde = { version = "1.0.209", features = ["derive"] }
6666+serde_yaml = "0.9.34"
6767+syntect = "5.2.0"
6868+```
6969+7070+Syntect providing oh so nice code highlighting in the markdown.
7171+29723073```json
3174{
···3578}
3679```
37803838-as dependancies in the end we get a clean~ish, 2.8MB executable.
8181+```rust
8282+8383+std::fs::write(format!("{output_path}/index.html"), handlers::index().as_bytes()).expect("Couldnt write index file");
8484+std::fs::write(format!("{output_path}/about.html"), handlers::about().as_bytes()).expect("Couldnt write about file");
8585+std::fs::write(format!("{output_path}/404.html"), handlers::not_found().as_bytes()).expect("Couldnt write 404 file");
39864040-All markdown compilation gets done every time page is loaded, which is sub-optimal,
4141-But reading time for all posts is non-significant compared to other loading times.
42874343-And voila, there is the new post.
8888+for entry in post_dir_iter {
8989+ if let Ok(entry) = entry {
9090+9191+ let filename = entry.file_name().into_string().unwrap().split(".").collect::<Vec<_>>()[0].to_string();
9292+9393+ fs::write(format!("{output_path}/blog/{filename}.html"), handlers::blog(filename).as_bytes()).expect("Couldnt write blog entry");
9494+ };
9595+9696+}
9797+9898+```
9999+100100+For now, I am rather happy with the result.
101101+102102+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.
103103+> ./target/release/rusty_duck 0.03s user 0.01s system 97% cpu 0.035 total
104104+105105+This is no **BLAZING** speed, but it's honest work.
44106