2

写了一个 obsidian 插件,能够把 obsidian 笔记转换为 hugo blog

 3 months ago
source link: https://www.v2ex.com/t/1015313
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

V2EX  ›  分享创造

写了一个 obsidian 插件,能够把 obsidian 笔记转换为 hugo blog

  kirito41dd · 5 小时 0 分钟前 · 271 次点击

最早有一个 hugo 静态 blog 的站点,开始写博客都是在 vscode 里,后来用了 obsidian ,基本上所有笔记都在 obsidian 上写,然后想把 ob 的笔记变成 blog 的话,还要自己把 md 拷贝一次,包括处理图片链接啥的,挺麻烦的,所以写了个 obsidian 插件。

插件原理是扫描 obsidian 的文章,找到文章属性 tags 中带有博客 tag 的文章,将文章和其中嵌入的图片,转换到 hugo 站点对应目录。

插件会先把 obsidian md 转换为 ast ,进行一些转换后,再将其写入为 hugo 格式的 md 。

插件配置:

hugo-publish%E9%85%8D%E7%BD%AE.png
  • blog tag 是告诉插件,拥有那个 tag 的文章要被转换到 hugo 站点
  • site dir 是 hugo blog 的根目录
  • blog dir 是转换后的 md 存放目录,在 hugo blog 中的相当位置
  • static dir 是静态文件拷贝到的目录,指定为在 static 下的某个目录

obsidian 中要转换到 hugo 中的文章:

hugo-publish02.png
  • 加一个 tag 即可

转换:

hugo-publish003.png
  • 点击侧边栏按钮,或者 cmd+p 运行命令都可以

转换后在 hugo blog 中的结果:

hugo-publish004.png
  • md 和图片都转移过来了,之后运行hugo server可以查看效果

也可以看我的这篇笔记https://www.kirito.info/神经网络的结构/

图片和 latex 公式都能正常转换

地址: https://github.com/kirito41dd/obsidian-hugo-publish

目前申请官方的三方插件列表还没通过,安装需要手动把release中的 main.jsmanifest.json 放到 path/to/vault/.obsidian/plugins/hugo-publish

有感兴趣的可以试试,主要还是解决自己的需求,如果有同样需求希望可以帮到你


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK