{"version":"https://jsonfeed.org/version/1.1","title":"奇诺分享 | blog.ccino.cc - 重在分享","home_page_url":"https://blog.ccino.cc","feed_url":"https://blog-ccino-cc.pages.dev/json/","description":"","icon":"https://cdn-blog-ccino-cc.ccino.cc/blog-ccino-cc/production/images/channel-6ebae07c242a357bee27d74ca3e4b3ce.png","favicon":"https://cdn-blog-ccino-cc.ccino.cc/blog-ccino-cc/production/images/favicon-bdc56a1bbdd3d9f75032075380339348.jpg","authors":[{"name":"奇诺分享"}],"language":"zh-cn","items":[{"id":"N4KE5hrTVPH","title":"使用 Obsidian 一键发布博客","attachments":[{"url":"https://yaofun.top/posts/2024/03/%E4%BD%BF%E7%94%A8-obsidian-%E4%B8%80%E9%94%AE%E5%8F%91%E5%B8%83%E5%8D%9A%E5%AE%A2/","mime_type":"text/html"}],"url":"https://blog.ccino.cc/i/Use -obsidian- to publish a blog in one click","external_url":"https://yaofun.top/posts/2024/03/%E4%BD%BF%E7%94%A8-obsidian-%E4%B8%80%E9%94%AE%E5%8F%91%E5%B8%83%E5%8D%9A%E5%AE%A2/","content_html":"<p>博客荒废好久了！之前也陆陆续续使用过一些博客程序，要么发布部署有些麻烦，要么使用第三方服务不太稳定，一段时间就停止维护了。</p><p>偶然的机会看到文章：&nbsp;<a href=\"https://lillianwho.com/posts/obsidian-hugo-cloudflare/\" rel=\"noopener noreferrer\" target=\"_blank\">obsidian 配合 hugo、cloudflare：让发布博客简单到不可思议</a>，心动入坑，花了近一周的时间研究折腾，终于把基于 obsidian 的博客写作与发布工作流搭建起来了，现在可以愉快的一键发布啦。</p><p>从 0 到 1 折腾踩坑，整个过程好似「<strong>晨兴理荒秽，带月荷锄归</strong>」，但没有陶渊明那样悠然自得。折腾的心累，年纪再大点肯定折腾不动的，这里首先强烈建议怕麻烦同学的劝退。</p><p><br></p><h2>博客方案</h2><p>折腾前我整理出自己的博客需求如下：</p><ul><li>简单快捷：使用 Obsidian 写完，一键发布</li><li>稳定靠谱：减少第三方依赖，尽量使用靠谱的第三方服务，例如 github</li><li>图片能够顺畅加载：之前直接使用 github 做图床，国内访问很慢</li></ul><p>参考一些大佬的配置，最终的选型如下：</p><ul><li>Obsidian + obsidian git 插件 ：markdown 写作，obsidian git 插件自动上传 github</li><li>Hugo：静态网站构建工具</li><li>Github + Github Action ：源码托管，自动化编译（<em>emmm，github 应该不会倒闭</em>）</li><li>Cloudflare Page：静态网站托管 （也可以直接用 github page 托管）</li><li>Picgo + jsdelivr：基于 github 的图床 、cdn 加速</li></ul><p>最终达到的效果是： 在 obsidian 写文章，通过快捷键一件上传到 git 之后，自动构建发布。 图片在 obsidian 可以自动上传到 github 图床，并且转为 cdn jsdelivr 加速。如下图所示：</p><p><img src=\"https://cdn.jsdelivr.net/gh/goby-ao/picgo@main/img/20240606232431.png\"></p><p>本站源码：</p><ul><li><a href=\"https://github.com/goby-ao/yaofun.top/\" rel=\"noopener noreferrer\" target=\"_blank\">GitHub - goby-ao/yaofun.top: my blog</a></li></ul><p>参考与致谢：</p><ul><li><a href=\"https://immmmm.com/tags/%E6%8A%98%E8%85%BE/\" rel=\"noopener noreferrer\" target=\"_blank\">折腾 :: 木木木木木</a></li><li><a href=\"https://lillianwho.com/\" rel=\"noopener noreferrer\" target=\"_blank\">Lillian Who</a></li></ul><p><br></p><h3>折腾记录0 准备工作</h3><ul><li>能科学上网</li><li>github 账号、熟悉基本命令</li><li>cloudflare 账号</li><li>个人域名</li></ul><h3>1 本地初始化 hugo 博客</h3><p><strong>1.1 hugo 安装</strong></p><p>windows 上安装 hugo 需要先安装 go，在 macOS 上安装 hugo 比较简单可以自动安装所需依赖。</p><p><br></p><pre class=\"ql-syntax\" spellcheck=\"false\">brew update\nbrew install hugo\n</pre><p>Bash</p><p><strong>1.2 hugo 博客初始化</strong></p><p><br></p><pre class=\"ql-syntax\" spellcheck=\"false\">hugo new site yaofun.top\n</pre><p>Bash</p><p>例如 /home/yao/blog 下执行命令，会 生成 yaofun.top 子目录： /home/yao/blog/yaofun.top</p><p><strong>1.3 安装 hugo 主题</strong></p><p>我安装的是 hello-friend-ng 主题：</p><p><br></p><pre class=\"ql-syntax\" spellcheck=\"false\">$ git submodule add https://github.com/rhazdon/hugo-theme-hello-friend-ng.git themes/hello-friend-ng\n</pre><p>Bash</p><p><strong>1.4 本地运行与调试</strong></p><p>拷贝 theme 下的 exmapleSite 下的 content 目录和 .toml 配置到 hugo 根目录（/home/yao/blog/yaofun.top）</p><p>执行 hugo server 即可用 http://localhost:1313 查看预览效果，修改静态代码后它会自动重新编译构建。</p><p>你可以调试 hugo 的配置，折腾成自己满意的效果。</p><p><br></p><h3>2 自动化发布与部署</h3><p>本地博客搭建完毕后，可以开始配置自动化部署。</p><p><strong>2.1 博客及源码上传到 github 仓库</strong></p><ol><li>github 新建一个仓库 ，git clone 到本地</li><li>把博客源码（/home/yao/blog/yaofun.top/*&nbsp;）拷贝到本地 git 仓库里面</li><li>通过 git push 到 github</li></ol><p>至此可以通过 git 把源码推送到 github 仓库</p><p><strong>2.2 博客源码自动化编译部署</strong></p><ol><li>新建一个仓库，存放 hugo 生成的博客静态文件（这一步也可以用同仓库，不同分支）</li><li>配置 github action&nbsp;<a href=\"https://github.com/goby-ao/goby-ao.github.io\" rel=\"noopener noreferrer\" target=\"_blank\">github action</a>&nbsp;实现：</li><li class=\"ql-indent-1\">hugo 编译生成静态代码 ./public；</li><li class=\"ql-indent-1\">推送 ./public 静态代码到刚才新建的&nbsp;<a href=\"https://github.com/goby-ao/goby-ao.github.io\" rel=\"noopener noreferrer\" target=\"_blank\">github 静态文件仓库</a></li></ol><p><strong>2.3 cloudflare page 托管静态网站</strong></p><ol><li>cloudflare 在 workers &amp; pages 里面新建一个 page，指向静态代码的仓库</li><li>build 里面什么都不用配置，因为 github action 已经完成了 hugo 编译</li><li>配置自定义域名</li></ol><p>至此完成基本的自动化发布流程：</p><p>本地 -&gt; github 源码库 -&gt; github 静态仓库 -&gt; cloudflare page 托管</p><p><br></p><h3>3 图床与图床加速</h3><p>文本没问题了，还差一个图片如何展示，并且国内也能顺畅展示的问题。</p><p><strong>3.1 picgo + github 图床</strong>&nbsp;下载 picgo ，设置 github 图床，此步略过不表</p><p><strong>3.2 图床加速</strong>&nbsp;picgo 配置自定义域名，例如我的是：https://cdn.jsdelivr.net/gh/goby-ao/picgo@main 配置规则：github 用户名，仓库名，分支要换成自己的。默认图片在仓库的 img 目录。</p><p><br></p><h3>4 obsidian 配置</h3><p>以上工作做好之后，就可以配置 obsidian 了，实现拼图的最后一步 - 使用 obsidian 一键发布。</p><ol><li>obsidian 创建新的 vault ，地址为 hugo 源码目录</li><li>安装 obsidian 插件&nbsp;<em>git</em>：在 obsidian 中一键 commit 、push 代码</li><li>安装 obsidian 插件&nbsp;<em>Image Auto Upload</em>：实现贴图自动上传图床，生成链接</li><li>安装 obsidian 插件&nbsp;<em>Templater</em>&nbsp;：配置博客模板 header</li></ol><pre class=\"ql-syntax\" spellcheck=\"false\">---\ndate: &lt;% tp.file.creation_date(\"YYYY-MM-DD\") %&gt;\ntitle: &lt;% tp.file.title %&gt;\ntags: ['&lt;% tp.system.suggester(item =&gt; item, Object.keys(app.metadataCache.getTags()).map(x =&gt; x.replace(\"#\", \"\"))) %&gt;']\n---\n</pre><p>YAML</p><ol><li>安装 obsidian 插件&nbsp;<em>quickadd</em>&nbsp;：更便捷的创建博客文件</li></ol><p><br></p><h3>5 折腾美化</h3><p><strong>5.1 图片排版</strong></p><p>参考：<a href=\"https://immmmm.com/about-images-gird/\" rel=\"noopener noreferrer\" target=\"_blank\">Hugo 多图排版这样来：：木木木木木</a>&nbsp;在&nbsp;themes/hello-friend-ng/assets/scss/_single.scss&nbsp;里面加入以下 css 代码：</p><p><br></p><pre class=\"ql-syntax\" spellcheck=\"false\">.post-content p:has(&gt; img:nth-child(2)){column-count:2;column-gap:8px;margin:6px 0;}\n.post-content p:has(&gt; img:nth-child(3)){column-count:3;}\n.post-content p:has(&gt; img:nth-child(4)){column-count:4;}\n.post-content p:has(&gt; img:nth-child(5)){column-count:5;}\n.post-content p:has(&gt; img:nth-child(6)){column-count:4;}\n.post-content p:has(&gt; img:nth-child(2)) img{display:inherit;}\n.post-content p:has(&gt; img:nth-child(6)) img{margin-bottom:8px;}\n</pre><p>CSS</p><p>效果如下：</p><p><img src=\"https://cdn.jsdelivr.net/gh/goby-ao/picgo@main/img/20240325181403.png\"></p><p>实际显示：</p><p><img src=\"https://cdn.jsdelivr.net/gh/goby-ao/picgo@main/img/IMG_2019.jpeg\"><img src=\"https://cdn.jsdelivr.net/gh/goby-ao/picgo@main/img/IMG_1696.jpeg\"></p><p><strong>5.2 图片灯箱效果</strong></p><p>图片点击后灯箱效果，使用：<a href=\"https://tokinx.github.io/ViewImage/\" rel=\"noopener noreferrer\" target=\"_blank\">ViewImage.js - 2kb minimalist lightbox.</a></p><ol><li>下载&nbsp;view-image.min.js&nbsp;到 static/js/ 下</li><li>在 themes/hello-friend-ng/layouts/partials/javascript.html 下加入代码：</li></ol><p><br></p><pre class=\"ql-syntax\" spellcheck=\"false\">&lt;script src=\"/js/view-image.min.js\"&gt;&lt;/script&gt;\n&lt;script&gt;\n    window.ViewImage &amp;&amp; ViewImage.init('.content img');\n&lt;/script&gt;\n</pre><p>JavaScript</p><h3>6 其他问题</h3><p><strong>中文字数统计不准</strong></p><p>在 hugo.toml 里加入一行：hasCJKLanguage = true</p><p><br></p><h2>为什么要写博客 ？</h2><p>督促自己思考，沉淀，进步。在互联网上有一片属于自己的 Secret Garden。</p>","content_text":"博客荒废好久了！之前也陆陆续续使用过一些博客程序，要么发布部署有些麻烦，要么使用第三方服务不太稳定，一段时间就停止维护了。\n\n偶然的机会看到文章： obsidian 配合 hugo、cloudflare：让发布博客简单到不可思议，心动入坑，花了近一周的时间研究折腾，终于把基于\nobsidian 的博客写作与发布工作流搭建起来了，现在可以愉快的一键发布啦。\n\n从 0 到 1\n折腾踩坑，整个过程好似「晨兴理荒秽，带月荷锄归」，但没有陶渊明那样悠然自得。折腾的心累，年纪再大点肯定折腾不动的，这里首先强烈建议怕麻烦同学的劝退。\n\n\n\n\n\n博客方案\n\n折腾前我整理出自己的博客需求如下：\n\n * 简单快捷：使用 Obsidian 写完，一键发布\n * 稳定靠谱：减少第三方依赖，尽量使用靠谱的第三方服务，例如 github\n * 图片能够顺畅加载：之前直接使用 github 做图床，国内访问很慢\n\n参考一些大佬的配置，最终的选型如下：\n\n * Obsidian + obsidian git 插件 ：markdown 写作，obsidian git 插件自动上传 github\n * Hugo：静态网站构建工具\n * Github + Github Action ：源码托管，自动化编译（emmm，github 应该不会倒闭）\n * Cloudflare Page：静态网站托管 （也可以直接用 github page 托管）\n * Picgo + jsdelivr：基于 github 的图床 、cdn 加速\n\n最终达到的效果是： 在 obsidian 写文章，通过快捷键一件上传到 git 之后，自动构建发布。 图片在 obsidian 可以自动上传到 github\n图床，并且转为 cdn jsdelivr 加速。如下图所示：\n\n[https://cdn.jsdelivr.net/gh/goby-ao/picgo@main/img/20240606232431.png]\n\n本站源码：\n\n * GitHub - goby-ao/yaofun.top: my blog\n\n参考与致谢：\n\n * 折腾 :: 木木木木木\n * Lillian Who\n\n\n\n\n\n折腾记录0 准备工作\n\n * 能科学上网\n * github 账号、熟悉基本命令\n * cloudflare 账号\n * 个人域名\n\n\n1 本地初始化 HUGO 博客\n\n1.1 hugo 安装\n\nwindows 上安装 hugo 需要先安装 go，在 macOS 上安装 hugo 比较简单可以自动安装所需依赖。\n\n\n\n\nbrew update\nbrew install hugo\n\n\nBash\n\n1.2 hugo 博客初始化\n\n\n\n\nhugo new site yaofun.top\n\n\nBash\n\n例如 /home/yao/blog 下执行命令，会 生成 yaofun.top 子目录： /home/yao/blog/yaofun.top\n\n1.3 安装 hugo 主题\n\n我安装的是 hello-friend-ng 主题：\n\n\n\n\n$ git submodule add https://github.com/rhazdon/hugo-theme-hello-friend-ng.git themes/hello-friend-ng\n\n\nBash\n\n1.4 本地运行与调试\n\n拷贝 theme 下的 exmapleSite 下的 content 目录和 .toml 配置到 hugo\n根目录（/home/yao/blog/yaofun.top）\n\n执行 hugo server 即可用 http://localhost:1313 查看预览效果，修改静态代码后它会自动重新编译构建。\n\n你可以调试 hugo 的配置，折腾成自己满意的效果。\n\n\n\n\n\n2 自动化发布与部署\n\n本地博客搭建完毕后，可以开始配置自动化部署。\n\n2.1 博客及源码上传到 github 仓库\n\n 1. github 新建一个仓库 ，git clone 到本地\n 2. 把博客源码（/home/yao/blog/yaofun.top/* ）拷贝到本地 git 仓库里面\n 3. 通过 git push 到 github\n\n至此可以通过 git 把源码推送到 github 仓库\n\n2.2 博客源码自动化编译部署\n\n 1. 新建一个仓库，存放 hugo 生成的博客静态文件（这一步也可以用同仓库，不同分支）\n 2. 配置 github action github action 实现：\n 3. hugo 编译生成静态代码 ./public；\n 4. 推送 ./public 静态代码到刚才新建的 github 静态文件仓库\n\n2.3 cloudflare page 托管静态网站\n\n 1. cloudflare 在 workers & pages 里面新建一个 page，指向静态代码的仓库\n 2. build 里面什么都不用配置，因为 github action 已经完成了 hugo 编译\n 3. 配置自定义域名\n\n至此完成基本的自动化发布流程：\n\n本地 -> github 源码库 -> github 静态仓库 -> cloudflare page 托管\n\n\n\n\n\n3 图床与图床加速\n\n文本没问题了，还差一个图片如何展示，并且国内也能顺畅展示的问题。\n\n3.1 picgo + github 图床 下载 picgo ，设置 github 图床，此步略过不表\n\n3.2 图床加速 picgo 配置自定义域名，例如我的是：https://cdn.jsdelivr.net/gh/goby-ao/picgo@main\n配置规则：github 用户名，仓库名，分支要换成自己的。默认图片在仓库的 img 目录。\n\n\n\n\n\n4 OBSIDIAN 配置\n\n以上工作做好之后，就可以配置 obsidian 了，实现拼图的最后一步 - 使用 obsidian 一键发布。\n\n 1. obsidian 创建新的 vault ，地址为 hugo 源码目录\n 2. 安装 obsidian 插件 git：在 obsidian 中一键 commit 、push 代码\n 3. 安装 obsidian 插件 Image Auto Upload：实现贴图自动上传图床，生成链接\n 4. 安装 obsidian 插件 Templater ：配置博客模板 header\n\n---\ndate: <% tp.file.creation_date(\"YYYY-MM-DD\") %>\ntitle: <% tp.file.title %>\ntags: ['<% tp.system.suggester(item => item, Object.keys(app.metadataCache.getTags()).map(x => x.replace(\"#\", \"\"))) %>']\n---\n\n\nYAML\n\n 1. 安装 obsidian 插件 quickadd ：更便捷的创建博客文件\n\n\n\n\n\n5 折腾美化\n\n5.1 图片排版\n\n参考：Hugo 多图排版这样来：：木木木木木 在 themes/hello-friend-ng/assets/scss/_single.scss 里面加入以下\ncss 代码：\n\n\n\n\n.post-content p:has(> img:nth-child(2)){column-count:2;column-gap:8px;margin:6px 0;}\n.post-content p:has(> img:nth-child(3)){column-count:3;}\n.post-content p:has(> img:nth-child(4)){column-count:4;}\n.post-content p:has(> img:nth-child(5)){column-count:5;}\n.post-content p:has(> img:nth-child(6)){column-count:4;}\n.post-content p:has(> img:nth-child(2)) img{display:inherit;}\n.post-content p:has(> img:nth-child(6)) img{margin-bottom:8px;}\n\n\nCSS\n\n效果如下：\n\n[https://cdn.jsdelivr.net/gh/goby-ao/picgo@main/img/20240325181403.png]\n\n实际显示：\n\n[https://cdn.jsdelivr.net/gh/goby-ao/picgo@main/img/IMG_2019.jpeg][https://cdn.jsdelivr.net/gh/goby-ao/picgo@main/img/IMG_1696.jpeg]\n\n5.2 图片灯箱效果\n\n图片点击后灯箱效果，使用：ViewImage.js - 2kb minimalist lightbox.\n\n 1. 下载 view-image.min.js 到 static/js/ 下\n 2. 在 themes/hello-friend-ng/layouts/partials/javascript.html 下加入代码：\n\n\n\n\n<script src=\"/js/view-image.min.js\"></script>\n<script>\n    window.ViewImage && ViewImage.init('.content img');\n</script>\n\n\nJavaScript\n\n\n6 其他问题\n\n中文字数统计不准\n\n在 hugo.toml 里加入一行：hasCJKLanguage = true\n\n\n\n\n\n为什么要写博客 ？\n\n督促自己思考，沉淀，进步。在互联网上有一片属于自己的 Secret Garden。","date_published":"2024-10-04T23:59:39.484Z","_microfeed":{"is_audio":false,"is_document":false,"is_external_url":true,"is_video":false,"is_image":false,"web_url":"https://blog-ccino-cc.pages.dev/i/obsidian-N4KE5hrTVPH/","json_url":"https://blog-ccino-cc.pages.dev/i/N4KE5hrTVPH/json/","rss_url":"https://blog-ccino-cc.pages.dev/i/N4KE5hrTVPH/rss/","guid":"N4KE5hrTVPH","status":"published","itunes:episodeType":"full","date_published_short":"Fri Oct 04 2024","date_published_ms":1728086379484}}],"_microfeed":{"microfeed_version":"0.1.2","base_url":"https://blog-ccino-cc.pages.dev","categories":[],"subscribe_methods":[{"name":"RSS","type":"rss","url":"https://blog-ccino-cc.pages.dev/rss/","image":"https://blog-ccino-cc.pages.dev/assets/brands/subscribe/rss.png","enabled":true,"editable":false,"id":"7-6m9ozpyuG"},{"name":"JSON","type":"json","url":"https://blog-ccino-cc.pages.dev/json/","image":"https://blog-ccino-cc.pages.dev/assets/brands/subscribe/json.png","enabled":true,"editable":false,"id":"kFHio_oK78v"}],"description_text":"","copyright":"©2024","itunes:type":"episodic","items_sort_order":"newest_first"}}