3 ms·
This is mindblowing synchronicity. I thought this article was one I had read this weekend for a second but checked the post date and saw it wasn't available yes
by annowiki 4y ago
This is mindblowing synchronicity. I thought this article was one I had read this weekend for a second but checked the post date and saw it wasn't available yesterday.
I'm working on trying to write a static site generator for my own personal site/blog in C++, been tinkering for a couple months. It started as a passion project in tribute to my dog that passed. GatsbyJS wasn't working (again) which is what my current site is built with, so I just said screw it, I'll write my own. Chose C to begin with and quickly gave up. Decided to switch to C++ because its what I'm supposed to be learning for work.
I named it bluesky, after my dog that passed, Sky Blue. https://github.com/mas-4/bluesky https://github.com/mas-4/bluesky
Templating is a lot harder than I had initially thought. I wanted the templating system to be as bare bones as possible, similar to another static site generator I rather like, sergey[0]. Most of these articles I found ([1], [2]) about writing your own SSG don't go into templating much, they just use an off the shelf library. Inja[3] is available for C++ but, like I said, I want something really bare bones, like if you were designing html now, you'd obviously include html-includes and html-templates. I finally got it working for includes and templates, now I have to add the markdown support, and then I plan on migrating my personal site to using it.
[0]: https://sergey.cool/ https://sergey.cool/
[1]: https://www.smashingmagazine.com/2020/09/stack-custom-made-static-site-generator/ https://www.smashingmagazine.com/2020/09/stack-custom-made-s...
[2]: https://blog.hamaluik.ca/posts/build-your-own-static-site-generator/ https://blog.hamaluik.ca/posts/build-your-own-static-site-ge...
[3]: https://github.com/pantor/inja https://github.com/pantor/inja
edit: a link
- brundolf 4y agoI've found you don't actually need a templating system, you just need format-strings. Write your rendering logic with normal code that just spits out a string Templating languages probably help with performance a bit when you're rendering at request-time, but for static stuff I don't really see much point I've got a hand-rolled static site generator in JavaScript that just uses template strings. I only have around 30 pages, to be fair, but when I make a change it re-generates the whole site before I can even alt-tab and reload the page. I assume a C++ version could be much faster
- tomjakubowski 4y agoOne great benefit of a good template language is automatic escaping (e.g. within HTML attributes or tags), which you won't get from format strings.
- brundolf 4y agoIs that important in a static site generator? In a server-rendered site you have to worry about injection attacks, but that's not really relevant when you're statically generating a site from content that's fully under your control
- ordu 4y agoBut then you'll need to watch for `<script>` in examples of your articles, so you dont need to write it as `<script>`. And how you are going to get the second in your blog? How do you like to write `&lt;script&gt;`? It is very convenient to have an automatic escaping of everything.
- brundolf 4y agoDepends on the site I guess. My actual blog content is written in Markdown, which already handles escaping stuff between backticks, and that's the only place I'm likely to run into that sort of thing
- frozencell 4y agoSorry for your loss.
- lionkor 4y agoWhats the loss..?
- checkyoursudo 4y agoProbably the dog that was mentioned.