<?xml version='1.0' encoding='UTF-8'?>
<?xml-stylesheet href="/rss/stylesheet/" type="text/xsl"?>
<rss xmlns:content='http://purl.org/rss/1.0/modules/content/' xmlns:taxo='http://purl.org/rss/1.0/modules/taxonomy/' xmlns:rdf='http://www.w3.org/1999/02/22-rdf-syntax-ns#' xmlns:itunes='http://www.itunes.com/dtds/podcast-1.0.dtd' xmlns:googleplay="http://www.google.com/schemas/play-podcasts/1.0" xmlns:dc='http://purl.org/dc/elements/1.1/' xmlns:atom='http://www.w3.org/2005/Atom' xmlns:podbridge='http://www.podbridge.com/podbridge-ad.dtd' version='2.0'>
<channel>
  <title>奇诺分享 | blog.ccino.cc - 重在分享</title>
  <language>zh-cn</language>
  <generator>microfeed.org</generator>
  <itunes:type>episodic</itunes:type>
  <itunes:explicit>false</itunes:explicit>
  <atom:link rel="self" href="https://blog-ccino-cc.pages.dev/rss/" type="application/rss+xml"/>
  <link>https://blog.ccino.cc</link>
  <itunes:author>奇诺分享</itunes:author>
  <itunes:image href="https://cdn-blog-ccino-cc.ccino.cc/blog-ccino-cc/production/images/channel-6ebae07c242a357bee27d74ca3e4b3ce.png"/>
  <image>
    <title>奇诺分享 | blog.ccino.cc - 重在分享</title>
    <url>https://cdn-blog-ccino-cc.ccino.cc/blog-ccino-cc/production/images/channel-6ebae07c242a357bee27d74ca3e4b3ce.png</url>
    <link>https://blog.ccino.cc</link>
  </image>
  <copyright>©2024</copyright>
  <item>
    <title>使用 Obsidian 一键发布博客</title>
    <guid>N4KE5hrTVPH</guid>
    <pubDate>Fri, 04 Oct 2024 23:59:39 GMT</pubDate>
    <itunes:explicit>false</itunes:explicit>
    <description>
      <![CDATA[<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
brew install hugo
</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
</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
</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">---
date: &lt;% tp.file.creation_date("YYYY-MM-DD") %&gt;
title: &lt;% tp.file.title %&gt;
tags: ['&lt;% tp.system.suggester(item =&gt; item, Object.keys(app.metadataCache.getTags()).map(x =&gt; x.replace("#", ""))) %&gt;']
---
</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;}
.post-content p:has(&gt; img:nth-child(3)){column-count:3;}
.post-content p:has(&gt; img:nth-child(4)){column-count:4;}
.post-content p:has(&gt; img:nth-child(5)){column-count:5;}
.post-content p:has(&gt; img:nth-child(6)){column-count:4;}
.post-content p:has(&gt; img:nth-child(2)) img{display:inherit;}
.post-content p:has(&gt; img:nth-child(6)) img{margin-bottom:8px;}
</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;
&lt;script&gt;
    window.ViewImage &amp;&amp; ViewImage.init('.content img');
&lt;/script&gt;
</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>]]>
    </description>
    <link>https://blog.ccino.cc/i/Use -obsidian- to publish a blog in one click</link>
    <itunes:episodeType>full</itunes:episodeType>
    <enclosure 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/" type="text/html"/>
  </item>
</channel>
</rss>