From f2e9ce3826e9fb833e17907ea2a611750b4b2e2b Mon Sep 17 00:00:00 2001 From: Joshua Mo Date: Wed, 15 Nov 2023 15:33:59 +0000 Subject: [PATCH] fix: backlinking --- _blog/2023-11-15-ssg-in-rust.mdx | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/_blog/2023-11-15-ssg-in-rust.mdx b/_blog/2023-11-15-ssg-in-rust.mdx index 0e6cab12..65502252 100644 --- a/_blog/2023-11-15-ssg-in-rust.mdx +++ b/_blog/2023-11-15-ssg-in-rust.mdx @@ -1,5 +1,5 @@ --- -title: "Building and Deploying A Static Site Generator with Rust in one hour" +title: "Building and Deploying A Static Site Generator" description: This article documents how someone built and deployed a static site generator using Rust in an hour, converting Markdown to HTML as well as adding OG tag support and CSS. author: josh tags: [rust, static site generator, frontend, guide] @@ -7,9 +7,7 @@ thumb: ssg-in-rust-thumb.png cover: ssg-in-rust-thumb.png date: '2023-11-15T14:30:00' --- -Rust has always been seen from the outside as a language that takes quite a long time to write something in. While that might be true for more things involving more advanced type machinery (implementing your own job queues, implementing async traits manually, lifetimes), for a lot of things that don't require things that amount to mental space rocketry you can knock out a project surprisingly quickly. I want to challenge the assumption that Rust is a slow language to program in by writing a usable, extendable web service in an hour that also provides immediate value to anyone who would also like to use it. - -We'll be making a website in the form of a Rust static site generator that we'll be able to add our own pages to. If you want to see the final result so you can deploy it straight to Shuttle, you can follow the instructions below: +We'll be making a website in the form of a Rust static site generator that we'll be able to add our own pages to. If you want to skip straight to the project, deploy your own instance and try it out, you can follow the instructions below: 1) Run `cargo shuttle init --from joshua-mo-143/shuttle-ssg` and follow the prompt 2) `cd` to the folder @@ -17,6 +15,8 @@ We'll be making a website in the form of a Rust static site generator that we'll Don't forget to make sure that `cargo-shuttle` is installed and that you're logged in! You can also visit the repo [here.](https://www.github.com/joshua-mo-143/shuttle-ssg) +Rust has always been seen from the outside as a language that takes quite a long time to write something in. While that might be true for more things involving more advanced type machinery (implementing your own job queues, implementing async traits manually, lifetimes), for a lot of things that don't require things that amount to mental space rocketry you can knock out a project surprisingly quickly. I want to challenge the assumption that Rust is a slow language to program in by writing a usable, extendable web service in an hour that also provides immediate value to anyone who would also like to use it. + ## 59:59 - Getting Started It's time to lock in. I went on Youtube and put on a breakcore playlist, then used `cargo shuttle init --template axum` to quickly spin up what I wanted. I used the project name `ssg` and put it in my projects folder, then got to work. What helps me move quickly is that with Shuttle I don't need a Dockerfile; I just use the runtime, provision the things I need and I'm ready to get cracking. @@ -30,7 +30,7 @@ This lets Shuttle know where we keep all of our files so that when we deploy, it Anyway, onto the next part! ## 59:39 - Adding basic functionality -I knew initially from previous experience that you can use `pulldown-cmark` to turn Markdown to HTML, so I quickly added it using `cargo add pulldown-cmark`. I remember that they had an example on their GitHub repo for parsing Markdown, so I grabbed it and quickly threw it in a handler function: +I knew initially from previous experience that you can use [`pulldown-cmark`](https://github.com/raphlinus/pulldown-cmark) to turn Markdown to HTML, so I quickly added it using `cargo add pulldown-cmark`. I remember that they had an example on their GitHub repo for parsing Markdown, so I grabbed it and quickly threw it in a handler function: ```rust // src/main.rs async fn parser(State(state): State, Path(page): Path) -> impl IntoResponse { @@ -77,7 +77,7 @@ body { ``` As you can see, it's not quite [Awwwards](https://www.awwwards.com)-worthy CSS. However, it'll do for making our pages look at least somewhat aligned. -Then I added a handler function to send the CSS text as a response. I struggled with it for a few minutes by trying to set the response type to `Response` and using `cargo clippy` before remembering that I needed to set it as `impl IntoResponse`: +Then I added a handler function to send the CSS text as a response. I struggled with it for a few minutes by trying to set the response type to [`axum::response::Response`](https://docs.rs/axum/latest/axum/response/type.Response.html) and using `cargo clippy` before remembering that I needed to set it as `impl IntoResponse`: ```rust // src/main.rs async fn styles() -> impl IntoResponse { @@ -97,9 +97,9 @@ html_output.push_str(r#"); ```