我的 Obsidian + Hugo 博客设置(使用热键自动发布)
如果您点击了这篇文章,您可能知道这两种技术是什么,但如果您不知道,这里有一个快速解释:
黑曜石
Obsidian 是一个功能丰富的 Markdown 编辑器。但它不仅仅是一个 Markdown 编辑器。这是管理知识的一种方式。它非常适合以灵活、非线性的方式组织您的想法。
黑曜石适用于所有平台。所以你基本上可以在任何平台上写文章。
几个月来我一直在其中记下所有笔记,这太棒了!
雨果
Hugo 是一个用 golang 制作的超快速静态网站生成器。我的博客使用 Hugo 已经快两年了。我最近更换了博客的主题。了解更多关于新面貌、新开始的变化。
设置
在本文中,我不会展示如何设置这两种技术,而只是展示如何让它们协同工作。
如果您想了解我如何使用hugo、cloudflare 和 render.com 设置整个博客,请阅读:我如何免费设置此博客(域名、托管、ssl)完整指南
如果您想要有关如何使用黑曜石的良好指南,请阅读:入门 - obsidian.md
目标
我的设置目标是:
- 使用单个黑曜石金库
- 有一个易于使用的黑曜石模板,我可以将其用于我的博客文章。
- 将我的个人保管库文件夹保密。
- 使用黑曜石热键自动发布。
- 将所有 Markdown 文件放在公共 github 存储库中,以便人们可以提出更改
现有设置
我当前的工作流程是:
- 从内容文件夹编辑文章。
- 运行hugo命令。
- 推送到github。
- Render.com 自动获取更改并提供服务。
旅行
如果你想跳过旅程部分可以直接去The Sauce
我将经历一些在设置时犯的错误。
错误#1
我的第一个想法是创建一个简单的符号链接(顺便说一句,我使用 linux),将两个文件夹链接在一起。
基本上我有两个文件夹:
blog/ vault/
博客文件夹包含所有博客文件夹,保管库是我的个人保管库。
符号链接将链接这些文件夹
blog/content vault/Blog
但是符号链接的问题是文件夹内容在我的 git 存储库中不可见。这意味着人们不能对我的任何文章提出修改
错误#2
我想要同步我的文件夹。我尝试编写几个 bash 脚本,使用 cronjob 自动同步两个文件夹。然而,当我不写作时,不断运行后台是一种资源浪费。仅仅通过 cli 运行脚本并不那么顺利。
酱汁
基本上我设置的方式是我有两个文件夹:
blog vault
blog 文件夹包含所有必需的 Hugo 文件,还有一个名为 content 的子目录,其中包含所有 Markdown 博客文件。
我在我的保管库中创建了一个名为 Blog
的新文件夹
blog/content vault/Blog
之后,我将所有文件从内容目录复制到博客。
然后我开始写这篇文章
黑曜石模板
我需要某种方法来设置一个简单的模板来包含所有必需的 Hugo 前言。
这很简单。
了解如何设置模板 模板 - obsidian.md
我在模板文件夹中创建了一个名为 Blog Post 的文件
我的博客文章模板包含以下内容:
--- title: "{{Title}}" description: date: "{{date:YYYY-MM-DD}}T{{time:HH:mm:ss}}+00:00" draft: true --- **If you enjoyed this article consider [supporting me](https://4rkal.eu.org/donate)**
我有所有必需的前言,包括标题、描述和日期,格式符合 Hugo 要求的格式。
我还添加了一条简短的捐赠文字,将其添加在每篇文章的底部。
这意味着我可以自动将此模板插入到任何文件中并开始编写!
文件夹同步
现在我希望将我的保管库/博客目录中的所有文件复制到博客/内容
感谢一位热心的不和谐用户,我找到了 obsidian-shellcommands 插件。
注意:这个插件目前不能很好地与黑曜石的 flatpak 版本配合使用(因为 flatpak 隔离了环境)。使用另一种替代方案(.deb 或 appimage)似乎可行。
它允许您使用热键在后台运行 shell 命令。
设置步骤如下:
- Install the plugin
- Enable the plugin
- Go to the plugin options
- Click on New shell command
- Now you will need to enter a shell command to copy the files from the one folder to the other.
On Linux/MacOS that is:
cp -a ~/folder1/. ~/folder2/
in my case that is cp -a ~/Documents/vault/Blog/. ~/Documents/blog2/content/
On windows it most probably is:
robocopy "%USERPROFILE%\folder1" "%USERPROFILE%\folder2" /E /COPYALL
After that we need to set a hotkey that will run the command
Click on the (+) icon to go to the hotkey settings and assign a hotkey
My hotkey is CTR + 0, simply because that was available.
Now every time that I run the hotkey it copies over all of my files to the hugo folder ready to be published
Auto publishing scripts
I also want to be able to automatically publish my articles. But I want it to happening by hitting a hotkey.
I wrote a small script that does exactly that:
#!/bin/bash cd ~/Documents/blog hugo git add . git commit -m "new" git push -u origin main
This script will build my website, commit and push to my github repo, where it is picked up and published. Read How I setup this blog for free (domain, hosting, ssl) Complete Guide to learn how to setup your own blog for free.
Don’t forget to make the script executable by running
chmod +x ./YOURSCRIPT.sh
Then create a new shell command for the shellcommand plugin (as we did before) and enter the path to your script.
In my case that is:
~/Documents/blog2/push.sh
Then enter a hotkey and you’re done!
Conclusion
I can now simply open my obsidian vault, create a new file, insert my template and have all the info automatically entered.
I then write my article inside of obsidian
Run my hotkey and copy all the files into the hugo directory
Hit another key and my blog is published!
If you enjoyed this article consider supporting me
以上是我的 Obsidian + Hugo 博客设置(使用热键自动发布)的详细内容。更多信息请关注PHP中文网其他相关文章!

热AI工具

Undresser.AI Undress
人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover
用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool
免费脱衣服图片

Clothoff.io
AI脱衣机

Video Face Swap
使用我们完全免费的人工智能换脸工具轻松在任何视频中换脸!

热门文章

热工具

记事本++7.3.1
好用且免费的代码编辑器

SublimeText3汉化版
中文版,非常好用

禅工作室 13.0.1
功能强大的PHP集成开发环境

Dreamweaver CS6
视觉化网页开发工具

SublimeText3 Mac版
神级代码编辑软件(SublimeText3)

Golang在性能和可扩展性方面优于Python。1)Golang的编译型特性和高效并发模型使其在高并发场景下表现出色。2)Python作为解释型语言,执行速度较慢,但通过工具如Cython可优化性能。

