6 ms·
Show HN: Static blog generator in about 1 KLOC
- dvfjsdhgfv 6y agoI remember playing with these things in late nineties and making jokes at my friends creating bleeding edge CMSes with PHP and mSQL/MySQL I can get much faster than them. I wouldn't have believed things would come full circle over 20 years later.
- forgotmypw17 6y agoSometimes the journey is about learning where home is, and why it's home. It has been that way for me. After trying many frameworks, "modern" languages, working on many teams, I've learned to love Perl, LCD-JS, and HTML in a whole new way.
- mhd 6y agoMy first blog ran on blosxom. I think I switched to something dynamic (textpattern) partly because back then I thought it mandatory that every month and day needed its own index if you just put in the month/day in the URL and stuff like that. Seemed more elegant to do that dynamically than store redundant information. (Textpattern was pretty great. Taught me about the weird google searches that lead people to your site.)
- jstanley 6y ago1000 lines! What decadence! This is what I use for my blog, it is 250 lines: https://gist.github.com/jes/88e3e587413d5794f69c281bdd14a27f https://gist.github.com/jes/88e3e587413d5794f69c281bdd14a27f (Joking aside: cool project, and I expect it is substantially more capable than my ridiculously-hacky version).
- forgotmypw17 6y ago1 line of Perl counts for 5 lines of Python, so you're actually behind on the golf course.
- jstanley 6y agoInterestingly OP's project includes equivalent Perl and Python implementations and his Python version is actually shorter, I did not expect that.
- forgotmypw17 6y agoI did not notice that, thanks for pointing it out.
- pmiller2 6y agoThat seems like a lot of unnecessary maintenance to me.
- jjjbokma 6y agoI ported the program to Python when the Perl version was already fleshed out a bit. Keeping them in sync hasn't been that hard. After each update I run both versions on the same input file (resulting in my blog https://plurrrr.com/ https://plurrrr.com/) and check with meld if there are any differences. This works very well. I am only a little worried that the Python code might contain some Perl-isms.
- forgotmypw17 6y agoI disagree. It does a lot to help reliability and to find bugs. It also means you have a completely decoupled backup system should anything go wrong with the primary. I'm aiming to have at least one redundant component for every piece in the system I'm writing.
- cristiandima 6y agoThis is my 103 lines python version: https://github.com/cristiandima/scribe https://github.com/cristiandima/scribe. I wrote it about four years ago for my own blog and I still use it to this day. It does however depend on a few libs and comes with separate html template files for a theme so I am not exactly sure where I stand on the golf course.
- 1wheel 6y agoMine is 60 lines of js; the markdown library does most of the work. https://roadtolarissa.com/literate-blogging/ https://roadtolarissa.com/literate-blogging/
- lynndotpy 6y agoThe most minimal I can muster is 3 lines of Bash: for filename in ./posts/*.md; do pandoc -s -c style.css $filename -o outputs/$(basename $filename md)html done
- samtheprogram 6y agoThis can get pretty pedantic. Where do you draw the line between what is the blog generator and the tools required to do it when counting the number of lines of code? One could easily argue in this case you might want to be counting the lines of code in pandoc, not this bash script. That said, I do think this is the way to go, using a popular and generic tool (notably that you do not have to maintain) to accomplish a specific task. And more importantly, composing utilities together in a succinct and efficient way. Also, if you used semicolons, or xargs with a pipe, you could make this one line :) newlines can be pretty arbitrary, I wonder if there's a better measurement for simplicity, like branches or statements/expressions.
- antisol 6y agodamn, that's not a bad effort, I like it. But it does sort of feel like cheating ;) Mine is about 140 lines of bash, and I don't /think/ i'm using anything that isn't part of coreutils.
- jjjbokma 6y agoIt started small but then I added an RSS feed (it already had JSON somewhat from the start) and various calendar views. Also some code was added to rewrite an image followed by text to a figure + figcaption to make it more semantic and easier to style.
- jpgleeson 6y agoMy ~750ish one to split the difference. https://sr.ht/~jpgleeson/piaine/ https://sr.ht/~jpgleeson/piaine/ I do think this is one of the most enjoyable projects I’ve ever done.
- jjjbokma 6y agoSame here. I was happy to find a small bug in the code so I could work somewhat more on it.
- superkuh 6y agoThe filesystem is the best CMS. For my static blog I just stick to a file naming format like ~/www/blog/2020-10-17-1.html and then assemble post indices with shell and variations for monthly indices. The RSS feed generation is a 100 line perl script though. ~/www/blog/ $ ./recentblogposts.pl; ls -v 2020-*.html | tac | xargs cat > blog-2020.html
- Rebelgecko 6y agoMine is 4 lines, although it would be trivial to make it shorter. Here it is, although I'm actually working on migrating over to Hugo because it has some nice features that would be a pain to implement myself for filename in pages_md/*.md; do basename=$(basename "$filename" .md) pandoc "$filename" -f markdown_github -t html -o "pages/$basename.html" done
- jjjbokma 6y agoExample of the output can be viewed at https://plurrrr.com/ https://plurrrr.com/
- Animats 6y agoOh, it's just a Markdown to HTML translator. I expected it to write the blog, with GPT-3.
- userbinator 6y agoThe amount of "intelligence" you could fit in 1KLoC is probably not much more than a really bad Markov model...
- Animats 6y agoDepends on what external services it calls.
- winrid 6y agoThe one I wrote for the FastComments Blog is 140 lines. Each post is a separate markdown file, and it has RSS support. I love using NodeJS for little scripts like this. Generates in about 200ms for the content we have today. https://github.com/FastComments/fastcomments-blog/blob/master/src/app.js https://github.com/FastComments/fastcomments-blog/blob/maste... There are hacks in that file. Beware the dragons. Commenting support is or course done with FastComments...
- thomasfromcdnjs 6y agoI've been toying with a project where you define your entire blog in one file (blog.json) and then you can pass that file to a generator (community built) and it will output html for you to deploy. I wrote about it here -> https://ajaxdavis.com/post/Introducing-JSON-Blog/ https://ajaxdavis.com/post/Introducing-JSON-Blog/ I'm using the project to run my blog above.
- mobilio 6y agoI'm testing for same job bashblog -> https://github.com/cfenollosa/bashblog https://github.com/cfenollosa/bashblog
- mihaifm 6y agoAdding my own in here, 668 lines: https://github.com/mihaifm/smolpress https://github.com/mihaifm/smolpress Static generator + CMS (extremely lightweight), management interface and markdown editing.
- indigodaddy 6y agoThis looks really cool and fairly unique! Thanks for posting.
- egberts1 6y agoAnd here we begin the “I did it in X lines” where X is less than the previous commentator’s boast.