我坚持用 Emacs 写博客
Babel is why I keep blogging with Emacs

原始链接: https://entropicthoughts.com/why-stick-to-emacs-blog

作者对那些使用简单、自建静态网站生成器的博主感到羡慕,承认自己的工作流程是一个复杂的谜。他们使用Org模式写作,并依赖其发布功能生成HTML,但并不了解其中涉及的2万多行代码。 虽然定制一个2千行的生成器听起来很有吸引力,但Org模式强大的Babel功能却让他们望而却步。Babel允许在导出文章时执行代码块,并将结果(如图表和表格)直接显示在发布的文档中。这种代码、数据和文本的无缝集成对他们的工作流程至关重要。 复制Babel的功能将是一项巨大的工程,远远超出了一个简单的博客引擎的范围。尽管承认其复杂性,作者认为Babel是不可或缺的,并将继续使用Org模式,即使这意味着对它的内部运作知之甚少。

Hacker News 新闻 | 过去 | 评论 | 提问 | 展示 | 招聘 | 提交 登录 我用 Emacs 继续写博客 (entropicthoughts.com) 20 分,ibobev 发表于 23 分钟前 | 隐藏 | 过去 | 收藏 | 1 条评论 _wire_ 0 分钟前 [–] 为什么有人仍然认为用图灵机做计算值得一提?还是说这是个 Church 极客在发帖说“别忘了 Lisp!”? Oops “entropicthoughts”!抱歉,明白了。回复 考虑申请 YC 2026 冬季批次!申请截止至 11 月 10 日 指南 | 常见问题 | 列表 | API | 安全 | 法律 | 申请 YC | 联系 搜索:
相关文章

原文

Every time I look at someone’s simple static site generation setup for their blog, I feel a pang of envy. I’m sure I could make a decent blogging engine in 2,000 lines of code, and it would be something I’d understand, be proud over, able to extend, and willing to share with others.

Instead, I write these articles in Org mode, and use mostly the standard Org publishing functions to export them to html. This is sometimes brittle, but most annoyingly, I don’t understand it. I have been asked for details on how my publishing flow works, but the truth is I have no idea what happens when I run the org-publish-current-file command.

I could find out by tracing the evaluation of the Lisp code that runs on export, but I won’t, because just the html exporting code (ox-html.el) is 5,000 lines of complexity. The general exporting framework (ox-publish.el and ox.el) is 8,000 lines. The framework depends on Org parsing code (org-element.el) which is at least another 9,000 lines. This is over 20,000 lines of complexity I’d need to contend with.

It might seem like a no-brainer to just write that 2,000 line custom static generator and use that instead.


Except one thing: Babel.

Any lightweight markup format (like Markdown or ReStructuredText or whatever) allows for embedding code blocks, but Org, through Babel, can run that code on export, and then display the output in the published document, even when the output is a table or an image. It supports sessions that lets code reuse definitions from earlier code blocks. It allows for injecting variables from the markup into the code, and vice versa. As a bonus, Org doesn’t require a JavaScript syntax highlighter, because it generates inline styles in the source code.

It does this for a large number of languages, although I mainly use it with R for drawing plots. Being able to do this is incredibly convenient, because it makes it trivial to draft data, illustrations, and text at the same time, adjusting both until the article coheres. Having tried it, I cannot see myself living without it.


A simple 2,000 line blogging engine would be a fun weekend project. Mirroring the features of Babel I use would turn it into a multi-month endeavour for someone with limited time such as myself. Not going to happen, and I will continue to beat myself up for overcomplicating my publishing workflow.

联系我们 contact @ memedata.com