Golang在并发性上优于C ,而C 在原始速度上优于Golang。1)Golang通过goroutine和channel实现高效并发,适合处理大量并发任务。2)C 通过编译器优化和标准库,提供接近硬件的高性能,适合需要极致优化的应用。

goisidealforbeginnersandsubableforforcloudnetworkservicesduetoitssimplicity,效率和concurrencyFeatures.1)installgromtheofficialwebsitealwebsiteandverifywith'.2)

Golang适合快速开发和并发场景,C 适用于需要极致性能和低级控制的场景。1)Golang通过垃圾回收和并发机制提升性能,适合高并发Web服务开发。2)C 通过手动内存管理和编译器优化达到极致性能,适用于嵌入式系统开发。

Golang和Python各有优势:Golang适合高性能和并发编程,Python适用于数据科学和Web开发。 Golang以其并发模型和高效性能着称,Python则以简洁语法和丰富库生态系统着称。

Golang和C 在性能上的差异主要体现在内存管理、编译优化和运行时效率等方面。1)Golang的垃圾回收机制方便但可能影响性能,2)C 的手动内存管理和编译器优化在递归计算中表现更为高效。

Golang和C 在性能竞赛中的表现各有优势:1)Golang适合高并发和快速开发,2)C 提供更高性能和细粒度控制。选择应基于项目需求和团队技术栈。

Golangisidealforbuildingscalablesystemsduetoitsefficiencyandconcurrency,whilePythonexcelsinquickscriptinganddataanalysisduetoitssimplicityandvastecosystem.Golang'sdesignencouragesclean,readablecodeanditsgoroutinesenableefficientconcurrentoperations,t
