---
title: "All posts - Owen"
url: "https://www.owenyoung.com/archive?layout=list&page=49"
markdown_url: "https://www.owenyoung.com/archive.md?layout=list&page=49"
site: "Owen"
language: "zh-Hans"
page: 49
total_pages: 55
llms: "https://www.owenyoung.com/llms.txt"
skill: "https://www.owenyoung.com/skill.md"
mcp: "https://www.owenyoung.com/api/mcp"
public_mcp: "https://www.owenyoung.com/api/public/mcp"
public_api: "https://www.owenyoung.com/api/public/threads"
---

# All posts - Owen

*For AI assistants — Site overview: [llms.txt](https://www.owenyoung.com/llms.txt) · Author/agent guide: [skill.md](https://www.owenyoung.com/skill.md) · Public read-only MCP: https://www.owenyoung.com/api/public/mcp*

---

## 2022-08-08 · ud69u

以下这几个别名和函数节省了我至少一吨的时间。

```bash
function gg() { git commit -m "$*" -a }
function gp() { git commit -a -m "$*" && git push }
function ga() { git add . }
alias ll="ls -GF -l"
alias la="ls -GF -la"
alias gpull="git pull"
alias gpush="git push"
alias gd="git diff"
alias gs="git status 2>/dev/null"
alias gv="git remote -v"
```

_2022-08-08 · note_ — [HTML](https://www.owenyoung.com/ud69u) · [Markdown](https://www.owenyoung.com/ud69u.md)

---

## 2022-08-08 · 9gedx

每次看到中国明星离婚的消息，我在心里都暗暗为女方叫好，我不咱相信中国成功男明星能配得上女明星。普通中国男的已经够糟了，成功的男明星大多都是粪坑吧。

_2022-08-08 · note_ — [HTML](https://www.owenyoung.com/9gedx) · [Markdown](https://www.owenyoung.com/9gedx.md)

---

## 2022-08-08 · pfjop

成年后学了 2 样东西：1. 双拼输入法 2. 自己接网线水晶头

_2022-08-08 · note_ — [HTML](https://www.owenyoung.com/pfjop) · [Markdown](https://www.owenyoung.com/pfjop.md)

---

## 不用 U 盘在 Windows 10 上安装Ubuntu Server 22 双系统

这篇文章是一篇笔记，记录一下安装期间遇到的坑，不算是教程，因为我走了一遍流程之后决定放弃这样安装，还是乖乖的买一块新的 U 盘去安装系统，劝你也这样做（我为啥要这样装系统，是因为我的旧 U 盘是一个 360wifi 的 u 盘，试了用[refus](https://rufus.ie/en/),[ventoy](https://www.ventoy.net/en/faq.html)等工具创建引导 u 盘，电脑都无法启动这块 u 盘的引导系统，这才尝试无 U 盘安装）。

> 背景是：最近刚搬家，无意中找到一个 dp 的转接头，神奇的发现之前屏幕坏掉的 Thinkpad T450 笔记本可以外接到房东的大电视上显示，（之前拿到联想售后店，售后告诉我整个显卡都坏掉，外接显示屏也无法显示，我也就没尝试过），所以准备给这台旧笔记本额外安装一个 Linux 系统，用作家庭服务器，可以跑旁路由，和一些媒体中心等等。这样的需求最适合装一个 headless 系统，平时都通过 ssh 连接和操作，把废旧笔记本当作树莓派一样用。

我发现装系统的时候最能学到一些更底层的知识，我虽然是程序员，但还是有超多基本知识都不了解，通过这次装系统，又学了好多新知识。在查找教程的过程中，有一点感触很深，就是写教程的人，最好解释清楚每一步操作都干了啥，这样读者才能从中学到真正的东西，但是网络上有很多中文的教程就只是告诉你说这几行命令能解决问题，这就搞得人很虚。所以自己写教程或者笔记的时候，一定不要怕冗余，努力说清楚每一个操作实际上干了什么。

装完之后，总算理解了一点点电脑的启动流程，写了一篇笔记：[电脑的启动流程](/blog/booting)

<!--more-->

> 下面文章里提到的很多名词，我会默认你已经读过上面这篇操作系统启动的综述了，所以就不再重复解释。
>
> 这篇文章是靠回忆完成的，所以可能会有一些步骤的遗失，如果你遇到问题，欢迎帮助我一起编辑这篇文章。

## 1. 关闭快速启动

电源选项 -&gt; 选择电源按钮的功能 -&gt; 更改当前不可用的设置，取消勾选启用快速启动.这样电源按钮就恢复为单纯的电源按钮了。

> 快速启动是 Windows 把传统的完全关机模式，升级为“关机+休眠唤醒”的混合启动模式。在传统的关机模式中，执行关机命令后，Windows 会彻底结束正在运行的应用程序、停止系统服务、注销登录用户账户、关闭计算机电源，而不刷入缓存、写入文件。故下次开机时，所有资源项都必须重新启动一遍、全新加载、全新读取，因而在进入桌面后，仍会有一段的等待加载时间(体现在鼠标转圈圈)。而在“快速启动”模式下执行关机，Windows 8、8.1、10 等系统版本会将系统当前的运行状态(包括进程、服务、会话、内核等)写入到休眠缓存文件中，待下次开机时，系统便直接读取该休眠文件，并将其加载到内存，从而实现快速唤醒、快速恢复、快速启动，故等待时间较短，所以有些时候关机前没有关掉的窗口开机后可能会再次出现。

## 2. 转换分区格式 MBR 到 GPT

我的笔记本的主板是用的 UEFI，但是它的默认设置却用了 Legacy boot 的模式，磁盘也是使用 Master Boot Record (MBR)作为分区格式。这是一种过时的配置，所以第一步，我就把整个电脑的分区格式从 Master Boot Record (MBR)改为 GUID Partition Table (GPT) 格式，全面 UEFI 化。这一步其实很底层，有可能丢失数据，但是我的电脑啥都没有，所以我不担心这个问题，如果你有重要数据，请一定做好备份。我使用[傲梅分区助手](https://www.disktool.cn/)把整个磁盘转换为 GPT 格式，我只有一个磁盘。

![conver](https://media.jant.me/media/sit_01kmyfab3cfztrzn5qs9b80083/files/med_01kwtjjkrzfeza93rh8f8nx2ey.png)

转换完成之后，重启系统，按 F1 进入 UEFI 的 Boot 设置菜单,把 Boot Mode 改为 UEFI，同时确认 Security Boot 是关闭状态，CSM 也是关闭状态。

> Security Boot 开启后，uefi 将会用公钥验证操作系统是否由认证的厂商发型，当时好像只内置了 Windows，Ubuntu 的支持，所以其实我觉得爱折腾的人，家用电脑没必要开启这个选项
>
> CSM（兼容性支持模块）,因为我们全面使用 UEFI，所以关闭 CSM 的支持，CSM 用于支持 MBR 引导

![uefi](https://media.jant.me/media/sit_01kmyfab3cfztrzn5qs9b80083/files/med_01kwtjjnz5feza93s3zkckzsvv.jpg)

## 3. 磁盘划分

开机后，使用 Windows 的磁盘管理工具，新建一个 8G 左右大小的 FAT32 格式的分区，用于代替 U 盘，存放 Ubuntu 的系统镜像文件。

![disk](https://media.jant.me/media/sit_01kmyfab3cfztrzn5qs9b80083/files/med_01kwtjjra5feza93sp3bay20z7.png)

然后在[Ubuntu Server 的下载页面](https://ubuntu.com/download/server), 下载最新版的 Server 镜像文件，然后把镜像文件解压到这个分区里。注意是把根目录的所有文件解压进去，不带根目录

解压完成之后，我们需要修改一个 grub 的引导启动项参数, 找到`boot/grub/grub.cfg`文件，然后用记事本打开，找到以下行：

```bash
menuentry "Try or Install Ubuntu Server" {
	set gfxpayload=keep
	linux	/casper/vmlinuz  ---
	initrd	/casper/initrd
}
```

修改为：

```bash
menuentry "Try or Install Ubuntu Server" {
	set gfxpayload=keep
	linux	/casper/vmlinuz toram  ---
	initrd	/casper/initrd
}
```

我们添加了一个`toram`参数，这个参数告诉 grub 把整个 ubuntu 系统加载到内存中，这样我们就不依赖硬盘了，也就能在安装的过程中操作硬盘了。

## 4. 新建系统引导项

下载 [EasyUEFI](https://www.easyuefi.com/index-us.html) 软件，进入系统启动项管理，点击新建启动项，名字可以叫`ubuntuinstaller`,选择你刚新建的 Fat32 分区，引导文件选择`EFI -> BOOT -> grubx64.efi`，使用 grub 来引导，然后确定即可。这样就创建了一个启动盘，代替 U 盘。

## 5. 新建 ubuntu 的分区

接着再分出一个 80GB 左右的磁盘空间，用于安装 ubuntu 系统，具体操作是在磁盘管理里，先压缩 C 盘，压缩出大概 80G 的空间，然后把这个空间格式化为 nfts 格式

> 如果不格式化成 nfts 格式的话，ubuntu server 的安装程序无法发现未分配的磁盘，所以这一步先随便格式化一下，到时候安装的时候再让 ubuntu 安装程序格式化成 ext4 格式

## 6. 安装 ubuntu

重启电脑，按 F12 选择启动项，选择刚刚创建的`ubuntuinstaller`启动项启动，这时会进入 grub 的引导菜单，选择`Try or Install Ubuntu Server`,接下来就按照菜单里的提示一步步来，到了 disk 选择那一步要注意：

![disk](https://media.jant.me/media/sit_01kmyfab3cfztrzn5qs9b80083/files/med_01kwtjjtyffeza93t6pr48qt08.png)

这一步要选择 Custom Storage layout, 然后选择你刚创建给 ubuntu 的分区，进入`edit`菜单，`Format`选择`ext4`格式，Mount 选择`/`即可，其他的设置根据自己的喜好来就好。

## 7. 完成安装

我的电脑完成安装后，好像会丢失 windows 的 UEFI 一级引导项，但是 grub 作为二级引导程序， 会在这里加上 Windows 的引导，开机后按`esc`键会进入 grub 的系统选择菜单，在这里可以进入 Windows，然后可以再打开 EasyUEFI，好像打开一下，它就会修复一级系统引导了，这样之后按 F12 就可以选择不同的系统了。另外完成安装后，就可以删除磁盘里的 ubuntu 安装分区里。

## 8. 卸载 Ubuntu

卸载 Ubuntu 很简单，进入 Windows 系统后，直接删除 ubuntu 的分区磁盘，然后在 easyuefi 软件里也删除 ubuntu 的启动项即可。

_2022-08-07 · note_ — [HTML](https://www.owenyoung.com/blog/windows-10-ubuntu-22-dual-system-without-usb-flash-drive) · [Markdown](https://www.owenyoung.com/blog/windows-10-ubuntu-22-dual-system-without-usb-flash-drive.md)

---

## 笑话收集

收集笑话, 有的时候和外国人交流的时候，经常需要讲一些笑话，但是脑子里很少能立刻想到几个，在这记录一些。

<!--more-->

## 网站

- [笑话词典](http://xiaohua.cidiancn.com/leng/)
- [苏联笑话 Wiki](https://en.wikipedia.org/wiki/Russian_political_jokes)

## 笑话大全

> 苏联极权主义的基本信条：1. 党总是正确的。 2. 如果该党有错，请参照条件一。

> 一个年轻的共产主义者得意地宣称：“我们建立了一个没有富人的社会！”对此，一位老社会民主主义者摇摇头并低声说：“其实我们的本意是建立一个没有穷人的社会。”

> 民间传说将苏联人应遵循的生活准则概括如下：1、不用思考。2.
> 如果你在思考，就不要说话。3. 如果你在说话，就不要写下来。4.
> 如果你写了，就不要签名。5. 如果你签了它，就别对后果感到惊讶。

> 一位年轻人在工作时抱怨道：“这种政府真差劲儿！！！！！”结果被一位警察听到而遭逮捕。年轻人辩解说：“我根本没讲是哪个政府，你怎么可以随便逮捕我呢？”"
> 你少骗人，”警察咆哮道，“我在这里工作二十多年了，哪一个政府差劲我不会知道吗？”
>
> A young man complained at work, "This kind of government sucks!!!!" and was
> arrested by a police officer. The young man defended: "I didn't say which
> government it was, how could you arrest me casually?" "You don't lie," the
> policeman smiled, "I've worked here for more than 20 years, which government
> is bad，should I not know?"

> 勃列日涅夫在路上看到一个人扛着西瓜回家。他停下车，招呼那人，要那人把西瓜卖给他。“好吧，勃列日涅夫同志。”那人说，“您选一个吧。”,“可只有一个西瓜啊。”,“我们选您的时候就是这样。
>
> On the road, Brezhnev saw a man carrying a watermelon home. He stopped the car
> and greeted the man, asking him to sell him the watermelon. "Okay, Comrade
> Brezhnev." The man said, "You choose one.", "But there is only one
> watermelon.", "That's how we chose you.

> 问：苏联入侵捷克斯洛伐克是为了什么？答：为了寻找邀请他们介入的捷克斯洛伐克人民。

> 两个东德人民站在柏林墙附近聊天。一个问：“你觉得我们的政权如何？”另一个回答说：“和你的看法一样。”“这样的话，我就有责任逮捕你！”

> 问：当镇上有食物但乡下没有食物时，这意味着什么？ 答：左派，托洛茨基派的偏差。
> 问：当乡村有食物但镇上没有食物时，这意味着什么？ 答：是的，布哈里派的偏差。
> 问：当乡村没有食物，镇上没有食物时，这意味着什么？ 答：正确应用一般线路。
> 问：当乡村和城镇都有食物时，这意味着什么？ 答：资本主义的恐怖。

> 问：苏联真的有言论自由，就像美国一样吗？
>
> 答：是的。在美国，你可以站在华盛顿特区的白宫前，大喊“打倒罗纳德·里根”，这样你就不会受到惩罚。同样，你也可以站在莫斯科的红场大喊“打倒罗纳德·里根”，你不会受到惩罚。

> 问：美国宪法和苏联宪法有什么区别？他们都保障言论自由。

_2022-08-07 · note · Articles_ — [HTML](https://www.owenyoung.com/jokes) · [Markdown](https://www.owenyoung.com/jokes.md)

---

## [Ex-Muslims: 前穆斯林](https://en.wikipedia.org/wiki/Ex-Muslims)

_2022-08-02 · link · Articles_ — [HTML](https://www.owenyoung.com/exmuslims-qian-mu-si-lin) · [Markdown](https://www.owenyoung.com/exmuslims-qian-mu-si-lin.md)

---

## [荒诞帝国](https://laurivahtre.ee/empire-of-the-absurd/)

- 她问道：“但人们为什么要让自己被塞进开往西伯利亚的牛车里？他们为什么不报警？
- 一个年轻的共产主义者得意地宣称：“我们建立了一个没有富人的社会！”对此，一位老社会民主主义者摇摇头并低声说：“其实我们的本意是建立一个没有穷人的社会。”
- 对马克思来说，资产阶级应该被消灭，因为他是资产阶级。希特勒只是把“资产阶级”一词换成了“犹太人”。二者的“罪行”都是“客观的”，所需做的只是确定其种族或阶级。
- 马克思的基本缺陷，在我看来，是他的教义所指导的任何经济体都未能成功发展，也永远不会成功发展的原因，源于他根本的假设：消灭私人所有制会导致生产力爆发性增长，从而将一个国家的经济推向新的、难以想象的高度，这一假设纯属幻想。前所未有的生产力提升会把生产增加到几乎可以进行无限支出的水平（……）这种生产增长在任何消灭了私人所有制的地方都尚未被观察到，未来也肯定不会被观察到。许多客观事实都反对这种可能性，顺便说一句，包括所有资源不可避免的限制定律。资源总是有限的；没有什么可以被无限制地生产或消费。
- 共产主义是一个糟糕的思想，永远无法被妥善实现——因为它对人性的看法是错误的
- 另一个例子是，把一种源远流长的俄罗斯文化元素改造成共产主义荒诞之物——在苏联游行中抬着领袖肖像。在苏联各地，纪念十月革命周年时，中央委员会政治局每位成员的照片都必须在每一次有组织的游行中被抬着，不论是在塔林、塔什干还是莫斯科。不是一张合影，而是一张张单独的照片，每张都装在杆子顶端高高举着。这正是对俄罗斯东正教宗教游行中抬着圣像的照搬。当然，这些象征物并不是可敬的同志波德戈尔内、佩尔谢、苏斯洛夫、乌斯季诺夫、阿利耶夫等人的肖像，而是基督教的圣像。
- 事实确是如此；克里姆林宫只有在经济绝望地恶化后才开始关注实际结果。
- 在这里我们看到的是一种典型的东方专制，只不过这种专制自称为世界上唯一真正的民主。这无疑是苏维埃荒诞性的众多花朵之一。
- 在波罗的海三国的贪污腐败程度或多或少与欧洲其他地区相当。俄罗斯人就是无法相信这一点。一次在20世纪80年代初，一支由莫斯科派出的官方委员会受命调查苏联各地的大学，被派到一所爱沙尼亚大学，查找并解雇那些被指控接受暗中贿赂的教职人员。令他们大为懊恼的是，他们找不出任何一起贪污事件。完成报告后，委员会主席把大学的代表拉到一边，私下问他：“报告可以，不过我很好奇。你们是怎么做的，怎么把贪污做得这么巧妙，以至于我们查不出来？”大学代表耸了耸肩，像以前一样回答说，这种陋习在这里并不存在。主席在一次明显的非公开谈话中被喂了他认为是胡扯的话，却仍然没有被告知贪污是如何发生的，这让他颇感被冒犯。也许这件事一直困扰着他，直到生命的最后。
- “‘我们国家的生活很好’——那是我们小学歌本里的一句诗。我们从歌曲和报纸上学到我们的生活如此美好。但有一件事我小时候不明白：如果这里的生活这么好，而资本主义国家的生活这么糟——他们为什么有那么多漂亮的物品，而我们却什么都没有？”
- 好吧，有时我们会看到一些外国的目录或杂志。很难相信那些东西真的可以买到。课堂上我们曾开始讨论此事。老师于是试图向被资本主义迷住的孩子们解释真正的原因。她说事物根本不是我们所看到的那样。她很清楚，所有那些漂亮的物品只是为少数富人准备的；西方的普通工人买不起任何东西，生活在极度贫困中。她解释说，这就是为什么商品看起来虚幻地充足的原因——大多数人买不起东西，商品因此留在商店里。在苏维埃国，这种商品短缺则源于相反的原因——所有人都很富有并且有购买力，因此商品不会留在商店里。
- 尽管如此，大多数人，如前所述，从未对赤字的起因进行过太多思考。管理如此糟糕，资源浪费如此惊人，愚蠢和懒惰如此泛滥，人们不可能期待富足——这一点无需多想就很清楚。人们也适应了这种状况。他们学会了在商店里不去询问前面提到的那种熏香肠、白兰地或香蕉之类的东西。货架上的缺货从来不是什么新闻。真正能传为话柄、通过口耳相传的，是这些东西偶尔以有限数量出现的时候。那时，眨眼之间就会排起极长的队，人们会耐心地等上几个小时去买例如一顶兔皮帽子。据计算，仅苏联人民在排队中浪费的生产时间，就足以建立一个中等规模的国家，或者修建一条从地球到月球再返回的铁路。
- 一位爱沙尼亚女诗人描述了她在一次苏联时代招待会上一盘水果面前的两难处境，除了各种重要的党内人物外，还有一些作家和艺术家也被邀请了。怎么办？在这里吃一根还是带回家？她知道把它带回家不合适，但是……最终，经过一番挣扎她抓起一根香蕉塞进了手提包。她为从那些她憎恨的人那里偷窃感到非常尴尬，但她不想让她的孩子长大后从未尝过香蕉。在家里，当她的孩子把第一口这种新食物吐出来，说它是“粑粑”时，女诗人开始哭泣。为什么？因为这一切既屈辱又愚蠢。一个普通的苏联男人或女人究竟做错了什么，竟至于在那数以千万计的石油收入中——这些收入足以维持整个古巴乃至世界上数十个共产党（更不用说巨额的军费开支）——竟连一根香蕉都没有提供？
- 1982 年，爱沙尼亚教授乌诺·梅雷斯特（Uno Mereste）有幸因公前往匈牙利出差。匈牙利并没有自由市场制度，但其经济显著比苏联的更为正常。他的妻子随信寄来了以下购物清单：\[...\] 后来，在自由市场社会生活多年后，教授在一本书的书页之间发现了那张清单，惊讶地读了起来。“还有哪个国家，会有教授要去外国讲学时，被他的妻子列出这样的愿望清单？这听起来像是精神病！为什么不在你家乡附近的商店里去买那些等待购买的普通小玩意儿呢？”
- 莫斯科是整个苏联唯一一家有时能买到缝纫机针的商店。有一次，我学生时期必须去莫斯科，也被拜托顺便去那家店看看。于是我坐上一辆拥挤的公交车，去了给我的地址。不幸的是，我从远处就能看到店门前的招牌写着“我们没有针”。当巴士上约有一半的人看到那块牌子时，发出令人心碎的哀叹。他们都是为了缝针来那的；谁知道他们从多远赶来的。
- 在苏联解体前的那些年，我的另一位熟人曾给一个住在西方的表亲写信，请他邮寄手纸来。（我们在上世纪70年代就学会用手纸代替报纸，但这后来成了稀缺品。）那位外方表亲回信说：“如果你不告诉我是要黄色、浅蓝、粉色还是绿色的；单层还是双层；以及卷子的尺寸，我就不能寄手纸给你。”
- 民间传说将苏联人应遵循的生活准则概括如下：1、不用思考。2. 如果你在思考，就不要说话。3. 如果你在说话，就不要写下来。4. 如果你写了，就不要签名。5. 如果你签了它，就别对后果感到惊讶。

_2022-07-29 · link · Articles_ — [HTML](https://www.owenyoung.com/blog/links/2022-07-29-3) · [Markdown](https://www.owenyoung.com/blog/links/2022-07-29-3.md)

---

## [德国与全球化的终结](https://www.spiegel.de/international/world/germany-and-the-end-of-globalization-prosperity-under-pressure-a-4f0b98ce-a2a5-4889-8375-d0dcf64cee2c)

- 全世界民主国家的数量正在稳步减少，专制国家注册的专利比西方多。一个新时代正在到来-它可能会对我们的工作、金钱和生活产生巨大影响。
- 贝莱德（Blackrock）是世界金融巨头中的巨头，拥有超过 10万亿美元，这个数字几乎是德国国内生产总值（GDP）的三倍。芬克确信，国际公司将退出一些国家。不仅因为经济风险，还因为道德风险。“今天的公司必须在一个非常不同的层面上面对政治和社会问题，”。他确实列举了一些可能从这种转变中受益的国家。例如，墨西哥和巴西。生产成本较低，但人权仍然在很大程度上得到尊重的国家。
- 这位总理如何看待即将到来的世界，可以从他邀请参加最近 G-7 峰会的其他客人以及其他六个主要工业化国家和欧盟（印度，印度尼西亚，南非，塞内加尔和阿根廷）中看到。来自三大洲的五个国家 - 塞内加尔总统 Macky Sall 也是非洲联盟的代表，非洲联盟有 55 个成员国。

_2022-07-29 · link · Articles_ — [HTML](https://www.owenyoung.com/blog/links/2022-07-29-2) · [Markdown](https://www.owenyoung.com/blog/links/2022-07-29-2.md)

---

## [人类愚蠢的基本法则](https://www.speedtest.net/)

1. 不可避免地，每个人都低估了流通中的愚蠢个体数量。
2. 某个人愚蠢的概率与该人的任何其他特征无关。
3. 人类分为四个基本类别：无助者、聪明人、土匪和愚蠢的人, 愚蠢的人是给另一个人或一群人造成损失的人，而他自己却没有获得任何收益，甚至可能遭受损失。
4. 不愚蠢的人总是低估愚蠢个体的破坏力。特别是不愚蠢的人经常忘记，在任何时候，任何地点，在任何情况下，与愚蠢的人打交道和/或交往总是被证明是一个代价高昂的错误。
5. 愚蠢的人是最危险的人,一个愚蠢的人比一个土匪更危险。
6. [hn 讨论](https://news.ycombinator.com/item?id=32264942)

_2022-07-29 · link · Articles_ — [HTML](https://www.owenyoung.com/blog/links/2022-07-29-1) · [Markdown](https://www.owenyoung.com/blog/links/2022-07-29-1.md)

---

## [css 实现嵌套的 a 标签](https://codepen.io/pwkip/pen/oGMZjb)

_2022-07-25 · link · Articles_ — [HTML](https://www.owenyoung.com/blog/links/2022-07-25-6) · [Markdown](https://www.owenyoung.com/blog/links/2022-07-25-6.md)

---

## [为什么过去 10 年的美国人生活是独一无二的愚蠢 - twitter 转发按钮的发明](https://www.theatlantic.com/magazine/archive/2022/05/social-media-democracy-trust-babel/629369/)

- [反驳：我们的问题不是程序性的](https://www.city-journal.org/our-problems-arent-procedural)
- [Twitter 从未创造世界](https://scholars-stage.org/the-world-that-twitter-never-made/)

_2022-07-25 · link · Articles_ — [HTML](https://www.owenyoung.com/blog/links/2022-07-25-5) · [Markdown](https://www.owenyoung.com/blog/links/2022-07-25-5.md)

---

## [用 Docker 来本地构建](https://matt-rickard.com/non-obvious-docker-uses/)

_2022-07-25 · link · Articles_ — [HTML](https://www.owenyoung.com/blog/links/2022-07-25-4) · [Markdown](https://www.owenyoung.com/blog/links/2022-07-25-4.md)

---

## [同在一个岛上，多米尼加为什么比海地富裕的多？](https://www.thefitzwilliam.com/p/hispaniolas-great-divergence)

_2022-07-25 · link · Articles_ — [HTML](https://www.owenyoung.com/blog/links/2022-07-25-2) · [Markdown](https://www.owenyoung.com/blog/links/2022-07-25-2.md)

---

## [Lisp 如何成为上帝自己的编程语言](https://twobithistory.org/2018/10/14/lisp.html)

_2022-07-25 · link · Articles_ — [HTML](https://www.owenyoung.com/blog/links/2022-07-25-1) · [Markdown](https://www.owenyoung.com/blog/links/2022-07-25-1.md)

---

## Adding search to zola blog with meilisearch deployed on Mogenius

I deployed [Meilisearch](https://meilisearch.com/) on my VPS [a couple of days ago](/blog/add-search), but I'm panic, because I mess up my VPS a lot, and I rebuild my VPS a lot, so it's not a stable environment to deploy meilisearch. So I started to browse [free-for-dev](https://www.trackawesomelist.com/ripienaar/free-for-dev/), see if there are some good(and cheap) solutions for me. I saw this:

> [mogenius](https://mogenius.com/home) - A code-to-cloud platform to easily deploy any service, from static website to advanced microservice architectures. mogenius comes with fully managed hyper-scaling cloud resources, Kubernetes, CI/CD and security from Cloudflare. Free tier includes 1 CPU core, 2 GB RAM, 10 GB traffic, 4 GB SSD persistent storage.

**The main point:**

- Free tier includes 1 CPU core, 2 GB RAM, 10 GB traffic, 4 GB SSD persistent storage.
- from static website to advanced microservice architectures.

I think it's enough for my blog's search index.

<!--more-->

[Mogenius](https://mogenius.com/home) said they "from static website to advanced microservice architectures", and they also have a decent plan for free tier. I decided to try it out. After completing the registration, it requires a mandatory mobile number verification. It's a bit annoying, but I'm glad to have a free tier, and it's a good way to avoid abuse. (There is a bug when you verify your mobile number, I'am using firefox, it seems the country code select can not show list correctly, so I just change a vpn to fix it. (maybe I should use chrome to test it, I almost give up because of this bug))

For those who want to see the final results, here is the final result:

![meilisearch](https://media.jant.me/media/sit_01kmyfab3cfztrzn5qs9b80083/files/med_01kwtj8rf4feza93b0rn9dyt0a.png)

Let's see how to set it up:

## Step 1: Create cloudspace

Just click ADD button, and fill in the form.

## Step 2: Create a new servicee

Enter to the cloudspace, and click the add button to create a new service with `Use a template`, and search `meilisearch`

## Step 3: Configure the service

1. Fill the servicename, for me I just type `meilisearch`
2. Connect your github account(you can give it only selected repo permissions, you must selected at least one repo, it can be any public repo)

   Screenshot: ![0](https://media.jant.me/media/sit_01kmyfab3cfztrzn5qs9b80083/files/med_01kwtj8v1yfeza93bpac5bwrb4.png)
3. Click `Add repository`, input the repo name, I input it as `meili`, and with `public` permission.

   Screenshot:

   ![1](https://media.jant.me/media/sit_01kmyfab3cfztrzn5qs9b80083/files/med_01kwtj8xaxfeza93c4ndt1848b.png)
4. set resources limit (if needed, the default value is a recomendation from Mogenius).
5. set environment variables:
   1. add `MEILI_MASTER_KEY` as key vault to protect your master key. (Click `create new secret` to fill the secret)
   2. the following environment variables can be plain text type.
      ```bash
      MEILI_NO_ANALYTICS=true
      MEILI_ENV=production
      ```
   
      All environment options are [here](https://docs.meilisearch.com/learn/configuration/instance_options.html#environment)

   Screenshot:

   ![2](https://media.jant.me/media/sit_01kmyfab3cfztrzn5qs9b80083/files/med_01kwtj8znnfeza93cgwghvy7mb.png)
6. optional, set custom domain. I set it to `meili.owenyoung.com`, I set a CNAME record `meili.owenyoung.com` to `meilisearch-prod-meilisearch-r4efxz.mo2.mogenius.io`, you will get the endpoint after the service created.

   Screenshot:

   ![3](https://media.jant.me/media/sit_01kmyfab3cfztrzn5qs9b80083/files/med_01kwtj928sfeza93d7cwv4p7nb.png)
7. Then, click the `Create Service` button. It may take 1 minute to build and deploy the service.

## Step 5: Get your meilisearch admin key, and user key

After the service is created, the meilisearch is ready to use, you can visit [https://meili.owenyoung.com/](https://meili.owenyoung.com/) to test if everything is worked fine. At this moment, the default meilisearch template version is [`v0.27.0rc1`](https://docs.mogenius.com/services/various/meilisearch), the following is the success output:

```json
{ "status": "Meilisearch is running" }
```

You need to run the bash script to get the admin key and user key:

```bash
curl \
  -X GET 'https://meili.owenyoung.com/keys' \
  -H "Authorization: Bearer you-master-key" \
  | json_pp
```

We'll use them in the next step.

## Step 6: Setup doc-scraper

We need to build search index after every updates of our blogs, I use Github Actions to build my blog, so I just add a job after the site is deployed. We'll use [docs-scraper](https://github.com/meilisearch/docs-scraper) to scrape our whole site with `sitemap.xml` file. [docs-scraper](https://github.com/meilisearch/docs-scraper) will help us to build heading and content level search index, it'll bring the best search experience for our readers.

> The current [docs-scrape is only adapted with `0.27.x`](https://github.com/meilisearch/docs-scraper#-compatibility-with-meilisearch), at this moment, the latest meilisearch version 0.28 is not supported, I have submitted [an issue](https://github.com/meilisearch/docs-scraper/issues/231), so the default Mogenius meilisearch template version `0.27.0rc1` is fine, we can also upgrade it to `v0.27.2`.(I have done this by change the [Dockerfile](https://github.com/theowenyoung/meili/blob/main/Dockerfile), Mongenius will monitor the updates, and automatically deploy the updates)

See the [`.github/workflows/build.yml`](https://github.com/theowenyoung/blog/blob/main/.github/workflows/build.yml)

```yaml
name: Deploy Site
on:
  workflow_dispatch:
  push:
    branches:
      - main
jobs:
  build-deploy:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - run: make install
      - name: Build Site
        run: make build
      - name: Deploy
        uses: peaceiris/actions-gh-pages@v3
        with:
          publish_dir: ./public
          github_token: ${{ secrets.GITHUB_TOKEN }}
  scrape-and-build-search-index:
    needs: build-deploy
    runs-on: ubuntu-latest
    steps:
      # wait github pages publish
      - run: sleep 1m
      - uses: actions/checkout@v3
      - name: Run docs-scraper
        env:
          HOST_URL: "https://meili.owenyoung.com"
          API_KEY: ${{ secrets.MEILISEARCH_API_KEY }}
          CONFIG_FILE_PATH: ${{ github.workspace }}/meilisearch-docs-scraper-config.json
        run: |
          docker run -t --rm \
            -e MEILISEARCH_HOST_URL=$HOST_URL \
            -e MEILISEARCH_API_KEY=$API_KEY \
            -v $CONFIG_FILE_PATH:/docs-scraper/config.json \
            getmeili/docs-scraper:v0.12.2 pipenv run ./docs_scraper config.json
```

`MEILISEARCH_API_KEY` will be the admin key from the previous step.

[`meilisearch-docs-scraper-config.json`](https://github.com/theowenyoung/blog/blob/main/meilisearch-docs-scraper-config.json) will be placed in the root of the repository, and it will be used by `docs-scraper` to scrape the site. Here is my config file:

```json
{
  "index_uid": "owen-blog",
  "sitemap_urls": ["https://www.owenyoung.com/sitemap.xml"],
  "start_urls": [""],
  "scrap_start_urls": false,
  "stop_urls": [
    "https://www.owenyoung.com/categories/",
    "https://www.owenyoung.com/tags/",
    "https://www.owenyoung.com/en/tags/",
    "https://www.owenyoung.com/en/categories/",
    "https://www.owenyoung.com/pages/",
    "https://www.owenyoung.com/en/pages/"
  ],
  "selectors": {
    "lvl0": {
      "selector": ".detail-page .p-category",
      "default_value": "Random"
    },
    "lvl1": {
      "selector": ".detail-page .p-tags",
      "default_value": "Notes"
    },
    "lvl2": ".detail-page .entry-title",
    "lvl3": ".e-content h2",
    "lvl4": ".e-content h3",
    "text": ".e-content p, .e-content li"
  },
  "strip_chars": " .,;:#",
  "min_indexed_level": 2,
  "custom_settings": {
    "synonyms": {
      "js": ["javascript", "nodejs"]
    },
    "stopWords": ["一", "的", "是"]
  }
}
```

> Cause I'm using Chinese and English, so I added [a lot of stop words of Chinese.](https://github.com/theowenyoung/blog/blob/main/meilisearch-docs-scraper-config.json)

Then the Github Actions workflow will run `docs-scraper` to scrape the site after the site is deployed.

## Step 7: Setup the frontend

See my [search template](https://github.com/theowenyoung/blog/blob/main/templates/search.html), basically, you need to include the [docs-searchbar](https://github.com/meilisearch/docs-searchbar.js) css and js, and add an `<input type="search" id="search-bar-input" placeholder="Search" />` to whereever you want to include the search bar. And add the following script to init:

```js
docsSearchBar({
  hostUrl: "https://meili.owenyoung.com",
  apiKey: "your-user-api-key",
  indexUid: "owen-blog",
  inputSelector: "#search-bar-input",
});
```

## Conclusion

You can see the all source code on [my blog source code](https://github.com/theowenyoung/blog).

As a programmer, it's not a big deal to setup those things with [mogenius](https://mogenius.com/home), sometimes their UI prompts are not very friendly, for example:

1. Firstly, I tried to create meilisearch without the template, the git address I entered at the beginning was `https://github.com/meilisearch/meilisearch`, then I can't create the service, the error message is: `This field is required.`, finally I tried another git url with suffix `.git`, then the form is valid, and I can choose the git branch. I don't know why they don't allow me to choose a tag branch, only the normal branches are allowed, luckily, Meilisearch has [one normal release branch](https://github.com/meilisearch/meilisearch/tree/release-v0.27.2), so I can choose it.
2. Their log UI is broken on Firefox browser, the edge browser is okay.
3. Even in Edge browser, the CI/CD monitor UI is broken, with an always refreshed page.

> Update: 2. it's not their fault, it's my default broswer settings that disabled the canvas rendering.

I don't know if they will offer a config file to setup those form, like `vercel.json` or `netlify.toml`, if so, it'll be easy for other non-programmers to setup those things.

Finally, I'm appreciate that they can offer a so decent free plan, I hope I don't need to migrate it to another service. Let's see.

_2022-07-17 · note_ — [HTML](https://www.owenyoung.com/blog/adding-search-to-zola-blog-with-meilisearch-deployed-on-mogenius/index-en) · [Markdown](https://www.owenyoung.com/blog/adding-search-to-zola-blog-with-meilisearch-deployed-on-mogenius/index-en.md)

---

## 2022-07-13 · ym0rz

想做一个 telegram bot，我分享给它链接，然后可以点击他的整理功能，按天，或按星期的排列好一个组合，这样就可以辅助我记录今天或本周阅读了什么，然后再手动转移到笔记里。

_2022-07-13 · note_ — [HTML](https://www.owenyoung.com/ym0rz) · [Markdown](https://www.owenyoung.com/ym0rz.md)

---

## 2022-07-13 · h79ve

如果你在家里还有马桶盖困扰的话，有一个很简单的办法，就是所有人都蹲下尿尿，这对男士来说是一个不成比例的微小付出。我这样做已经 5 年了，现在我已经不习惯站着尿尿了。

_2022-07-13 · note_ — [HTML](https://www.owenyoung.com/h79ve) · [Markdown](https://www.owenyoung.com/h79ve.md)

---

## 2022-07-13 · uthkf

最近把主力浏览器换成了[librewolf](https://librewolf.net/),火狐的 fork 版，基本上是一个比火狐更激进，更注重隐私的版本。删除了绝大多数火狐自己的东西比如 Pocket，和遥测等，以及一份默认隐私的配置。既可以充分享受火狐的插件，又能更隐私的使用它。我最喜欢火狐的功能是容器功能，这样就可以在一个窗口下，不同的 tab 使用不同的容器登录不同的小号，容器之间不共享 Cookie. 但是非主流浏览器的一大痛点就是缺失网页翻译功能，所以我还是把 Edge 作为备用浏览器，在需要翻译网页的时候切换过去。

_2022-07-13 · note · 1 reply_ — [HTML](https://www.owenyoung.com/uthkf) · [Markdown](https://www.owenyoung.com/uthkf.md)

---

## 2022-07-13 · wpnj7

两个人有两个人好处，一个人也有一个人的好处。在家办公的情况下，两个人必须独立分开办公才行（公司同理）。一起办公无法提高效率，也会限制很多东西，比如A想要语音聊天，或者外放音乐，外放教程等等等等。但是我也不是很支持公司的远程办公，我认为员工应该有独立办公室，同时也应该有很快能聚集的大厅，这样效率才能最大化。

_2022-07-13 · note_ — [HTML](https://www.owenyoung.com/wpnj7) · [Markdown](https://www.owenyoung.com/wpnj7.md)

---

## 通过创建 dotfiles, 我终于拥有了一个 web3 身份

作为技术人员,我对 web3 最大的障碍是创建一个 web3 身份并体面的保存下来。一个 web3 身份实在太重大了，我必须能良好的管理我的 web3 私钥，我我才有信心创建它，不然我怀疑我的整个 web3 世界只会建立在一个岌岌可危的根基上。

<!--more-->

我之前一直在用人脑管理我的密码，所以我不在任何地方记录我的密码。而由于我没有地方去体面的记录密码，而我的人脑又无法记住一个那么长的私钥，所以我一直对创建一个 web3 身份很害怕。

## 为什么不用密码管理器？

简单的答案是：没有契机。密码管理器一直给我一种很贵很复杂，然后还全是 GUI 界面(通过研究各种密码管理工具，证明这是一个错误的印象)，而我喜欢纯文本工具，我喜欢用简单的工具。所以在此之前我一直使用一套可以用人脑计算的密码模型来决定我的密码，这使得我在每个网站每个账户的密码都不一样，这样我就不需要太担心哪家密码有泄露。这一套基本运行良好，但是我内心一直希望哪天可以有一套更科学的密码管理器来整理我的各种账户，我目前这套靠人脑的密码管理只适合我主动创建的账户，它不适合各种工具生成的 Token, ssh key, 一个 web3 身份，或者是一个双重因素验证的恢复码，这些东西没法靠人脑，一定需要放在某个地方存起来，或者打印出来放在某个地方。

为什么没有契机去做呢？**因为我的数字花园很混乱**。

定义一个人的数字花园混乱不混乱只需要看一点，那就是你在重装你的电脑系统后，能否体面地把自己的系统成恢复原样？（利用全盘备份的方式把系统恢复成和之前一模一样的在我看来并不体面，这种方式的恢复只是治标，隐藏在冰面之下的是一个不可重现的巨大黑盒。所以这种方式只能作为一种方便的备份手段，而不能成为数字花园的根基）。当然如果你连全盘备份都没有的话，那你的数字花园可能算是危房了。

在这个意义上，[NixOS 系统](https://nixos.org/)算是可重现系统的天花板了，它的整个系统的核心设计理念就是可重现，可配置。安装NixOS系统，其实就是根据你的配置文件生成出来的，所以，同样的配置，永远都能构建出一模一样的系统，这简直太适合完美主义者了。你可以看下[一个 nixos 全系统的配置文件](https://github.com/gvolpe/nix-config)，这就是整个系统。

## 一个契机的诞生

前段时间，我需要在自己的 macbook pro 上临时装一个 windows 系统（银行，政府，u 盾，驱动相关），本来我也不想动原有的系统，所以我就尽我所能把我总共就 256G 的存储清出来 95 个 G（我正常情况下电脑剩余空间通常都是 20G 以下），然后开始使用苹果的系统助手新建 windows 系统，结果有一个该死的错误`An error occurred while copying the Windows installation files`阻止了它，我开始尝试网上提到的各种办法，30分钟后，苹果系统还是会告诉我一模一样的错误。

**所以只能祭出最鲁棒的方法了，重装 macOS 系统，然后再安装 windows 系统**

**但是，我敢这么做吗？我会不会有什么重要的东西忘记备份？之后要花多久重新恢复我的系统？**

这让我下定决心，决定花大量的精力去重建我的数字花园根基，力求我的数字花园变得轻量，可重现，可持续化。这和我的博客一样，都属于值得用一生的时间去维护的一个东西。

## Dotfiles

随后我了解到一个东西叫做 [Dotfiles](https://dotfiles.github.io/),简单的来说，这个 dotfiles就是管理你整个系统的配置文件的集合。

> 为什么叫 Dotfiles，因为类 unix 系统里习惯把配置文件用 dot 开头的文件名命名，如`.gitignore`,就是 git 的忽略配置文件，dot 开头的文件在系统中是默认隐藏的。所以如果有一个文件夹存放你全部的配置文件，那大家习惯上叫这个文件夹为`dotfiles`. 关于如何组织自己的 dotfiles 文件，有非常多的方式，辅助工具，[Dotfiles](https://dotfiles.github.io/) 就是一个很好的指引。

> 如果我没有进入这个新领域，我永远都不会知道光 github 上就有[17 万人](https://github.com/search?q=dotfiles)在公开他们的 dotfiles 文件

**在我看来使用 dotfiles 文件主要有 3 个好处：**

1. 随时随地轻量级的重现你的环境
2. 可以在本地删除某个工具，然后在想恢复的时候，无痛恢复这个工具
3. 现实中有人把自己房子打理的特别好，分类特别科学，当我们在数字世界中做了类似的整理之后，会对整个数字世界的体验变得非常的有信心，也可以帮助你了解很多软件的运行机制。

从[这个页面看](https://dotfiles.github.io/utilities/)，至少有 24 个工具可以帮你管理 dotfiles 文件，[chezmoi](https://chezmoi.io)可能是其中最全面的工具，但是我最终选择了[一个比较小众的 rust 编写的二进制工具 Comtrya](https://github.com/comtrya/comtrya)，因为我想尽可能维持 dotfiles 管理工具的轻量级，不想过度复杂化 dotfiles，这个工具的配置大概长这样(`ssh/ssh.yml`)：

```yaml
actions:
  - action: file.copy
    from: config
    to: "{{user.home_dir}}/.ssh/config"
    template: true
  - action: file.link
    source: id_ed25519.pub
    target: "{{user.home_dir}}/.ssh/id_ed25519.pub"
```

这是我的对 ssh 配置文件的动作配置，用`yaml`语言配置，是[ansible](https://www.ansible.com/)工具的非常轻量级的替代。这几行配置告诉 comtrya 把指定的配置文件复制或者软链接到该去的地方，同时我在复制的过程还使用了模版，因为我在`config`配置文件里对 macos 加了一点小小的东西`UseKeychain yes`：

```bash
Host *
  AddKeysToAgent yes
  IdentityFile ~/.ssh/id_ed25519{% if os.name=="macos"%}
  UseKeychain yes{% endif %}
```

这样之后，我的 ssh 配置就可以在 macos 和 linux 系统上通用了。

我最终的全部[dotfiles](https://github.com/theowenyoung/dotfiles)我已经放在 github 上了。整体的结构大概如下：

```bash
├── modules
│   └── zsh
│       ├── change_zsh_as_default_shell_debian.sh
│       ├── files
│       │   ├── alias_debian.zsh
│       │   ├── general_config.zsh
│       │   ├── includes
│       │   │   ├── 1_env.zsh
│       │   │   ├── 2_path.zsh
│       │   │   ├── 3_function.zsh
│       │   │   ├── 4_aliases.zsh
│       │   ├── path_macos.zsh
│       │   ├── zshenv.zsh
│       │   └── zshrc.zsh
│       ├── install_zsh_debian.sh
│       └── zsh.yml
├── private
│   ├── keepassxc
│   │   ├── dev.kdbx
│   │   ├── high.kdbx
│   │   └── main.kdbx
│   ├── ssh
│   │   ├── files
│   │   │   ├── config
│   │   │   └── id_ed25519.pub
│   │   └── ssh.yml
└── scripts
    ├── 0_install_pre_required_modules_for_debian.sh
    ├── 1_configure_macos.sh
    ├── 1_install_required_modules_for_debian.sh
    ├── 2_import_dotfiles_debian.sh
    ├── 2_install_required_modules_macos.sh
    ├── 3_import_dotfiles_macos.sh
    ├── 4_install_modules_macos.sh
    ├── env.sh
    ├── import_ssh_key.sh
    ├── import_temp_env.sh
    ├── link_all.sh
    ├── test.sh
    └── unlink.sh
```

其中`modules`存放所有的模块的配置，我讨厌分类，所以`macos`的相关配置也是其中的一个模块。还有一个`private`文件夹，这里面放我觉得不便公开的模块的配置（但也不包含任何明文密码），比如说 ssh 的 config，caddy 的 config Caddyfile，以及密码管理器 [keepassxc](https://github.com/keepassxreboot/keepassxc)中加密后的文件。我把 private 单独在 github 上设置了一个私有仓库，然后克隆在 dotfiles 仓库里，并在 dotfiles 仓库里忽略这个文件夹。

[keepassxc](https://github.com/keepassxreboot/keepassxc)是我最终选用的密码管理器，开源，易用，且久经考验。同时拥有 GUI 客户端，以及命令行客户端，可以很好的集成在我的 dotfiles 工作流里，同时 GUI 也可以方便的和浏览器等集成以及方便地编辑密码。这是一个完全本地的密码管理器，不依赖任何中心，你所有的密码都存放在一个加密后的文件,GUI 界面大概长这样，这是编辑某个密码的页面：

![keepassxc-edit](https://media.jant.me/media/sit_01kmyfab3cfztrzn5qs9b80083/files/med_01kwtjpbspfeza94dpdxz64ct9.png)

我总共使用 3 个文件存放我的密码：

```bash
high.kdbx
main.kdbx
dev.kdbx
```

其中`high.kdbx`是我的最高级的密码，比如银行密码，支付密码等，`main.kdbx`是我其他主要密码，比如 twitter，github 等，Like this:

```bash
twitter/
github/
hacker_news/
Microsoft/
GPG/
servers/
tools/
amazon/
ifttt/
IRC/
```

而`dev.kdbx`是我在各种开发服务器中会用到的密码，包括 token, 环境变量，ssh key 等,like this:

```bash
youdao_translate_secret
ssh/
github/
cloudflare/
ifttt/
telegram/
envs/
```

这三个密码文件都有不同的主密码，这三个主密码可以说是我人生最重要的秘密了，理论上这 3 个密码是我需要记住的全部密码了。

有了这个密码管理器，我的 dotfiles 文件的最重要的根基就搭建好了，我主要在 dotfiles 文件里使用 shell 脚本来管理所有的软件安装（顺便学习了一直想学习的`bash`脚本语言），每个module(比如窗口管理器[tmux](https://github.com/tmux/tmux)) 下面都有一个类似`install_tmux_macos.sh`的脚本。然后还有一个`tmux.yml`的文件去告诉[Comtrya](https://github.com/comtrya/comtrya)去执行复制文件到对应 module 的配置文件夹所在地。`scripts`文件夹放一些集合的脚本，比如一次性安装所有的必要软件的脚本，这里面的脚本一般来说是调用 modules 里已有的脚本。

**所以，当我现在有个新电脑，我的初始化流程将会是这样：**

1. 安装 xcode 的开发者工具（这样才能用 git 等命令）

```bash
xcode-select --install
```

1. 克隆 dotfiles 文件夹

```bash
git clone https://github.com/theowenyoung/dotfiles.git ~/dotfiles
cd dotfiles
git clone https://theowenyoung:<token>@github.com/theowenyoung/private.git ~/dotfiles/private
```

2. 运行配置 macos 的文件，这样就不用一个个在界面上去做配置了，全部配置见[这里](https://github.com/theowenyoung/dotfiles/blob/main/modules/macos/configure_macos.sh)

```bash
./scripts/1_configure_macos.sh
```

3. [安装必备软件](https://github.com/theowenyoung/dotfiles/blob/main/scripts/2_install_required_modules_macos.sh)

```bash
./scripts/2_install_required_modules_macos.sh
```

4. 安装[配置文件](https://github.com/theowenyoung/dotfiles/blob/main/scripts/3_import_dotfiles_macos.sh)（这一步会导入所有配置文件，以及密码，需要的环境变量等等（命令行脚本会提示你输入密码））

```bash
./scripts/3_import_dotfiles_macos.sh
source ~/.zshrc
```

> 其中包含 1 个[导入 ssh key 的脚本](https://github.com/theowenyoung/dotfiles/blob/main/scripts/import_ssh_key.sh)，和[导入临时环境变量的脚本](https://github.com/theowenyoung/dotfiles/blob/main/scripts/import_temp_env.sh)

5. 独立安装其他想安装的软件

```bash
./modules/foo/install_foo_macos.sh
```

Linux 的初始化也是类似，可以看我的 [readme 文件](https://github.com/theowenyoung/dotfiles#deiban-init), **我强烈建议你不要直接用我的 dotfiles 文件**，就像自己的房子一样，你应该始终自己从头开始构建，这样才是保持可持续的好方法（我对[anki](https://www.ankiapp.com/)的使用也是同样的观点，你应该使用自己插入每一个要记住的单词，而不是使用别人做好的列表，只有你自己插入的，你才有场景去记住它）。我的 repo 只是给你做参考，还有[17 万人](https://github.com/search?q=dotfiles)的 dotfiles 可以用来参考。

[Comtrya](https://github.com/comtrya/comtrya)的运行操作的命令是：

```bash
comtrya apply
```

这个命令会应用所有当前目录下他找到的`.yml`文件。我写了一个[更方便的 bash 命令](https://github.com/theowenyoung/dotfiles/blob/main/modules/comtrya/files/comtrya_alias.zsh)去做这件事,有了个function 之后，我可以在任意目录执行这些命令：

表示仅应用 ssh 模块下的配置：

```bash
ca ssh
```

表示应用全部模块的全部更新：

```bash
ca all
```

如果你当前在某个模块目录下，直接运行：

```bash
ca
```

即可执行当前模块的配置。

另外我还有一个[`unlink.sh`](https://github.com/theowenyoung/dotfiles/blob/main/scripts/unlink.sh) 的脚本，可让你一件删除所有 comtrya 创建的配置文件（为了更清晰，这个脚本是手动维护的）

### 关于我的键盘

我用的键盘的[键位配置](https://github.com/theowenyoung/dotfiles/tree/main/modules/qmk)也在里面，我使用一款叫 [redox](https://github.com/mattdibi/redox-keyboard) 的分体键盘（顺便说一下，分体键盘真的好用，你可以把手按照最舒服的姿势摆在任何地方），我的键盘的键位大概长这样：

![keyboard](https://media.jant.me/media/sit_01kmyfab3cfztrzn5qs9b80083/files/med_01kwtjperhfeza94e44ymty6yy.png)

这是一个[客制化](https://www.zfrontier.com/app/flow/2wXVPWNnXn5v)的键盘，意味着我可以按照我的习惯自定义全部的按键，还有一个重要功能是，可以“一键两用”，比如我最常用的空格键，在单击的时候是空格键，但是在按住的情况下是`cmd`键，几乎每个控制键, 我都重新定义了他在单击的时候的键位，这样就最大化的利用了键盘里最常用的区域。还有一个是键盘支持多层，我只利用了 2 层，我觉得人脑记不住那么多层，我的第二层就放一些播放，暂停，下一首，静音之类的控制键和 F1 到 F12 的键位。

你可以在[这里](https://config.qmk.fm/#/redox/rev1/LAYOUT) 导入我的[键位配置文件](https://github.com/theowenyoung/dotfiles/raw/main/modules/qmk/files/redoxpro/redoxpro.json)，以查看我的键盘的更多层。

## 结论

在做完以上的一切后，我的数字生活开始变得更加的得心应手，系统也更加的 robust，基本上可以随时 reset 重来。以及我终于拥有了自己的第一个以后会稳定使用的 web3 身份了（以前注册的 metamask 真的找不到了，不过反正也没钱），也许我应该把之前在 [matters](https://matters.news/) 上赚的一点点 like 币（被我在交易所换成了 200 usdt 了）转到这里？以及我还需要开哪些 web3 账户？

> 上次看了这个[nostr](https://branle.netlify.app/)协议，觉得很喜欢，现在终于可以生成一个永久账户了：[astral](https://astral.ninja/57c22f1ceef806230690b0932e3bc850d485f34ee722378b0f6f2e403097caa1)

以及这是我当前的[全部模块](https://github.com/theowenyoung/dotfiles/tree/main/modules),里面有我精心调试的最优配置（对于我），以及由于刚开始维护，还在频繁不断完善中（但是我对当前的文件结构很满意）：

```bash
├── modules
│   ├── acme
│   ├── alacritty
│   ├── alfred
│   ├── anki
│   ├── automator
│   ├── bash-language-server
│   ├── bat
│   ├── broot
│   ├── caddy
│   ├── cargo-generate
│   ├── clash
│   ├── comtrya
│   ├── curl
│   ├── dashflare
│   ├── dufs
│   ├── editor
│   ├── fd
│   ├── font
│   ├── fzf
│   ├── git
│   ├── git-filter-repo
│   ├── gnupg2
│   ├── gost
│   ├── helix
│   ├── homebrew
│   ├── hurl
│   ├── jq
│   ├── kakoune
│   ├── keepassxc
│   ├── kitty
│   ├── lua_language_server
│   ├── macos
│   ├── macports
│   ├── meilisearch
│   ├── microsoft_edge
│   ├── miller
│   ├── napa
│   ├── navi
│   ├── nodejs
│   ├── nvim
│   ├── pass
│   ├── passwd
│   ├── pepper
│   ├── pip3
│   ├── podman
│   ├── podman-compose
│   ├── postman
│   ├── qBittorrent
│   ├── qmk
│   ├── rage
│   ├── rust
│   ├── rust-analyzer
│   ├── shadowsocks-rust
│   ├── simple-torrent
│   ├── ssh
│   ├── ssh-agent
│   ├── starship
│   ├── systemd
│   ├── taplo
│   ├── tiny
│   ├── tmux
│   ├── translate-shell
│   ├── vscode
│   ├── wasm-pack
│   ├── wezterm
│   ├── wrangler
│   ├── yaml-language-server
│   ├── zellij
│   └── zsh
```

我用[tmux](https://github.com/tmux/tmux) 管理窗口，终端用[Alacritty](https://github.com/alacritty/alacritty) ,模态编辑器 [helix](https://github.com/helix-editor/helix) 和[kakoune](https://github.com/mawww/kakoune),kak 更成熟，但是更喜欢 helix，我买了[alfred](https://www.alfredapp.com/)的终身版，现在它已经升级到 alfred5 了（但是 alfred 的配置文件太恶心了，不适合在 dotfiles 里管理，因为是自动生成的，由于这一点我想找一个替代品，但是没有体验更好的），我用[navi](https://github.com/denisidoro/navi) 管理常见的 [cheatsheets](https://github.com/theowenyoung/dotfiles/tree/main/modules/navi/files/cheats), [fzf](https://github.com/junegunn/fzf)查找文件（太好用了，强烈推荐），以及很多其他的好东西，上述的一些 module 有的已经没有在用了，但是配置文件我想留着，以防将来有一天想再试试。

在[这里查看整个 dotfiles repo](https://github.com/theowenyoung/dotfiles/)

> 最后还要建议 web3 的大佬们，你们应该投资密码管理器才对，把更好用的密码管理器免费带给大家！

_2022-07-12 · note_ — [HTML](https://www.owenyoung.com/blog/web3-to-dotfiles) · [Markdown](https://www.owenyoung.com/blog/web3-to-dotfiles.md)

---

## Zola 博客的中文阅读时间预估误差很大，所以我做了一个修复

我发现 Zola 给中文文章的阅读时间预估特别高，比如我刚发布的这篇[给 Zola 博客增加搜索功能](/blog/add-search), 显示要 20 分钟才能阅读完:

> 发布于: 2022-07-12 · 最后更新时间: 2022-07-12 · 阅读时间: 20 min

我就纳闷我这是写了一篇 essay 吗，于是就是查它的[实现](https://github.com/getzola/zola/blob/39cf436b1174a3d5f2fbe4bac20e942795005f05/components/content/src/utils.rs#L55-L61), 发现实现很简单，就是基于 unicode 字符除以了一个数：

<!--more-->

```rust
/// Get word count and estimated reading time
pub fn get_reading_analytics(content: &str) -> (usize, usize) {
    let word_count: usize = content.unicode_words().count();
    (word_count, ((word_count + 199) / 200))
}
```

然后他在注释里链接了这个数字的[来源](https://help.medium.com/hc/en-us/articles/214991667-Read-time)，证明它不是拍脑袋决定的, 来源是 [Medium](https://medium.com/) 的文档：

> Read time is based on the average reading speed of an adult (roughly 265 WPM). We take the total word count of a post and translate it into minutes, with an adjustment made for images. For posts in Chinese, Japanese and Korean, it's a function of number of characters (500 characters/min) with an adjustment made for images.

这篇文档说英文这类字符大约是 265 个单词每分钟，中日韩这类文字是 500 个字符每分钟，所以对于中文来讲，zola 这个计算是有大约 1 倍的误差的，所以我加了一个判断：

```html
{% macro get_reading_time(minutes) %} {% if lang=="zh" %} {{ minutes/1.88 |
round }} {% else %} {{ minutes }} {% endif %} {% endmacro get_reading_time %}
```

然后在`page.html`里可以这样调用：

```html
{{ macro::get_reading_time(minutes=page.reading_time) }}
```

这样应该就能修正中文的预估时间了。修正后，开头提到的文章现在预估时间大约是 11 分钟，比较合理了。

_2022-07-12 · note_ — [HTML](https://www.owenyoung.com/blog/reading-time) · [Markdown](https://www.owenyoung.com/blog/reading-time.md)

---

## 给Zola博客增加搜索功能

我觉得个人博客的一个最大的好处就是我可以把它当成任何东西的试验田，弄坏也没事，反正这只是我的个人数字花园而已。所以昨天我给博客新加了一个[搜索页面](/pages/search)，以及首页也添加了一个搜索框。

我一直在这个博客里存放自己的所有公开内容，包括笔记和文章，我经常需要搜索自己的笔记，在此之前，我一直用 VSCode 在本地搜索文档。但是 VSCode 其实启动挺慢的，而且如果不在电脑边，也没法用，所以最近就研究了几种搜索方案。最终我选择了自托管 Rust 开发的[Meilisearch](https://github.com/meilisearch/meilisearch)，但是这也不是特别理想的方案，因为需要在自己的 VPS 服务器上托管，对于静态博客来说，多了一环需要动态运行的服务需要维护。但是这已经是目前最不差的方案了。

<!--more-->

对于静态博客的搜索，我了解的主要有 4 种主流方案，一是客户端搜索，另一种是很流行的使用[Algolia](https://www.algolia.com/)的搜索托管服务，还有一种是使用搜索引擎比如谷歌的索引结果，最后就是我最终使用的 Algolia 的开源[替代方案 Meilisearch](https://github.com/meilisearch/meilisearch)这类的自托管。

## 客户端搜索

客户端搜索是最符合静态博客定义的，完全不依赖服务端，zola 博客内置的搜索功能也是这样，其原理是 build 的过程中，生成整个网站的搜索的 JSON 索引文件，在前端网页提出搜索请求后，用 js 去搜索这个索引，然后找出对应的结果。这个索引可大可小，如果你只索引标题和路径的话，那么索引就很小，但是如果你索引全文的话，取决于你的文档大小，索引可能会很大。Zola 目前内置的搜索使用 [elasticlunr](https://github.com/weixsong/elasticlunr.js), 其实已经 3 年没有更新了，项目处于等继承者状态。另一个就是，这个基本上是不支持中文搜索的，虽然 Zola 有选项可以建立中文的搜索索引，但是前端库方面对于中文的支持处于不可用的状态，我试过接入，但是太多 bug 了，之前看到一个[日本博主好像确实有成功集成日文搜索](https://www.jpgov.art/posts/japanese-full-text-search-on-zola/), 我仿照的时候也失败了。

为什么对于中文搜索需要专门支持呢？因为所有类似的全文搜索实现都是要先建立一个倒排索引（听起来很牛逼，其实就是词语对文章 id 的哈希索引），类似下面这样：

```json
{
  "Hello": ["/hello", "/world"],
  "World": ["/world", "/foo"]
}
```

有了这个索引，就能很快的找到最相关的文章。这种索引对于类似英语的语言来说很好实现，因为英语中分词很简单，只需要根据空格就能把所有词语分开，但是中文没有用空格分开的习惯，所以需要很大的词语字典，然后从字典里找到相关的词语，然后再建立分词索引。这才完成第一步（这个比较好解决，因为这一步发生在编译阶段，有足够的资源去做这件事）。第二步是从客户端发出搜索请求，这一步依然需要分词，比如用户搜索`如何给zola博客添加索引`，搜索引擎首先要把这句话分为`如何`,`给`,`Zola`,`博客`,`添加`,`索引`，然后再去对应的索引里进行最佳匹配查询。所以我觉得对于中文搜索，在客户端做是不现实的，因为基本上没法在客户端上进行复杂的分词，而且随着文档的增加，全文搜索的索引还会进一步增加，全部加载到客户端看起来也不是一个很道德的选择。

**WASM 怎么样？**

[WebAssembly](https://webassembly.org/) 以作为 js 的高性能支持方案进入了主流浏览器的支持，你可以用 Rust, C++，或者任何你喜欢的语言来编写高性能的 WebAssembly 应用，然后在前端调用。

对于 WASM，看到过几个有意思的项目，比如[sql.js-httpvfs](https://github.com/phiresky/sql.js-httpvfs), 把 sqlite 数据文件存储到 CDN 服务器上，然后前端用含有内嵌 sqlite 的 wasm 去读取数据，充分利用了 sqlite 的高效，从而实现让 web 客户端完全摆脱服务端数据库的依赖。

我也找到了几个关于 WASM 搜索的项目，主要包括：[tinysearch](https://github.com/tinysearch/tinysearch) ,[stork](https://github.com/jameslittle230/stork), [edgesearch](https://github.com/wilsonzlin/edgesearch)

### [Tinysearch](https://github.com/tinysearch/tinysearch)

用 Rust 编写，原理和 js 客户端搜索基本类似，只不过把索引打包到 wasm 里面，最终的 wasm 大小可以是 100k 以内，但是也只支持英文。我把源码下载下来，然后把分词逻辑换用[Meilisearch 的分词](https://github.com/meilisearch/charabia)，尝试打包我目前的博客，发现总共也才 113K，这 113K 是同时包括搜索逻辑和索引数据的哦，而用 Zola 自带的搜索打包的纯中文索引数据是 3.5M,英文索引是 650K, 可见 tinysearch 的作者真的做了很多优化，作者也写了一篇[详细的文章](https://endler.dev/2019/tinysearch/)记录优化的过程。但其实这样对比是有一点不公平的，因为[Zola 的索引会有更好的搜索体验](https://www.getzola.org/documentation/getting-started/overview/)，你可以在文档网站体验一下, 而[Tinysearch](https://endler.dev/2019/tinysearch)则为了性能做了一些取舍，比如不支持前缀搜索，搜索结果只显示标题，没有上下文，也没有高亮等等，但是从性能角度，我觉得这种方案算是客户端搜索的天花板了。

### [Stork](https://github.com/jameslittle230/stork)

同样也是 Rust 编写，只支持英文，颜值很好，接入体验也很棒，搜索结果还能高亮，也有上下文，基本上和[Algolia](https://www.algolia.com/)类似，也使用了 wasm，不过 Stork 是把搜索逻辑单独打包成一个 wasm，然后把索引数据另外打包成另一个`st`文件，然后搜索的时候动态的加载索引数据。这样的操作其实多了一步序列化和反序列化的步骤。我也尝试把其内置的简单英文分词逻辑换用[Meilisearch 的分词](https://github.com/meilisearch/charabia)，但是发现我的索引数据竟然达到了 85M（可能有别的坑，因为我只是简单的替换了分词的函数），所以就没有更多的体验了。这也印证了，想在客户端把搜索体验做好，确实需要权衡你的索引大小。

### [edgesearch](https://github.com/wilsonzlin/edgesearch)

我喜欢这个哥们的概念，无服务器 Serverless 搜索，通过把 WASM 部署到 Cloudflare Workers 上，然后客户端通过网络请求进行搜索，我觉得这是最有戏的方案，我喜欢 Cloudflare Workers 这种一次书写，永远忘记的无服务器系统，而且每天还有 10 万请求的免费额度，同时作为基于 Chrome V8 中有限制的无服务器，冷启动又贼快，所以我觉得静态博客的最佳搜索方案就是这样了。虽然有一点点动态，但是我们用了最具有扩展性的方案，我倾向于认为这是必要的权衡。说回 EdgeSearch，它也是先 build 索引，然后把索引上传到 cloudflare 的 KV 内存数据库里，然后通过 wasm load 索引，进行搜索，性能很高，只是它目前只是处于实验阶段，接入需要自定义很多东西，而且也不支持中文，我个人很希望这个项目能获得更多的牵引力。

## 难道只能用云搜索服务了吗？

### [Algolia](https://www.algolia.com/)

即刻搜索的鼻祖和天花板，我在[Actionsflow 的文档网站](https://actionsflow.github.io/docs/)中用了他提供给开源项目的免费服务，接入和界面都是一流的，不信你去看[tailwindcss](https://tailwindcss.com/)的搜索体验，太棒了。唯一的问题就是贵，如果不差钱，那我觉得这是最佳选择了。他家同时也是[Hacker News](https://hn.algolia.com/)的御用搜索，我经常用来搜很多东西, 感谢感谢！

### [Sourcegraph](https://sourcegraph.com/)

我在[阮老师的科技周刊](https://github.com/ruanyf/weekly)里看到阮老师给用户的其中一个搜索选项是利用 [https://sourcegraph.com/github.com/theowenyoung/blog](https://sourcegraph.com/github.com/theowenyoung/blog) 提供的对 Github 源码的免费搜索服务，我试了一下，搜索准确度非常高，但是只能链接到源文件，没法回到对应的网页，但是由于博客内容是用 markdown 写的，所以纯文本也没问题。所以，这是一个不错的替代品。我在[Search](/pages/search)也添加了一个表单搜索链接过去，你可以体验一下。

### [VSCode Web 版(Github1s)](https://github1s.com/theowenyoung/blog)

你只需要在 github 的网址上加上`1s`之后，就能用浏览器以 VSCode 的方式打开你的 github repo，比如我的博客对应的地址就是：[https://github1s.com/theowenyoung/blog](https://github1s.com/theowenyoung/blog) ，这里自带 VSCode 的全局搜索，所以就可以直接在浏览器上搜索博客内容，这其实也是一个很好的搜索替代方案，完全不用担心自己托管，搜索速度也超快，就是差一个直接指向搜索并且带搜索参数的链接，我提了一个[Issue](https://github.com/conwnet/github1s/issues/428),结果他们回复其实他们用的是我上面提到的 Sourcegraph 的搜索，被骗了！我以为是 VSCode 自带的搜索！但是还是期待一下后续的进度，希望能有一个直链，支持类似这样的链接`https://github1s.com/theowenyoung/blog/panel/search?q=term&files-include=content`,这样就可以直接从我的博客里的搜索框跳转到 vscode 的全局搜索里，体验更好。不过这个工具的问题也是首次启动挺慢的，期待微软官方能出一个类似的工具，因为反正 github 也是他家的，可能会更快。

![githbu1s](https://media.jant.me/media/sit_01kmyfab3cfztrzn5qs9b80083/files/med_01kwtjnze3feza94c5x1vwaqcz.png)

### Google 网站搜索

你可以在谷歌的搜索框里加上`site:www.owenyoung.com`来指定搜索对应的网站，速度极快，缺点是可能收录不全。Anyway, 我在[Search](/pages/search)也添加了一个表单搜索链接了过去，你可以体验一下。

## 自托管方案

### [Meilisearch](https://github.com/meilisearch/meilisearch)

[美丽搜索？](https://github.com/meilisearch/meilisearch)是一个用 Rust 写的美丽的 Algolia 的开源替代，我喜欢这个名字哈哈哈，美丽！Evething is ok, 就是界面相比 Algolia 还是差了那么一点点。使用流程是：在服务端启动服务后，每次你的静态博客编译后，请求 meili 的接口，把要索引的文档通通丢给他，然后他就会立刻建立索引，客户端就可以搜索里。meili 提供了[客户端 js 库](https://github.com/meilisearch/docs-searchbar.js)让我们可以方便地一键接入。我研究了美丽自己的[文档网站](https://docs.meilisearch.com/) ([源码](https://github.com/meilisearch/documentation)),发现他的接入流程更美丽，用 Github 的[Action](https://github.com/meilisearch/documentation/blob/master/.github/workflows/gh-pages-scraping.yml)去扫描整个站点的 sitemap 文件，然后做一些针对网站排版的简单配置，就可以美丽的，有层次的索引你整个网站了。本来以为建立索引挺慢的，但是后面发现 1 分钟左右就能扫描完成，可以在[Search 页面](/pages/search)体验一下这个搜索结果的层次感！（顺便说一下，这些功能 Algolia 都有哈！），这个层次感是我决定采用它的最重要的原因，因为它是针对文章的各种二级，三级标题，以及内容所在的大标题做的更有细节的索引，所以在搜索结果中，可以直接从结果中点击进入到对应文章的锚点。以下是扫描全站的核心配置：

```json
{
  "selectors": {
    "lvl0": {
      "selector": ".detail-page .p-category",
      "default_value": "Random"
    },
    "lvl1": {
      "selector": ".detail-page .p-tags",
      "default_value": "Notes"
    },
    "lvl2": ".detail-page .entry-title",
    "lvl3": ".e-content h2",
    "lvl4": ".e-content h3",
    "text": ".e-content p, .e-content li"
  }
}
```

这样的配置的话， meilisearch 建立的索引是细节到具体的小标题和段落上的，可以让搜索体验直接上升一个层次。所有配置见[这里](https://github.com/theowenyoung/blog/blob/84f139a47658ff31482d4b36ba0acd86f08b071f/meilisearch-docs-scraper-config.json)

### 我的部署过程

1. 先在 VPS 上搭建 Meili,见[我的 meilisearch dotfile 配置](https://github.com/theowenyoung/dotfiles/blob/main/modules/meilisearch/meilisearch.yml)，并不复杂，是我最喜欢的单一二进制文件，无依赖。
2. 在 Github Actions 的中添加步骤，在网站更新后，立刻爬取整个网站.见[build.yml](https://github.com/theowenyoung/blog/blob/ee82d2d783c3b08b98862a7700a6a29a301e164e/.github/workflows/build.yml#L20-L37) 以及[爬取的配置文件](https://github.com/theowenyoung/blog/blob/main/meilisearch-docs-scraper-config.json),得益于我上次在[Now, I'm in IndieWeb?](/blog/indieweb.en)中给网站的结构添加了很多有用的标记，所以很好定位到我的一级标题，二级标题，分类等, 我在配置中排除了列表页面，让他只爬取文章页。
3. 在前端网页引入相应的 [css](https://github.com/theowenyoung/blog/blob/37de4f670b3b2d28a77e39b1804ce986c99f0a6a/templates/search.html#L6-L8) 和 [js 脚本](https://github.com/theowenyoung/blog/blob/37de4f670b3b2d28a77e39b1804ce986c99f0a6a/templates/search.html#L71-L85)

Over! 其实说的简单，但是我在建立索引的过程中多次调整了页面中 tag 的层级和 class 以便机器人可以更好的定位到需要的内容（面向机器人编程），最终打磨出来的效果就是：

![meilisearch](https://media.jant.me/media/sit_01kmyfab3cfztrzn5qs9b80083/files/med_01kwtjp1yqfeza94ck28cgz3hp.png)

搜索页面的模版文件[在这里](https://github.com/theowenyoung/blog/blob/main/templates/search.html)

升级的时候可能比较麻烦，我通常就是直接删除数据库，反正可以重新构建，跑一下 CI 就可以了。

升级后需要重新获取 admin key:

```bash
make meilikey
```

## 结论

虽然目前用 Meilisearch 解决了搜索的问题（而且体验超好），但是还是更喜欢[Edgesearch](https://github.com/wilsonzlin/edgesearch)的方案，这样我就能把搜索部署在类似 Workers 和 Deno Deploy 的平台上了。我不喜欢 Lambda 和 Vercel 的无服务器，虽然限制更少，但是相应的冷启动有点久，不够纯粹。我的理想方案应该是这样，它是一个通用的站内搜索引擎：

1. 通过 Fork 一个 Cloudflare Worker 项目即可部署自己的搜索引擎，带一些很少的配置。
2. 这个搜索引擎会暴露一个开始索引的路由，你会给这个路由提供一个配置文件，然后告诉他`sitemap`文件，以及要索引的区块配置。
3. 这个搜索引擎暴露几个类似 Algolia 的接口让前端可以搜索，以及管理索引。

基本上就是把我在 meilisearch 上做的事搬到 wasm 上，但是我更喜欢在 cloudflare workers 上部署搜索服务的方案，因为它更简单，更快，更具有扩展性。

我目前是把 Meili 部署在我的一个 4g 内存位于日本的服务器，这台服务器还部署了我很多其他的东西，如果你也想要接入美丽搜索，但是不想自己部署服务端（我懂），可以邮件或者私信我，我告诉你我的 Master Key，然后你也可以利用[https://meilisearch.owenyoung.com/](https://meilisearch.owenyoung.com/)建立你的博客索引了。但是这是玩具产品，不能保证可用性，后续也可能被替换，但是终止前我会提前通知你～

> 更新：我目前把 Meilisearch 从我的 VPS 迁移到免费的[Mogenius](https://mogenius.com/home),更省心，这样就算我弄乱 VPS 的情况下，搜索也不会轻易下线，我也写了[一篇文章](/blog/adding-search-to-zola-blog-with-meilisearch-deployed-on-mogenius/index.en)记录整个过程

_2022-07-11 · note · 1 reply_ — [HTML](https://www.owenyoung.com/blog/add-search) · [Markdown](https://www.owenyoung.com/blog/add-search.md)

---

## 2022-06-21 · q91qv

防疫措施里有 2 条是我觉得最最最反智的：1. 不让农民下地。2.不让快递员把快递放在位于小区内的快递柜里。

_2022-06-21 · note_ — [HTML](https://www.owenyoung.com/q91qv) · [Markdown](https://www.owenyoung.com/q91qv.md)

---

## 2022-06-21 · eh4go

Zola 的 next 分支支持双向链接了，刚给这个博客的文章末尾加了展示双向链接的地方！

_2022-06-21 · note_ — [HTML](https://www.owenyoung.com/eh4go) · [Markdown](https://www.owenyoung.com/eh4go.md)

---

## Now, I'm in IndieWeb?

Since I saw the concept of [IndieWeb](https://indieweb.org/IndieWeb) last year, I've been wanting to support it on [my Zola blog](https://github.com/theowenyoung/blog). Before that my blog had never had a commenting system, and this time with Webmention I was finally able to get a static blog to display responses to articles on the web in plain html. I will document how I did it in this article.

<!--more-->

> The [IndieWeb](https://indieweb.org/IndieWeb) **IndieWeb** is a community of independent &amp; personal websites connected by simple standards, based on the [**principles**](https://indieweb.org/principles) of: [**owning your domain**](https://indieweb.org/personal-domain) &amp; using it as [**your primary identity**](https://indieweb.org/How_to_set_up_web_sign-in_on_your_own_domain), [**publishing on your own site (optionally syndicating elsewhere)**](https://indieweb.org/POSSE), and [**owning your data**](https://indieweb.org/ownyourdata).

## 1. Support IndieWeb Auth

IndieAuth is a federated login protocol for Web sign-in, so by enabling this, we can use our own domain to sign in to other sites and services which support [IndieAuth](https://indieauth.net/). Learn more about [why IndieAuth](https://indieweb.org/IndieAuth) and [how to IndieAuth](https://indielogin.com/setup), here's how I enabled it:

1. By editing [my index template file](https://github.com/theowenyoung/blog/blob/a8b3cb3c13077b28cbcf7503518f6ed6cb8bb773/templates/base.html#L31-L33), add this to the head:

```html
<link rel="me" href="https://twitter.com/TheOwenYoung" />
<link rel="me" href="https://github.com/theowenyoung" />
<link rel="me" href="mailto:owen@owenyoung.com" />
```

2. Editing Twitter/GitHub profile bio, add my website URL `https://www.owenyoung.com`
3. Test it at [https://indielogin.com/](https://indielogin.com/)

## 2. Add Profile Info

When you sign in with IndieAuth or using [web mention](https://indieweb.org/Webmention), some sites will try to get your profile info, like name, image, and bio. So we can add this to our homepage, you can learn more about [h-card](https://indieweb.org/h-card) here. Here's how I added it:

By editing [my index template file](https://github.com/theowenyoung/blog/blob/a8b3cb3c13077b28cbcf7503518f6ed6cb8bb773/templates/base.html#L181-L187), add this in the `aside` (Cause I don't want this to affect the layout of my site, so use css `display: none` to hide it for human, but the bot will see it):

```html
<div class="display-none h-card pt">
  <img class="u-photo icon" alt="Owen"
  src="{{/*get_url(path="site/images/favicon-96x96.png",cachebust=true)*/}}" />
  <a class="p-name u-url" href="{{ config.base_url }}"
    >{{ config.extra.author }}</a
  >
  <p class="p-note">{{ config.extra.bio }}</p>
</div>
```

## 3. Joining [IndieWeb Webring](https://xn--sr8hvo.ws/)

> A webring (or web ring) is a collection of websites linked together in a circular structure, and usually organized around a specific theme, often educational or social. They were popular in the 1990s and early 2000s, particularly among amateur websites.

Now, IndieWeb has one [IndieWeb Webring](https://xn--sr8hvo.ws/)! by adding webring in our sites, so people can find (and be found by) other folks with IndieWeb building blocks on their sites!

So, I'm in it! By joining this, my blog has been listed in the [IndieWeb Webring Directory](https://xn--sr8hvo.ws/directory), you can see I already have [a profile](https://xn--sr8hvo.ws/%F0%9F%93%AE%F0%9F%86%99%F0%9F%93%A9) there.

It's easy to join the webring, just click the [link](https://xn--sr8hvo.ws/), and login with my domain `www.owenyoung.com`, then I can get my webring code, my webring code like this:

```html
<a href="https://xn--sr8hvo.ws/%F0%9F%93%AE%F0%9F%86%99%F0%9F%93%A9/previous"
  >←</a
>
An IndieWeb Webring 🕸💍
<a href="https://xn--sr8hvo.ws/%F0%9F%93%AE%F0%9F%86%99%F0%9F%93%A9/next">→</a>
```

Then, I add this code to [my homepage aside](https://github.com/theowenyoung/blog/blob/a8b3cb3c13077b28cbcf7503518f6ed6cb8bb773/templates/base.html#L216-L218), you can see it on the [aside footer](https://www.owenyoung.com/#bottom)

## 4. Adding [Webmention](https://indieweb.org/Webmention) Response to articles

[Webmention](https://www.w3.org/TR/webmention/) is a web standard for mentions and conversations across the web, a powerful building block that is used for a growing federated network of comments, likes, reposts, and other rich interactions across the decentralized social web.

> "An @ mention that works across websites; so that you don't feel immovable from Twitter or Fb.” — [Rony Ngala](https://twitter.com/rngala/status/852354426983591937)

Learn more about [Webmention](https://indieweb.org/Webmention) and [How to support webmention](https://indieweb.org/Webmention-developer)

Basically, I use [Webmention.io](https://webmention.io) to collect all webmentions about this blog, and then I use [Denoflow](https://github.com/denoflow/denoflow) to cache them to [my blog repo](https://github.com/theowenyoung/blog/tree/main/webmentions), and then I use [Zola](https://www.getzola.org/documentation/templates/overview/#load-data) `load_data` function to load them, and render them.

1. First, go [webmention.io](https://webmention.io) and create a new account with my domain `www.owenyoung.com`, then I can get my webmention endpoint, and I connected my twitter and github account to the service.
2. Second, let other services know your webmention endpoint. Add this to the head:

```html
<link
  rel="webmention"
  href="https://webmention.io/www.owenyoung.com/webmention"
/>
```

3. Use [Denoflow](https://github.com/denoflow/denoflow) to cache all webmentions to [my blog repo](https://github.com/theowenyoung/blog/tree/main/webmentions)

Workflow file([`workflows/fetch-webmention.yml`](https://github.com/theowenyoung/blog/blob/main/workflows/fetch-webmention.yml)):

> Fetch webmention [API](https://github.com/aaronpk/webmention.io#api) to get updates, then save to `webmentions` directory.

```yaml
sources:
  - use: fetch
    args:
      - https://webmention.io/api/mentions.jf2?domain=www.owenyoung.com&per-page=999&token=${{ctx.env.WEBMENTION_TOKEN}}
    run: return ctx.result.json()
    itemsPath: children
    key: "wm-id"
filter:
  run: |
    const {ensureDir} = await import("https://deno.land/std@0.121.0/fs/mod.ts");
    const { dirname } = await import("https://deno.land/std@0.121.0/path/mod.ts");
    for(const item of ctx.items){
      const id = item["wm-id"];
      const target = new URL(item["wm-target"]);
      const pathname = target.pathname;
      const filename = pathname.slice(1).replace(/\/$/, "");
      const filepath = "webmentions/"+filename+".json";
      await ensureDir(dirname(filepath));
      let webmentionData = {};
      try {
        const dataString = await Deno.readTextFile(filepath);
        webmentionData = JSON.parse(dataString);
      } catch (_e) {
        // ignore
      }
      webmentionData[id] = item;
      console.log("write file:", filepath);
      await Deno.writeTextFile(filepath, JSON.stringify(webmentionData,null,2));
    }
    return ctx.items.map(()=>true);
```

Github Workflow file([`.github/workflows/denoflow.yml`](https://github.com/theowenyoung/blog/blob/main/.github/workflows/denoflow.yml)):

> Run denoflow every day at midnight, if there are any new updates, it will create a new pull request.

```yaml
name: Denoflow
on:
  repository_dispatch:
  workflow_dispatch:
  # push:
  #   branches:
  #     - main
  schedule:
    - cron: "1 0 * * *"
jobs:
  denoflow:
    runs-on: ubuntu-latest
    concurrency: denoflow
    steps:
      - name: Check out repository code
        uses: actions/checkout@v2
      - uses: denoland/setup-deno@v1
        with:
          deno-version: v1.x
      - run: make webmention
        env:
          WEBMENTION_TOKEN: ${{secrets.WEBMENTION_TOKEN}}
        continue-on-error: true
      - name: chown
        run: sudo chown -R $USER:$USER ./
      - name: git config
        run: git config --global user.name "github-actions[bot]" && git config --global user.email github-actions-bot@users.noreply.github.com
      - name: git add
        run: git add data && git add webmentions
      - run: git status
      - id: isChanged
        run: git diff-index --cached --quiet HEAD || echo '::set-output name=changed::true'
      - name: Create pull request
        uses: peter-evans/create-pull-request@v3
        if: ${{ steps.isChanged.outputs.changed == 'true' }}
        with:
          token: ${{ secrets.PERSONAL_TOKEN }}
          labels: automerge
          add-paths: data,webmentions
          commit-message: "chore: new item"
          committer: "github-actions[bot] <github-actions-bot@users.noreply.github.com>"
          author: "github-actions[bot] <github-actions-bot@users.noreply.github.com>"
          branch: new-item
          delete-branch: true
          title: New item update
```

Github auto merge workflow file([`.github/workflows/auto-merge.yml`](https://github.com/theowenyoung/blog/blob/main/.github/workflows/auto-merge.yml)):

> When a pull request is created, the workflow will automatically merge it if the pull request is from the same author

```yaml
name: Auto merge
on:
  workflow_dispatch:
  pull_request_target:
jobs:
  auto-approve:
    runs-on: ubuntu-latest
    steps:
      - name: Merge
        if: (github.actor=='theowenyoung') && (startsWith(github.head_ref,'new-item'))
        uses: "pascalgn/automerge-action@v0.14.3"
        env:
          GITHUB_TOKEN: "${{ secrets.PERSONAL_TOKEN }}"
          MERGE_DELETE_BRANCH: true
          MERGE_LABELS: ""
```

4. Add response block to page tempalte

This part may take a while to finish, here is [the main page template code](https://github.com/theowenyoung/blog/blob/3034e093846f4e7e33a957e3169856407b9087c0/templates/page.html#L90-L148), I'll only show the main part.

Use [Zola load\_data function](https://www.getzola.org/documentation/templates/overview/#load-data) to load the webmention data JSON file.

```html
{% set current_webmention_file_name = current_path | trim_end_matches(pat="/")
%} {% set webmention_data =
load_data(path="webmentions"~current_webmention_file_name~".json",required=false)
%}
```

Show response:

```html
{% if webmention_data %} {% set_global mentions = [] %} {% for ignored, item in
webmention_data %} {% set_global mentions = mentions | concat(with=item) %} {%
endfor %}
<p class="muted text-sm">
  {{trans(key="label_response_description",lang=lang)| markdown(inline=true) |
  safe}}
</p>
{% for type, items in mentions | group_by(attribute="wm-property") %}
<h3>
  {{trans(key="label_"~type,lang=lang)}} ({{items | length}})<a
    href="#{{type}}"
    id="{{type}}"
    class="zola-anchor"
    >🔗</a
  >
</h3>
{% if type == 'like-of' or type == "repost-of" or type == "bookmark-of" or type
== "follow-of" %}
<ul class="list-none flex items-center flex-wrap">
  {% for item in items %} {{ macro::webmention(type=type, item=item) }} {%
  endfor %}
</ul>
{% else %}
<ul class="list-none">
  {% for item in items %} {{ macro::webmention(type=type, item=item) }} {%
  endfor %}
</ul>
{% endif %} {% endfor %} {% endif %}
```

Then, I add a webmention form, so if people want to submit their mentions, they can directly submit it.

```html
<form
  class="webmention-form"
  action="https://webmention.io/www.owenyoung.com/webmention"
  method="post"
>
  <div class="flex items-center flex-wrap pb">
    <input type="url" name="source" class="flex-3 mr-sm w-full py-sm px-sm" />
    <input type="submit" class="px py-sm" value="Send Webmention" />
  </div>
  <input type="hidden" name="target" value="{{current_url}}" />
</form>
```

> Optional: I also added an activity page for aggregating all response, the activity template page is [here](https://github.com/theowenyoung/blog/blob/main/templates/activity.html)

> Cause I don't have too many mentions, so I use [sebastiandedeyne's](https://github.com/sebastiandedeyne/sebastiandedeyne.com/tree/master/data/webmentions) mention data as this article's webmention data.

## 5. Send webmention when you publish a new article

When we publish a new article, we want to send a webmention to the mentioned links. We can do this by using [Denoflow](https://github.com/denoflow/denoflow) and the [Webmention.app](https://webmention.app/) API. [Webmention.app](https://webmention.app/) can check all the mentioned links in the new article and send all webmentions to them. Before [Webmention.app](https://webmention.app/) can recognize the mentioned links, we need to add some extra [microformats2](https://indieweb.org/microformats2) to our article html. Basically, it's some html tag class names. These took me quite a few time to update my templates, so now I have supported [h-card](https://indieweb.org/h-card), [h-entry](https://indieweb.org/h-entry) and [h-feed](https://indieweb.org/h-feed). It looks like this:

```html
<article class="h-entry">
  <h1 class="p-name">Microformats are amazing</h1>
  <p>
    Published by
    <a class="p-author h-card" href="http://example.com">W. Developer</a> on
    <time class="dt-published" datetime="2013-06-13 12:00:00"
      >13<sup>th</sup> June 2013</time
    >
  </p>
  <p class="p-summary">In which I extoll the virtues of using microformats.</p>
  <div class="e-content">
    <p>Blah blah blah</p>
  </div>
</article>
```

I have updated [page.html](https://github.com/theowenyoung/blog/blob/main/templates/page.html), [index.html](https://github.com/theowenyoung/blog/blob/main/templates/index.html), [taxonomy\_single.html](https://github.com/theowenyoung/blog/blob/main/templates/taxonomy_single.html) and [section.html](https://github.com/theowenyoung/blog/blob/main/templates/section.html) to support these new microformats. I have to say this is the most demanding job, good luck!

Once finished, I went to [indiewebify](https://indiewebify.me/) to test if it can recognize my new microformats. It works!

Next, I went to [webmention.app](https://webmention.app/token) to apply for a token. Then I can add a denoflow workflow file to fetch it's service every day.

Here is the workflow file([`workflows/send-webmention.yml`](https://github.com/theowenyoung/blog/blob/main/workflows/send-webmention.yml)):

```yaml
sources:
  - from: https://deno.land/x/denoflow@0.0.35/sources/rss.ts
    args:
      - https://www.owenyoung.com/blog/atom.xml
  - from: https://deno.land/x/denoflow@0.0.35/sources/rss.ts
    args:
      - https://www.owenyoung.com/en/blog/atom.xml
steps:
  - use: fetch
    args:
      - https://webmention.app/check?token=${{ctx.env.WEBMENTION_APP_TOKEN}}&url=${{encodeURIComponent(ctx.item.links[0].href)}}
      - method: GET
        headers:
          Content-Type: application/json
    run: |
      console.log(ctx.item.links[0].href);
      const json = await ctx.result.json();
      console.log(json);
```

Don't forget to add enviroment variables `WEBMENTION_APP_TOKEN` to your denoflow workflow file(`.github/workflows/denoflow.yml`).

```yaml
- run: deno run -A https://deno.land/x/denoflow/cli.ts run
  env:
    WEBMENTION_TOKEN: ${{secrets.WEBMENTION_TOKEN}}
    WEBMENTION_APP_TOKEN: ${{secrets.WEBMENTION_APP_TOKEN}}
```

## Conclusion

I really like the concept of IndieWeb and their API design philosophy, it took some time but I still think it was worth it. It gave me renewed confidence in the Internet.

You can find the all source code of this blog on [Github](https://github.com/theowenyoung/blog)

## Resources

- [Bird.gy](https://brid.gy/) - Bridgy connects your web site to social media. Likes, retweets, mentions, cross-posting
- [Indie Webring](https://xn--sr8hvo.ws/)
- [Telegraph](https://telegraph.p3k.io/) - Easily send Webmentions from your website
- [Webmention.app](https://webmention.app/) - Automate your outgoing webmentions
- [Webmention.io](https://webmention.io/) - Webmention.io is a hosted service created to easily receive webmentions on any web page.
- [Fediring](https://fediring.net/)
- [Webmentions on a static site with GitHub Actions](https://sebastiandedeyne.com/webmentions-on-a-static-site-with-github-actions/)

_2022-06-11 · note_ — [HTML](https://www.owenyoung.com/blog/indieweb-en) · [Markdown](https://www.owenyoung.com/blog/indieweb-en.md)

---

Next page: https://www.owenyoung.com/archive.md?page=50
