TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

“Make” as a static site generator (2022)

285 点作者 bundie超过 1 年前

38 条评论

p4bl0超过 1 年前
My personal website (<a href="https:&#x2F;&#x2F;pablo.rauzy.name&#x2F;" rel="nofollow noreferrer">https:&#x2F;&#x2F;pablo.rauzy.name&#x2F;</a>) used to be generated using a simple Makefile.<p>Then I added features like news and an RSS feed, a way to automatically list my research publications and course materials, a list of books filterable with tags, etc. So now it still is a Makefile but the Makefile itself is a bit simpler than it used to be, but it calls a few Bash scripts that in particular make use of the awesome xml2 and 2xml utilities to be able to manipulate HTML in a line-oriented manner using the core utils (grep and sed mostly).<p>On top of that I have a few git hooks that call make automatically when needed, in particular on the remote server where the website is hosted so that the public version is rebuilt when I push updates the repository there.<p>It&#x27;s been working like a charm for <i>years</i>! My git history goes back to 2009.<p>EDIT: I just had a look at the first commits…<p><pre><code> beccad7 (FIRST_VERSION) Initial commit d1cc6d7 adding link to Google Reader shared items 6ccfd0c fix typo d337959 adding link to Identi.ca account </code></pre> … 15 years have passed indeed.
评论 #37457614 未加载
jez超过 1 年前
A problem with this approach is that deleting a file from source&#x2F; does not delete it from build&#x2F;.<p>In my own projects, simply rebuilding the whole site is fast enough, so I opt to remove the whole build folder before a rebuild:<p><a href="https:&#x2F;&#x2F;github.com&#x2F;jez&#x2F;jez.github.io&#x2F;blob&#x2F;source&#x2F;Makefile#L10">https:&#x2F;&#x2F;github.com&#x2F;jez&#x2F;jez.github.io&#x2F;blob&#x2F;source&#x2F;Makefile#L1...</a><p>This defeats a big part of why you’d want a build system in the first place (incremental builds), but at least if you know the page you want to regenerate you can still `make` that file directly.<p>If there’s a common workaround for this pattern in makefiles I’d love to learn it.
评论 #37456477 未加载
评论 #37461998 未加载
评论 #37456267 未加载
评论 #37456411 未加载
评论 #37458332 未加载
评论 #37456751 未加载
评论 #37459094 未加载
评论 #37458483 未加载
评论 #37456464 未加载
bradley_taunt超过 1 年前
I was instantly inspired by Karl&#x27;s work on his &quot;blog.sh&quot; shell script[0] that he mentions in this article. I took it and tweaked it to create my own minimalist SSG called &quot;barf&quot;[1]. That wouldn&#x27;t exist if Karl didn&#x27;t share his wonderful work publicly!<p>[0]: <a href="https:&#x2F;&#x2F;github.com&#x2F;karlb&#x2F;karl.berlin&#x2F;blob&#x2F;master&#x2F;blog.sh">https:&#x2F;&#x2F;github.com&#x2F;karlb&#x2F;karl.berlin&#x2F;blob&#x2F;master&#x2F;blog.sh</a> [1]: <a href="https:&#x2F;&#x2F;barf.bt.ht" rel="nofollow noreferrer">https:&#x2F;&#x2F;barf.bt.ht</a>
评论 #37455472 未加载
m000超过 1 年前
Adding a pinch of m4 [1] can give you a bit more of flexibility while sticking with the same barebones approach.<p>I used to maintain a small website built like that some 20 years back. But I can&#x27;t see the model working today, personal websites excluded. The problem is that the approach essentially enforces Web 1.0 roles: You either need every contributing user to be html-proficient, or someone willing to assume the drudgery of being the &quot;webmaster&quot;.<p>[1] <a href="https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;M4_(computer_language)" rel="nofollow noreferrer">https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;M4_(computer_language)</a>
评论 #37455940 未加载
评论 #37456242 未加载
评论 #37455787 未加载
评论 #37455325 未加载
评论 #37456050 未加载
评论 #37464912 未加载
评论 #37465729 未加载
rambambram超过 1 年前
I like it that (almost) every dev blog I come across on HN has an RSS feed.<p>For every interesting article that I read here I follow the feed. Whether you have a Wordpress site, a Bear Blog, a Micro blog, a blog on Havenweb, or a feed on your self-built site, I add them to the &#x27;Really Social Sites&#x27; module of Hey Homepage.<p>Ultimately, I would like to publish this list of blogs, just like Kagi now does with their Small Web initiative. But I guess curating is key to adding quality. And when I think about curating, starting some kind of online magazine seems only natural.
评论 #37457891 未加载
评论 #37461501 未加载
marcodiego超过 1 年前
A friend of mine described using make to generate scientific papers. He explained that if he changed a single test file, the entire paper could be regenerated including running tests and generating graphs the changed test with a single command.
danielvaughn超过 1 年前
It&#x27;s a neat idea, though I have to point out that if you&#x27;re already pushing to Github, you could just push the source and Github will publish your markdown as a hosted page: <a href="https:&#x2F;&#x2F;pages.github.com&#x2F;" rel="nofollow noreferrer">https:&#x2F;&#x2F;pages.github.com&#x2F;</a>
评论 #37464477 未加载
adityaathalye超过 1 年前
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.<p>But the basic idea is the same --- heredocs for templating, using a plaintext -&gt; html compiler (pandoc in my case), an intermediate CSV for index generation. Also some handy sed-fu [3] to lift out front matter. Classic :)<p>Very nice!<p>[1] <a href="https:&#x2F;&#x2F;github.com&#x2F;karlb&#x2F;karl.berlin&#x2F;blob&#x2F;master&#x2F;blog.sh">https:&#x2F;&#x2F;github.com&#x2F;karlb&#x2F;karl.berlin&#x2F;blob&#x2F;master&#x2F;blog.sh</a><p>[2] <a href="https:&#x2F;&#x2F;github.com&#x2F;adityaathalye&#x2F;shite">https:&#x2F;&#x2F;github.com&#x2F;adityaathalye&#x2F;shite</a><p>[3] I&#x27;m doing this: <a href="https:&#x2F;&#x2F;github.com&#x2F;adityaathalye&#x2F;shite&#x2F;blob&#x2F;master&#x2F;bin&#x2F;templating.sh#L34">https:&#x2F;&#x2F;github.com&#x2F;adityaathalye&#x2F;shite&#x2F;blob&#x2F;master&#x2F;bin&#x2F;templ...</a><p><pre><code> case ${file_type} in org ) # Multiline processing of org-style header&#x2F;preamble syntax, boxed # between begin&#x2F;end markers we have defined. We use org-mode&#x27;s own # comment line syntax to write the begin&#x2F;end markers. # cf. https:&#x2F;&#x2F;orgmode.org&#x2F;guide&#x2F;Comment-Lines.html sed -n -E \ -e &#x27;&#x2F;^\#\s+shite_meta&#x2F;I,&#x2F;^\#\s+shite_meta&#x2F;I{&#x2F;\#\s+shite_meta.*&#x2F;Id; s&#x2F;^\#\+(\w+)\:\s+(.*)&#x2F;\L\1\E,\2&#x2F;Ip}&#x27; ;; md ) # Multiline processing of Jekyll-style YAML front matter, boxed # between `---` separators. sed -n -E \ -e &#x27;&#x2F;^\-{3,}&#x2F;,&#x2F;^\-{3,}&#x2F;{&#x2F;^\-{3,}.*&#x2F;d; s&#x2F;^(\w+)\:\s+(.*)&#x2F;\L\1\E,\2&#x2F;Ip}&#x27; ;; html ) # Use HTML meta tags and parse them, according to this convention: # &lt;meta name=&quot;KEY&quot; content=&quot;VALUE&quot;&gt; # cf. https:&#x2F;&#x2F;developer.mozilla.org&#x2F;en-US&#x2F;docs&#x2F;Learn&#x2F;HTML&#x2F;Introduction_to_HTML&#x2F;The_head_metadata_in_HTML sed -n -E \ -e &#x27;s;^\s?&lt;meta\s+name=&quot;?(\w+)&quot;?\s+content=&quot;(.*)&quot;&gt;;\L\1\E,\2;Ip&#x27; ;; esac</code></pre>
评论 #37455607 未加载
评论 #37455740 未加载
kazinator超过 1 年前
The benefit of make is that large programs that are built by slow compilers can be incrementally rebuilt much faster in the face of small changes. Something that would take 40 minutes to do a full rebuild can build in three seconds or whatever.<p>If your static site can be generated from scratch in under a second by just catting a few hundred HTML files with a common header, there is no benefit to using make over a script. You only risk performing an incomplete build due to a bug in the dependencies.
评论 #37458205 未加载
Kiuhrly超过 1 年前
Wow, this is almost exactly what I was planning to do for my site. For another small project, I wrote a tiny shell script as a makeshift &quot;bundler&quot; (just embeds the CSS and JS inside the HTML) with the goal of also being able to serve the unbuilt files locally:<p><pre><code> sed \ -e &#x27;&#x2F;[&#x2F;][&#x2F;]script&#x2F;r index.js&#x27; -e &#x27;&#x2F;[&#x2F;][&#x2F;]script&#x2F;d&#x27; \ -e &#x27;&#x2F; &lt;script defer src=&quot;[.][&#x2F;]index[.]js&quot;&gt;&lt;[&#x2F;]script&gt;&#x2F;d&#x27; \ -e &#x27;&#x2F;[&#x2F;][*]style[*][&#x2F;]&#x2F;r styles.css&#x27; -e &#x27;&#x2F;[&#x2F;][*]style[*][&#x2F;]&#x2F;d&#x27; \ -e &#x27;&#x2F; &lt;link rel=&quot;stylesheet&quot; href=&quot;styles[.]css&quot;&gt;&#x2F;d&#x27; \ index.html </code></pre> The HTML contains something like this:<p><pre><code> &lt;link rel=&quot;stylesheet&quot; href=&quot;styles.css&quot;&gt; &lt;style&gt; &#x2F;*style*&#x2F; &lt;&#x2F;style&gt; </code></pre> and the script just deletes the &lt;link&gt; tag and replaces the &#x2F;<i>style</i>&#x2F; comment with the contents of styles.css. Definitely not my finest work but it worked well enough.
jrm4超过 1 年前
Interesting. So I&#x27;m a weird sort, I imagine, in that I&#x27;m the type that has been using Linux and shell scripts for 20+ years, but never actually done any big-time coding, and thus I really don&#x27;t know &quot;make.&quot;<p>Point being, I do something very similar to this; except I first simply write&#x2F;create my website in Zim-wiki, but then I have a bunch of little tasks to &quot;clean up,&quot; i.e. fix&#x2F;modify some links and then use the Canvas API to update my main course page (which, because I hate Canvas that much, simply links out to my own site).<p>Why make instead of shell scripts?
评论 #37455345 未加载
评论 #37456654 未加载
评论 #37458020 未加载
defanor超过 1 年前
I used a shell script for that, but vaguely thought of changing to a Makefile for a while, and finally did now, thanks to the article reminding of that; it is more appropriate. Though the shell script still invokes make, and then rsync, since rsync seems less appropriate for a Makefile. But now it synchronizes fewer files.<p>As a side note, I am quite happy with XSLT templates to produce the pages (instead of attaching a static header, as in the article), as well as to generate indexes and an Atom feed.
denvaar超过 1 年前
It’s fun to make your own SSG tool, and this is a great example of keeping it simple.<p>It’s also interesting to read so many comments of people doing similar things.<p>For my own site, I find that I want an SSG tool that is simple, intuitive, and stays out of the way. With these goals in mind, I have been able to slowly improve my tool over and over. It’s been awesome to be able to do more using less.
评论 #37455727 未加载
tyingq超过 1 年前
The syntax takes a little trial and error and usually finding real-world examples, but I like &quot;make&quot;.<p>I had one project that involved downloading a jdk, using it to build a project specific jre, patching some class files with local java sources, bundling it, etc.<p>Without being a make expert, it took me a couple of hours of reading, finding examples, etc...but now I have the dependency stuff working perfectly. Where it now only re-downloads or re-builds things if something upstream from it changed, handles errors well and points out what broke, etc.<p>All that to say, for some things, it&#x27;s worth looking into for it&#x27;s built-in dependency chain stuff. When you need to run arbitrary outside scripts&#x2F;tools, it sometimes does things that other build tools can&#x27;t (gradle in my case, couldn&#x27;t easily do this, or at least I couldn&#x27;t figure out how).
评论 #37455421 未加载
w4rh4wk5超过 1 年前
I did some similar experiments some time ago. It includes Makefiles, Rakefiles, SASS, Ruby erb, Jade, m4, and a few other tools.<p><a href="https:&#x2F;&#x2F;github.com&#x2F;W4RH4WK&#x2F;static-page-generators">https:&#x2F;&#x2F;github.com&#x2F;W4RH4WK&#x2F;static-page-generators</a><p>Over all, I quite like Ruby since it comes with rake and erb.
评论 #37455750 未加载
ivanstojic超过 1 年前
Tossing mine in the pot too: make + pandoc: <a href="https:&#x2F;&#x2F;ordecon.com&#x2F;2020&#x2F;07&#x2F;pandoc-as-a-site-generator&#x2F;index.html" rel="nofollow noreferrer">https:&#x2F;&#x2F;ordecon.com&#x2F;2020&#x2F;07&#x2F;pandoc-as-a-site-generator&#x2F;index...</a>
donatj超过 1 年前
Just a couple days ago I set up a site with GitHub Pages and used a very similar setup.<p>I learned about envsubst in the process which let me fill in values here and there. This is the rough way the homepage works.<p><pre><code> public&#x2F;index.html: index.md template&#x2F;header.html template&#x2F;footer.html cat template&#x2F;header.html &gt; public&#x2F;index.html DATE=$(shell date +%Y-%m-%d) envsubst &lt; index.md | npx marked --gif &gt;&gt; public&#x2F;index.html cat template&#x2F;footer.html &gt;&gt; public&#x2F;index.html </code></pre> GitHub’s newer version of pages that lets you deploy via GitHub Actions rather than being forced into using Jekyll is just so amazing. I have converted a bunch of static sites to using it as hosting.
评论 #37455175 未加载
askiiart超过 1 年前
I did something similar for mine, I do markdown-to-html using pandoc, then replace the language labels using find (so that prism.js works). I&#x27;ve got it all running via a little Python script (I would&#x27;ve done bash but I&#x27;m terrible at it) to generate all the the files easily, rather than going through one-by-one: <a href="https:&#x2F;&#x2F;git.askiiart.net&#x2F;askiiart&#x2F;askiiart-net&#x2F;src&#x2F;branch&#x2F;main&#x2F;md2html.py" rel="nofollow noreferrer">https:&#x2F;&#x2F;git.askiiart.net&#x2F;askiiart&#x2F;askiiart-net&#x2F;src&#x2F;branch&#x2F;ma...</a><p>I might move to something make-based like this, looks interesting.
评论 #37475945 未加载
评论 #37456820 未加载
girishso超过 1 年前
Most Static Site Generators generate blog from markdown, which is not feasible for projects like company websites etc. For such projects I like Middleman (<a href="https:&#x2F;&#x2F;middlemanapp.com" rel="nofollow noreferrer">https:&#x2F;&#x2F;middlemanapp.com</a>) which provides layouts&#x2F;partials and things like haml templates.
评论 #37460830 未加载
mosselman超过 1 年前
This amazing course by Avdi Grimm on make and rake for the same purpose has completely changed my understanding of rake and I recommend anyone checking it out:<p><a href="https:&#x2F;&#x2F;graceful.dev&#x2F;courses&#x2F;acapa&#x2F;" rel="nofollow noreferrer">https:&#x2F;&#x2F;graceful.dev&#x2F;courses&#x2F;acapa&#x2F;</a>
karl42超过 1 年前
Author here. Nice to see people appreciate simplicity. If you have any questions, feel free to ask!
gigatexal超过 1 年前
I do this too! But my make-fu isn’t as good. I’ll use what I learned from here to make it better.
tiehuis超过 1 年前
I as well moved to this sort of approach a few years ago [1]. Definitely like the simple approach and it just stays out of the way.<p>[1] <a href="https:&#x2F;&#x2F;tiehu.is&#x2F;blog&#x2F;blog1" rel="nofollow noreferrer">https:&#x2F;&#x2F;tiehu.is&#x2F;blog&#x2F;blog1</a>
adriangrigore超过 1 年前
Shameless plug for my shell based static site generator <a href="https:&#x2F;&#x2F;mkws.sh" rel="nofollow noreferrer">https:&#x2F;&#x2F;mkws.sh</a>. You can replace the bin&#x2F;mkws script with a Plan9 mk file anytime.
评论 #37455835 未加载
mkoryak超过 1 年前
&gt; There are no exotic dependencies, nothing to maintain and you can quickly adapt it to your needs.<p>Yeah kinda, except that most people making static sites aren&#x27;t the people who know Make.
评论 #37455246 未加载
评论 #37455812 未加载
smarnach超过 1 年前
Isn&#x27;t this &quot;cat&quot; as a static site generator target than &quot;make&quot;? Make is just the build system invoking the static site generator.
jasonm23超过 1 年前
Bash&#x2F;Zsh as a static site generator would be less steps.<p>Or Github actions workflow as static site generator would only include one shell wrapper, instead of 2.
dwheeler超过 1 年前
I&#x27;ve been doing this for decades. It works very well, it can handle complex cases, and it ports trivially between different hosting systems.
TekMol超过 1 年前
What does make bring to the table here compared to a shellscript which loops over the files in the source dir?
评论 #37455529 未加载
sureglymop超过 1 年前
I use make and pandoc as my static site generator! Generates a good website from my markdown notes.
mstef超过 1 年前
utterson <a href="https:&#x2F;&#x2F;github.com&#x2F;stef&#x2F;utterson&#x2F;tree&#x2F;master">https:&#x2F;&#x2F;github.com&#x2F;stef&#x2F;utterson&#x2F;tree&#x2F;master</a> is generating blogs using make for a 14 years now...
PaulHoule超过 1 年前
Funny I am setting up a blog with Pelican which uses “make” for executive control.
lacrosse_tannin超过 1 年前
I&#x27;m gonna use bazel
superlopuh超过 1 年前
Is there a GitHub workflow available for this or similar tool?
bachmeier超过 1 年前
As long as we&#x27;re sharing our own projects...<p>One of the things I did during the pandemic lockdown was work on the simplest possible blog in a single html file. Something that requires essentially no technical knowledge beyond typing text into a file. I recently dusted it off and yesterday I posted the most recent iteration.<p>Demo: <a href="https:&#x2F;&#x2F;bachmeil.github.io&#x2F;minblog&#x2F;blog.html" rel="nofollow noreferrer">https:&#x2F;&#x2F;bachmeil.github.io&#x2F;minblog&#x2F;blog.html</a><p>Source: <a href="https:&#x2F;&#x2F;github.com&#x2F;bachmeil&#x2F;minblog&#x2F;blob&#x2F;main&#x2F;blog.html">https:&#x2F;&#x2F;github.com&#x2F;bachmeil&#x2F;minblog&#x2F;blob&#x2F;main&#x2F;blog.html</a><p>There&#x27;s very little styling, but that&#x27;s not the objective (and it&#x27;d be trivial to add).
评论 #37458783 未加载
liveoneggs超过 1 年前
hey I wrote almost this exact blog post 15(ish?) years ago except mine used m4 as an &quot;exotic dependency&quot; ;)
jameshart超过 1 年前
&quot;No exotic dependencies and nothing to maintain&quot;<p>Oh really?:<p><pre><code> sed -E &#x27;s|(href=&quot;$(subst source,,$&lt;))|class=&quot;current&quot; \1|&#x27; header.html | cat - $&lt; &gt; $@ </code></pre> a sed script that modifies HTML fragments isn&#x27;t <i>nothing</i>. And this just does <i>one</i> thing that you might want to customize in the header for each page. It doesn&#x27;t do things like handle pages having different &lt;title&gt; tags. Every feature like this that you come up with becomes another thing to maintain, and another thing that can catch you out later. When you come back to fix this later, will you even remember what it&#x27;s supposed to do?<p>From a web publishing point of view, make and sed <i>are</i> exotic dependencies. There&#x27;s not going to be a bunch of helpful pointers online to help you debug issues with using them for this purpose. When you google how to fix your sed regex to match specific HTML attributes and not match others, you&#x27;re going to find stack overflow posts about Zalgo, not quick answers.
评论 #37458338 未加载
superkuh超过 1 年前
Or maybe don&#x27;t make a site generator and just make a website using HTML files? You&#x27;ll spend a lot less time painting the shed and a lot more time actually putting your ideas&#x2F;content on the website.<p>If you want templating then use server side includes. It&#x27;s much less attack surface than say, PHP or some complex CMS, but you can still just make a footer.html and stick in at the bottom of every other .html page easily and avoid the one problem with file based sites: updating shared bits.
评论 #37455850 未加载