惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

P
Proofpoint News Feed
V
V2EX
博客园_首页
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
Recent Announcements
Recent Announcements
博客园 - 司徒正美
Microsoft Security Blog
Microsoft Security Blog
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
Latest news
Latest news
Vercel News
Vercel News
The Register - Security
The Register - Security
T
The Exploit Database - CXSecurity.com
S
Schneier on Security
N
Netflix TechBlog - Medium
WordPress大学
WordPress大学
小众软件
小众软件
L
Lohrmann on Cybersecurity
GbyAI
GbyAI
P
Privacy & Cybersecurity Law Blog
T
Tor Project blog
AWS News Blog
AWS News Blog
美团技术团队
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
K
Kaspersky official blog
B
Blog RSS Feed
G
Google Developers Blog
量子位
大猫的无限游戏
大猫的无限游戏
Google DeepMind News
Google DeepMind News
Scott Helme
Scott Helme
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
I
Intezer
雷峰网
雷峰网
Martin Fowler
Martin Fowler
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
Blog — PlanetScale
Blog — PlanetScale
IT之家
IT之家
F
Full Disclosure
Apple Machine Learning Research
Apple Machine Learning Research
博客园 - 【当耐特】
The Hacker News
The Hacker News
U
Unit 42
S
SegmentFault 最新的问题
I
InfoQ
aimingoo的专栏
aimingoo的专栏
Y
Y Combinator Blog
宝玉的分享
宝玉的分享
罗磊的独立博客
Spread Privacy
Spread Privacy
C
CERT Recently Published Vulnerability Notes

Allen Hua 的网络博客

