4 ms·
I love the code [1]. Mine [2] is a bit over engineered because I wanted hot-reloading (without JS), and it was a delightful yak shave. But the basic idea is th
by adityaathalye 3y ago
I love the code [1]. Mine [2] is a bit over engineered because I wanted hot-reloading (without JS), and it was a delightful yak shave.
But the basic idea is the same --- heredocs for templating, using a plaintext -> html compiler (pandoc in my case), an intermediate CSV for index generation. Also some handy sed-fu [3] to lift out front matter. Classic :)
Very nice!
[1] https://github.com/karlb/karl.berlin/blob/master/blog.sh https://github.com/karlb/karl.berlin/blob/master/blog.sh
[2] https://github.com/adityaathalye/shite https://github.com/adityaathalye/shite
[3] I'm doing this: https://github.com/adityaathalye/shite/blob/master/bin/templating.sh#L34 https://github.com/adityaathalye/shite/blob/master/bin/templ...
case ${file_type} in
org )
# Multiline processing of org-style header/preamble syntax, boxed
# between begin/end markers we have defined. We use org-mode's own
# comment line syntax to write the begin/end markers.
# cf. https://orgmode.org/guide/Comment-Lines.html
sed -n -E \
-e '/^\#\s+shite_meta/I,/^\#\s+shite_meta/I{/\#\s+shite_meta.*/Id; s/^\#\+(\w+)\:\s+(.*)/\L\1\E,\2/Ip}'
;;
md )
# Multiline processing of Jekyll-style YAML front matter, boxed
# between `---` separators.
sed -n -E \
-e '/^\-{3,}/,/^\-{3,}/{/^\-{3,}.*/d; s/^(\w+)\:\s+(.*)/\L\1\E,\2/Ip}'
;;
html )
# Use HTML meta tags and parse them, according to this convention:
# <meta name="KEY" content="VALUE">
# cf. https://developer.mozilla.org/en-US/docs/Learn/HTML/Introduction_to_HTML/The_head_metadata_in_HTML
sed -n -E \
-e 's;^\s?<meta\s+name="?(\w+)"?\s+content="(.*)">;\L\1\E,\2;Ip'
;;
esac
- rcarmo 3y agoI found his GEMINI approach quite funny - it strips out most of the formatting with a regexp. There is a bit of a limitation, though - I organize posts by namespace and with the date in the URL, and make can’t really handle that directly.
- adityaathalye 3y agoHuh, I previously skim-read the code and didn't notice the GEMINI regex detail. I wonder why they're doing that. Re: namespace organisation. I thought about that a lot, and decided to adopt namespace-only convention for symmetry between text file layout, html file layout, and url scheme. I've treated Date/time as metadata, which I can use to organise index pages. If I get to years worth of posts, then I'll group them by year/month or something reasonable. Likewise tags. I debated tags _and_ categories. But I decided on "everything is a post with tags, and categories will emerge based on topical coverage + post format".
- karl42 3y ago> I found his GEMINI approach quite funny - it strips out most of the formatting with a regexp. Do you mean the regexp in https://github.com/karlb/karl.berlin/blob/master/blog.sh#L4 https://github.com/karlb/karl.berlin/blob/master/blog.sh#L4 ? It doesn't remove the formatting, just HTML comments (because they would show up on the page, otherwise) and rel="me" attributes (because they don't work with md2gemini). Feel free to read the blog post about adding Gemini support for more details: https://www.karl.berlin/gemini-blog.html https://www.karl.berlin/gemini-blog.html
- maccard 3y agoSeeing these sorts of scripts is exactly why we don't write our own, and use something like esbuild and vite.
- adityaathalye 3y agoWell, I have my reasons and you have yours! For example, A) Most importantly, I wanted to tinker and have fun! B) I already use Bash at work and stuff, so it's easy for me. C) I am generally averse to fast-changing dependencies, and giant dependency trees, so that rules out most scripting languages. Besides, if you peruse the README, you will see that my code guarantee is "works on my machine". Your mileage will vary tremendously :)
- maccard 3y agoIf it's just for fun then write your bundler in assembly for all I care!
- adityaathalye 3y agoYou never know :)