把一个子树发布成一篇文章是 ox-hugo 的推荐做法
这也正是我想要的功能

Resources

ox-hugo - Org to Hugo exporter

Using Org Mode With Hugo · weblog.masukomi.org

Tips & advice on using ox-hugo to blog with org-mode & Hugo

My blogging setup with Emacs and Org Mode · Andrey Listopadov

Aster Hu’s Blog | Asteroid - Publish org-roam notes to personal wiki using ox-hugo and Quartz
我主要参考的是这篇博客

Manual

Anchors — ox-hugo - Org to Hugo exporter
Shortcodes — ox-hugo - Org to Hugo exporter

Usage

HUGO_BASE_DIR

This property can be set by one of two ways:

  • Setting the #+hugo_base_dir: keyword in the Org file.
  • Setting the org-hugo-base-dir variable in a .dir-locals.el or File Local Variables.

HUGO_SECTION

默认是 posts

EXPORT_FILE_NAME

对于导出到文件的子树来说,必须要存在这个属性

自动导出

Auto-export on Saving — ox-hugo - Org to Hugo exporter
org-hugo-auto-export-mode

Responsive Auto Export for Org Hugo - Noetic Nought
这是想要解决导出速度的问题

org-hugo-auto-export-mode 有一个很大的问题,我没说要导出的也会被导出!!!

我希望只导出我标记了要导出的

其实这里有一个解决办法 Exclude notes from export

最后我的解决办法在这里 org-roam-hugo

ISSUE

这种东西会被视为 html 标签,然后不在导出得到的文件中显示!
正确的做法应该是原样输出(或者专门搞一个 broken links 的样式?)

TODO EXPORT_FILE_NAME for file export

<~/.config/emacs/.local/straight/repos/ox-hugo/ox-hugo.el>

其实我只要在运行导出之前运行一下 org-roam-demote-entire-buffer 就能解决很多问题
但是这说实话不太好看,会有多余的缩进

但是只要在 ox-hugo 层面修改就不会有问题了

我在尝试导出 形如 [[id:7e29fdd8-b8bc-41c3-9001-a75ba9802758::*CODE][CODE]] 这样的链接的时候,会被认为是 broken link!
只有 id: 和 :: 搭配的时候会出这个问题(不管是指向标题还是模糊匹配),
file: 搭配模糊匹配就不会有问题,我觉得问题出在 ox-hugo 上。

这个标题匹配应该是可以实现的,id 下的 fuzzy link 可能不太容易实现,或许应该 fallback 到最近标题?

related issue:
kaushalmodi/ox-hugo#715 broken-links handling only for fuzzy not id-type links

TODO 需要支持一下对 ROAM_REFS 的支持

我的链接都是放在这个属性下的,然后这个属性在默认情况下不会被导出,这很不方便

DONE respect org-id-locations-file

为什么 org-hugo-export-wim-to-md 会加载这么多无用的缓冲区?我不理解
他会使用 org-id-locations ,然后我这里这个变量是 nil
调用 org-id-update-id-locations

已合并 kaushalmodi/ox-hugo#770 Respect `org-id-locations-file` by 0WD0

DONE 不知道为什么会同步整个 svg 文件夹

因为可能某种配置下(不是我的配置下) latex 是会被 svg 链接替代的。
我在配置里强制让 org-hugo—copy-ltximg-maybe 为空就能解决问题了:

(after! ox
  (require 'ox-hugo)
  (advice-add 'org-hugo--copy-ltximg-maybe :override (lambda (&rest _) nil)))

DONE 发现了一个巨大 bug

使用子树导出模式时,如果有连向一个文件的根 id 的链接就会解析错误,会有这样的东西:
[Multi-SG](#d41d8c)

这里看出来问题是遇到了不合法的标题

以文件为单位导出的时候就不会有这个问题,就很奇怪

所以问题是什么?怎么会认为那个标题是空标题的?
提了个 issue:
kaushalmodi/ox-hugo#764 org-roam file-level ID links incorrectly processed in…

已提PR解决:
kaushalmodi/ox-hugo#764 org-roam file-level ID links incorrectly processed in…

Dev Notes

仓库结构一览

  • ox-hugo.el:767 定义 Hugo 导出后端、选项与元素翻译函数,是整个包的核心导出逻辑。
  • ox-blackfriday.el:136 提供 Blackfriday 风格的 Markdown 后端,hugo 后端在此之上派生。
  • ox-hugo-pandoc-cite.el:122 负责可选的 Pandoc 引用处理(运行 pandoc 展开引用后再恢复前置元数据)。
  • org-hugo-auto-export-mode.el:34 定义自动导出 minor mode,将保存操作钩到 org-hugo-export-wim-to-md。
  • ox-hugo-deprecated.el 保留旧 API 兼容性。
  • doc/ 是 Hugo 站点源码,用于生成项目文档;doc/ox-hugo-manual.org 等为手册源。
  • test/ 包含 ERT 测试与示例 Hugo 站点(test/site),用于回归验证。
  • Makefile、README.org、CHANGELOG.org 给予构建、说明与变更记录。

主要功能逻辑(导出流程)

  • 用户入口:通过 Org 导出调度或命令调用 org-hugo-export-wim-to-mdorg-hugo-export-to-mdorg-hugo-export-as-md
    (ox-hugo.el:4780, 4814, 4869),统一进入 Hugo 导出流程。
  • 导出模式判定:org-hugo-export-wim-to-md 检测当前缓冲是否存在带 EXPORT_FILE_NAME 的有效子树,决定“按子树”或“整文件”导出,支持一次导出全部有效子树
    (ox-hugo.el:4869)。
  • 子树/文件导出分支:
  • 预处理:若需要跨子树链接重写,会生成轻量 AST 副本并把内部链接改成可解析的文件链接(ox-hugo.el:4624)。
  • 核心导出:org-hugo-export-to-md 组合 Org 环境、选择发布目录,调用 org-export-to-file ‘hugo;org-hugo—before-export-function/org-hugo—after-1-export-function 在前后挂接/卸下临时 advice,记录前置元数据并触发后续处理(ox-hugo.el:1083)。
  • 元素翻译与前置元数据:hugo 后端的 :translate-alist 将关键 Org 元素(headline、src-block、link 等)映射到 Hugo/Markdown 语法;org-hugo-inner-template 等函数在导出主体前生成 TOML/YAML front‑matter(定义同块起始于 ox-hugo.el:767)。
  • 可选引用处理:若启用 HUGO_PANDOC_CITATIONS,org-hugo—after-1-export-function 调用 org-hugo-pandoc-cite—run-pandoc 展开引用并恢复前置元数据格式(ox-hugo-pandoc-cite.el:122)。
  • 收尾:导出全部完成后 org-hugo—after-all-exports-function 清理临时缓冲与计数器(ox-hugo.el:1123)。
  • 自动化:启用 org-hugo-auto-export-mode 时,保存 Org 文件会自动执行“所见即所指”导出(org-hugo-auto-export-mode.el:34)。

Inbox

org-export-define-derived-backend

之后需要看看这个函数怎么用
这应该是 org-export 主要的操作接口

link