由于 Linux 桌面没有一个好用的天气程序就写了一个跨平台的CheckitoutWeather 给 caesium-image-compressor 图片压缩程序构建了 Linux AppImage v2.8.5 最新版 debian13(debian trixie)安装了nvidia闭源驱动后从x11切换到wayland的方法 山间摩旅追风,偶遇一场绚烂晚霞 最近使用debian系统的一些心得 机械革命无界14Pro笔记本debian forky成功驱动内置扬声器和麦克风 记录 typecho 1.2.0 升级到 1.3.0 过程 开发了一款openwrt插件:文本剪贴板 解决机械革命笔记本内屏高刷240Hz闪屏问题 使用 Java 写了一个局域网端口扫描器 - Allen Hua 的网络博客 openwrt使用外置根extroot机制扩展根分区大小 - Allen Hua 的网络博客 将机场ss节点批量转换成ss字符串链接批量添加到passwall - Allen Hua 的网络博客 给机械革命钛钽plus换屏:NY2换成NZ2 - Allen Hua 的网络博客 记录一次pve宿主机和上面的debian虚机无故down机事件 - Allen Hua 的网络博客 给图床部署cdn腾讯云的edgeone并排查Cache-Control max-age 3600的问题 - Allen Hua 的网络博客 从高山草甸到徽派古村:武功山反穿与皖浙赣自驾行记 - Allen Hua 的网络博客 增程器就是充电宝?别被忽悠了 - Allen Hua 的网络博客 浦口龙虎巷扫街,记录人间真实 博客图片压缩方案更新|AVIF|WebP|MozJPEG|标准JPEG Windows 电脑使用 Obs Studio 录制各个网站视频/桌面画面教程 为typecho博客添加latex支持 新能源汽车之纯电车使用交流慢充和直流快充的充电损耗对比 2025年3月更新全国5A景区名录 2025最新查看小米/红米手机电池健康度和循环次数方法 完美解决 seafile FILE_SERVER_ROOT 配置导致的内网外网不能同时访问和上传下载的问题 纯css实现typecho博客文章文字spoiler剧透效果 我对Typecho Facile主题的一些修改,图片懒加载优化,样式定制 2024年8月我的宜昌 - 重庆 - 川西小环线自驾旅行分享 2022年打卡南京市区人防工程纳凉点 2024年带着A7C2+腾龙28-200 再次来到红山森林动物园 入手a7c2第一个变焦镜头腾龙28-200体验分享 使用 exiftool 方便快捷写入图片的 exif metadata 使用JavaScript抓取易车销量排行榜数据到一个页面上展示 使用JavaScript脚本快速获取B站观看历史记录页面的视频标题和URL 入门三脚架推荐|云腾VCT-668配合索尼A7C2+FE 35mm F1.8 第一次夜景出片 Windows 11 Docker Desktop 更换默认C盘存储路径,释放C盘空间 雨游钟山——雨天带着索尼A7C2去钟山拍照 带上A7C2第一次扫街,分享今天拍的一些片子 再次为尼,买了人生第二台相机——索尼A7C2和FE 35mm F1.8 定焦镜头 更新 link-cleaner v1.1.0 适配linux桌面环境 使用自定义JavaScript脚本功能禁止memos最新版默认打开的链接预览功能 debian 11升级 docker ce 版本和 docker-compose 版本 机械革命无界14 Pro 安装 debian testing/trixie/sid 驱动扬声器,外部耳机,外接显示器过程分享 不借助 mirror 仓库,为docker engine daemon添加 proxy 访问 docker hub,解决国内公开的docker mirror 仓库不再可用了的问题 徒步江苏镇江句容九连尖 macOS 安装 proxychains-ng 并借助局域网 socks5 代理使用 Google Earth Pro 修复一块 18 年 12 月买的二手 4TB 机械硬盘 iCloud 在 Windows 下很流氓,用 taskkill 干掉它 2023 年 12 月 Spotify 彻底被墙,我在比亚迪车机上安装 surfboard 挂代理听歌 利用 proxychains 让 Windows10/11 上的 Google Earth Pro 通过代理正常访问 湖州安吉天荒坪盘山公路和杭州临安浙西天路之旅 Redmi K70 首发开箱和拍照体验 Review Android 13+ 通过 Shizuku + Language Selector 给特定应用设置独立语言 我的 2023 Spotify Wrapped 听歌总结 压缩剪贴板内图片并立即写入剪贴板,减轻服务器存储压力 【Allen Hua 翻唱】山阴路的夏天和一个人的北京 初涉录音设备,记录我购买声卡和麦克风的曲折经历以及第一首翻唱陶喆——流沙 soul power 版本(low quality) 特种兵旅行之马鞍山一日游 给我的 .com 域名续期以及转移域名(GoDaddy 到 Cloudflare) 看《下辈子我再好好过》第三季 使用油猴脚本干掉B站web首页的浏览器插件警告信息 闯进我平静生活的三只猫 在远离中短视频几天之后 [可能是]最好的压缩图片程序,使用 squoosh-cli 批量压缩图片 再次出发,自驾徽州天路和黄山之行 nginx设置referer配置个人图床的防盗链功能 微博注销记 第一次4+2旅行,骑行皖南川藏线 让 rime 输入法用上颜文字 使用 nginx 获取自己的公网 IP 地址 2023 年 618 买了一台机械革命笔记本,但很不愉快 聊聊我晚睡的习惯和早点洗澡悟出来的原因 配置 ShadowsocksR Plus+ 的服务端,在外访问家中服务 部署一个 memos 作为个人微博站点和备忘录 我的听歌软件 Spotify 和网易云的故事 | 导出网易云的歌单再导入到 Spotify 我问 ChatGPT 为何印度人痔疮发病率低 使用 immich 来管理家庭照片 | 升级 immich 1.52.0 添加 typesense 容器 在 OpenWrt 上搭建 nfs server 利用 cron 和 curl 自动模拟登录馒头,防止账号被 ban 更新 Mattermost 服务端版本,由 7.4.0 更新到 7.8.0 获取 Seafile 分享的文件直链 你是科技产品偏执狂吗?一张不同种类互联网用户日常使用产品的分级图片 记录我的 V2EX 账号被封 不通过插件给 Typecho 博客添加图片灯箱功能(fancybox js 实现) 为 Typecho 博客添加 favicon.ico(网页标签小图标) OpenWrt 修改登录页面默认展示的 root 用户名信息,保护隐私 米家智能插座 3 上手初体验 互联网上为了保护隐私我们能做些什么?分享我的想法和我写的 link-cleaner tplink 10280, wan 无法访问 lan 下的 dhcp 主机,换上 padavan 解决两台路由器 lan-wan 级联,两台路由器下面的电脑互访 机械革命自带键盘总是自动乱按,拆机拔掉排线,完美解决烦恼 做了一个 squoosh docker 镜像,写博客贴图直接在本地压缩文件,安全且高效 nginx 常规端口和非常规端口的 http redirect to https 记一次 OpenWrt luci 显示正在“收集数据”,使用公网 IP nginx 反向代理遇到的 Uncaught TypeError: Cannot read properties of null (reading 'wan') 问题 OpenWrt 安装并配置腾讯云动态 dns dnspod tencent ddns 浅谈文件传输/共享协议|内网共享文件协议选择|自建公网文件管理同步和共享方案推荐 解决 webdav 连接 seafile 无法重命名文件等操作造成的 SeafDAV: MOVE returns 502 Bad Gateway 错误 Linux 删除当前目录下的隐藏文件 OpenWrt 安装 4.4.2 版本的 qbittorrent-nox Docker 构建多架构镜像实战 构建 amd64 和 arm64 架构的兰空图床镜像 构建 arm64 架构和 amd64 架构的兰空图床 docker 镜像
记一次 leanote 蚂蚁笔记的博客更换主题 Chirpy
Allen Hua · 2021-12-19 · via Allen Hua 的网络博客
阅读量:3172

