为 Kindle 版微信读书替换衬线字体
date
Dec 24, 2022
slug
replace-weread-font-with-serif-for-kindle
status
Published
summary
我经常在微信读书读大部头,但是它的 Kindle 版本只能使用无衬线字体,总觉得差了点意思,于是就动了改造的念头。使用到了 nginx 反向代理技术和 sub_filter 内容替换模块。
tags
Engineering
Reading
type
Post
auth
起因
我经常在微信读书读大部头,但是它的 Kindle 版本只能使用无衬线字体,总觉得差了点意思,于是就动了改造的念头。
改造效果
![notion image](https://www.notion.so/image/https%3A%2F%2Fs3-us-west-2.amazonaws.com%2Fsecure.notion-static.com%2F594a6fd7-02f6-4aa3-a631-577a4100e7f5%2FSnipaste_2022-12-24_14-10-58.jpg?table=block&id=348264bb-d865-4b58-9ae9-30e5c0977b2e&cache=v2)
实现方案
- 应用的 CSS 样式:
font-weight: 500;
font-family: Baskerville, serif, STSong !important
- 前置条件:
- 自有域名
- 安装了 nginx 的服务器一台
- 交互如下:
![notion image](https://www.notion.so/image/https%3A%2F%2Fs3-us-west-2.amazonaws.com%2Fsecure.notion-static.com%2F1bce5a80-a76a-42e0-9c43-a98129057f16%2FUntitled.png?table=block&id=79236e48-f54a-4db4-b5ea-79d1da2e07d7&cache=v2)
具体步骤
一、编译 nginx 使其支持替换模块
- 查询系统安装的 nginx 版本和编译参数,通过
nginx -V
可以看到我的版本和参数
- 下载对应的 nginx 版本,我的是
1.18.0
所以下载这个文件:
wget http://nginx.org/download/nginx-1.18.0.tar.gz
- 解压 nginx 文件并进入解压文件夹,也是和你的版本号有关:
tar -xavf nginx-1.18.0.tar.gz
cd nginx-1.18.0
- 克隆模块代码仓库:
git clone https://github.com/yaoweibin/ngx_http_substitutions_filter_module
- 编译并安装,只需要在原有编译参数后添加
--add-module=./ngx_http_substitutions_filter_module
即可:
- (不一定需要)如果这时候报错,说明部分需要的库你没有安装,安装即可,我额外安装了
- 确定 nginx 位置,使用
whereis nginx
即可看到,
我的在
/usr/sbin/nginx
这个位置- 替换 nginx 执行文件,
cp ./objs/nginx /usr/sbin/nginx
二、设置域名和申请证书
为了快速输入我们的地址,需要绑定域名:
r.yourdomain.com
为主要访问服务器,指向你的服务器地址;
read.yourdomain.com
、res.yourdomain.com
、wereadsource.yourdomain.com
为静态资源服务器,指向你的服务器地址;
证书的获取参考其他教程,不做赘述,建议使用 acme.sh,省心。
三、Nginx 新增站点配置
在 Nginx 配置文件目录(默认位于
/etc/nginx/sites-enabled/
)新增 read.conf
微信阅读反代配置文件,文件内容如下(需自行替换 yourdomain.com
域名和对应证书路径):四、重启 nginx
systemctl restart nginx
配置生效,访问 r.yourdomain.com
即可。