How to create a static site generator with Rust

Does anyone know of any tutorial or reference on how I could create a static website generator with Rust? It doesn't necessarily have to be a tutorial, but something that tells me what I need to develop and research.
I know there is Zola and others, but I am a beginner and it is for learning reasons.
Thanks in advance.

Do you want to code your own template engine, or build your static site generator from existing components?
Maybe have a look at Tera: https://tera.netlify.com/docs/#usage, the template engine that Zola uses.
Other SSG written in Rust: mdBook and cobalt.rs

Thanks for answering.
I want to build the SSG based on existing components. Do the necessary components already exist in the language or would I have to do something from scratch? Is there a list of what it takes to do an SSG?

Reading through the Cobalt docs could be a good place to start:

https://cobalt-org.github.io/docs/

1 Like

Some crates to build a SSG:

  1. Markdown parser

    • pulldown
  2. HTML template engine

    • tera
    • handlebars
    • liquid
  3. HTTP server

    • watch file system using notify
    • live reload using WebSockets ws
    • static files server: actix-files or iron+staticfile
  4. Configuration file with metadata and build settings

    • toml
2 Likes

As someone who have built a static site generator in Rust, many of the required components already exist in the Rust ecosystem.

My only real problem was that there weren't any templating engine that both

  • Had a lightweight dependency tree
  • Worked on runtime, not compile time

So I had to hack on something tiny for my use case.

Also, I would recommend you to check out the source of my SSG, particularly the "tools", since I believe I have seperated the neccesary steps enough for you to just see how a particular step works in something that sorta works.


Also, a static site generator isn't something difficult, if you don't have any need for Markdown or something, you could just write some HTML, and use cat to wrap it in a page template and be done with it.

1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.