warning: 这篇文章距离上次修改已过1617天,其中的内容可能已经有所变动。

前言

前两天在 v2ex 看到 此帖。一直以来我用的都是官方的主题,然后我也心动了。于是乎我也换上了这个主题,慢慢踩坑直到现在让自己满意……

正片

我修改的博客地址: https://blog.hellodk.com/blog/dk11。该博客运行在我家里的 Phicomm N1 这台 armbian 设备上,是 docker 安装的leanote。使用的镜像是: https://hub.docker.com/r/lstcml/n1_leanote

n1 驾驭这些应用是小菜一碟,丝毫没有性能压力。但是由于 n1 是 arm 架构的,docker image 中使用的 leanote binary 程序亦需要是 arm based 的。这个 image 是基于 arm 的 Ubuntu 18.04,在更换国内镜像源以及安装软件包的过程中尽是坎坷。安装 python3pip3 遇到各种困难,主要是依赖非常麻烦。最终我放弃了在 n1 上运行,改在 x64 cpu 的软路由上运行。

原帖作者做了一些工作的,简要概括就是

  • 移植了 Chirpy 主题,创建 repo ctaoist/leanote-theme-chirpy
  • 改写 mongodb 数据库,让每篇文章具有一个 '是否是博客' 的属性。原本 leanote 2.6.1 需要将整个 notebook public as blog 才可以看到这个 category。作者改写了服务端程序让该 notebook 具有 public 的 blog 就自动生成 category
  • 归档页面排序 bug 修复

感谢作者的工作,我现在也用上了这个主题。


记录一些日志

  1. 原先 arm ubuntu 18.04 容器遇到问题 The certificate chain uses expired certificate. Could not handshake: Error in the certificate
    解决办法:软件包增加 [trusted=yes] 声明

    deb [trusted=yes] http://mirrors.ustc.edu.cn/ubuntu-ports/ bionic universe
    deb [trusted=yes] http://mirrors.ustc.edu.cn/ubuntu-ports/ bionic-updates universe
    deb [trusted=yes] http://mirrors.ustc.edu.cn/ubuntu-ports/ bionic multiverse
    deb [trusted=yes] http://mirrors.ustc.edu.cn/ubuntu-ports/ bionic-updates multiverse
    deb [trusted=yes] http://mirrors.ustc.edu.cn/ubuntu-ports/ bionic-backports main restricted universe multiverse
    deb [trusted=yes] http://mirrors.ustc.edu.cn/ubuntu-ports/ bionic-security main restricted
    deb [trusted=yes] http://mirrors.ustc.edu.cn/ubuntu-ports/ bionic-security universe
    deb [trusted=yes] http://mirrors.ustc.edu.cn/ubuntu-ports/ bionic-security multiverse
  2. 换了 amd64 架构的硬件,leanote 的服务端程序选了这个镜像 https://hub.docker.com/r/hjh142857/leanote
    容器是 x86_64 的 Ubuntu 18.04

    需要安装 python3 以及 pip3 然后通过 pip3 安装 pymongo


将以下代码命名成文件 leanote_2.6.1_to_2.7.0.py

#!/usr/bin/python3

import pymongo
from bson.objectid import ObjectId
import sys

if len(sys.argv) < 5:
    host = input('Mongodb Host: ')
    dbname = input('DB Name: ')
    user = input('DB Username: ')
    passwd = input("DB Password: ")
else:
    host, dbname, user, passwd = sys.argv[1], sys.argv[2], sys.argv[3], sys.argv[4]

dbClient = pymongo.MongoClient(f"mongodb://{user}:{passwd}@{host}:27017/?authSource={dbname}")
leanotedb = dbClient[dbname]

def updateNotebooks():
    for notebook in leanotedb.notebooks.find({"IsDeleted": False}):
        notebookId, userId, parentId = notebook["_id"], notebook["UserId"], notebook.get("ParentNotebookId")
        if parentId is not None:
            parentNotebook =  leanotedb.notebooks.find_one({"_id": parentId, "UserId": userId})
            if parentNotebook is not None:
                childs = parentNotebook.get("ChildNotebookIds", [])
                childs.append(notebookId)
                childs = set([str(c) for c in childs]) # 消除重复
                leanotedb.notebooks.update_one({"_id": parentId, "UserId": userId}, {"$set": {"ChildNotebookIds": [ObjectId(c) for c in childs]}})

def updateNotes():
    for note in leanotedb.notes.find({"IsDeleted": False}):
        cates = []
        noteId = note["_id"] # ObjectId
        i = 0
        notebookId, userId = note["NotebookId"], note["UserId"]
        while i < 10: # 最多10层目录
            i = i + 1
            notebook = leanotedb.notebooks.find_one({"_id": notebookId, "UserId": userId})
            if notebook is not None:
                # print(notebook["Title"])
                cates.append({"Title": notebook["Title"], "UrlTitle": notebook["UrlTitle"], "NotebookId": str(notebookId)})
                notebookId = notebook.get("ParentNotebookId", "")
                if len(str(notebookId)) > 0:
                    continue
                else:
                    break
        cates.reverse()
        # print(cates)
        leanotedb.notes.update_one({"_id": noteId, "UserId": userId}, {"$set": {"Cates": cates}})

if __name__ == '__main__':
    try:
        updateNotebooks()
        updateNotes()
        dbClient.close()
    except Exception as e:
        print(e)
        dbClient.close()

由于我的 leanote 数据库配置没有用户名和密码,在我更新数据库执行上面的 python script 时遇到了数据库认证错误。我更改为了以下版本

#!/usr/bin/python3

import pymongo
from bson.objectid import ObjectId
import sys

if len(sys.argv) < 5:
    host = input('Mongodb Host: ')
    dbname = input('DB Name: ')
    user = input('DB Username: ')
    passwd = input("DB Password: ")
else:
    host, dbname, user, passwd = sys.argv[1], sys.argv[2], sys.argv[3], sys.argv[4]

#dbClient = pymongo.MongoClient(f"mongodb://{user}:{passwd}@{host}:27017/?authSource={dbname}")
dbClient = pymongo.MongoClient(f"mongodb://127.0.0.1:27017/")
leanotedb = dbClient['leanote']

def updateNotebooks():
    for notebook in leanotedb.notebooks.find({"IsDeleted": False}):
        notebookId, userId, parentId = notebook["_id"], notebook["UserId"], notebook.get("ParentNotebookId")
        if parentId is not None:
            parentNotebook =  leanotedb.notebooks.find_one({"_id": parentId, "UserId": userId})
            if parentNotebook is not None:
                childs = parentNotebook.get("ChildNotebookIds", [])
                childs.append(notebookId)
                childs = set([str(c) for c in childs]) # 消除重复
                leanotedb.notebooks.update_one({"_id": parentId, "UserId": userId}, {"$set": {"ChildNotebookIds": [ObjectId(c) for c in childs]}})

def updateNotes():
    for note in leanotedb.notes.find({"IsDeleted": False}):
        cates = []
        noteId = note["_id"] # ObjectId
        i = 0
        notebookId, userId = note["NotebookId"], note["UserId"]
        while i < 10: # 最多10层目录
            i = i + 1
            notebook = leanotedb.notebooks.find_one({"_id": notebookId, "UserId": userId})
            if notebook is not None:
                # print(notebook["Title"])
                cates.append({"Title": notebook["Title"], "UrlTitle": notebook["UrlTitle"], "NotebookId": str(notebookId)})
                notebookId = notebook.get("ParentNotebookId", "")
                if len(str(notebookId)) > 0:
                    continue
                else:
                    break
        cates.reverse()
        # print(cates)
        leanotedb.notes.update_one({"_id": noteId, "UserId": userId}, {"$set": {"Cates": cates}})

if __name__ == '__main__':
    try:
        updateNotebooks()
        updateNotes()
        dbClient.close()
    except Exception as e:
        print(e)
        dbClient.close()

做了两点修改

  1. 数据库认证: dbClient = pymongo.MongoClient(f"mongodb://127.0.0.1:27017/")
  2. 获取数据库实例: leanotedb = dbClient['leanote']

归纳了说,本次更新主题所做的事情的主要步骤

  1. n1 上的 leanote mongodb 数据库备份
  2. 在 x86_64 的机器(我的软路由)上运行 leanote 服务程序
  3. 在软路由上恢复数据库,这样之前写的文章就回来了

    下面的操作都是在软路由上进行的了

  4. 进入容器,通过 apt install 安装 python3pip3,再通过 pip3 安装 pymongo library
  5. 执行修改过的 python 脚本,python3 leanote_2.6.1_to_2.7.0.py 终端让你输入 dhhost dbname username password 可以随便填写了,因为变量值已经在脚本中写死了
  6. 下载帖子作者编译好的 leanote-linux-amd64-2.7.0.zip
  7. 解压缩上面的 zip 文件,取出其中的 leanote-linux-amd64run.sh 替换掉容器中的对应文件,取出其中的 routes 路由声明文件替换掉容器中的对应文件。注意: 操作前请一定记得备份
  8. 重启容器
  9. 导入主题,可以看到分类页面正常工作了,归档页面也能按照文章创建时间排序了(原本只能是发布时间)
  10. 自己修改样式,做一些自定义

上面第9点我想吐嘈一下,我有三个 notebook,每个 notebook 都有若干篇文章公开为了博客,加起来一共几十篇,我对整个notebook设置了公开为博客,后面又给取消了,然后所有文章都不见了!!!也被取消公开博客了…… 一时间气死。好在我还记得哪些文章我有公开为博客,一篇一篇的改了回来,然后就发现了 leanote 2.6.1 归档页面只能根据发布时间排序的bug


后记

本次更换主题的折腾过程还是蛮酸爽的,作者只编译了 linux-amd 程序,没写过 go 的我,速成学习了一下 go 语言,学习了一下项目交叉编译,构建成功了 Linux arm 的可执行程序,但是 arm ubuntu 的安装软件体验实在是不好,依赖问题极其麻烦…… 后面放弃换了 x86_64 真就方便了很多,遇到极少数问题也能很快解决,网上的资料都更多。所以说,生态真是非一日之寒,一旦形成了生态,那么这个平台用户就不会少,平台的未来也就更加光明。

最后欢迎你光临我家里的博客 Allen Hua's another blog