用 Joplin 记笔记很久了,但每次想把写好的笔记发布到 Hexo 博客,过程都挺麻烦的。特别是涉及到图片的笔记,还得手动改链接

其实之前也不是没找过自动化的解决方案,比如这个https://github.com/mark-magic/mark-magic
以及它的前身。算是断断续续有在关注这个项目的进展,最开始的时候还只能用在新建Hexo博客上,现在已经可以支持已有的Hexo博客了。而且不止Hexo,这是一个基于 NodeJS 的优秀工具,目标很宏大,要做成一个通用的数据连接和转换工具,能处理像 Joplin 到 Hugo、Joplin 到 Jekyll,甚至打包小说成 ePub 电子书的各种工作流。

然而,它的强大功能对我这个特定的需求来说,也意味着复杂。在我试过mark-magic后,发现数学公式渲染有问题。看到Github的issue区有人碰到了同样的问题,通过LLM帮忙,我给出了一个可能的修复方案,但我对 NodeJS 开发环境实在不熟,想在本地跑起来测试一下都费劲,更别提按自己的想法去定制了。好消息是作者已经采纳了我的建议修复了这个bug。
不过另外一个问题是,如果Joplin的笔记开头就是一级标题#的话,转换成Hexo post,这个标题会被删掉,我看代码里特地有一块处理这个的,不知道原因。

再去学NodeJS开发不太实际,但是既然感觉别人的轮子用不顺手,就想有没有Python的解决方案,没有的话或许可以自己造一个。幸运的是确实有Joplin Python API,joppy。有了这个就可以开始做脚本了。

当然我的目标只是要创建一个简单的脚本,只做好一件事:把我的 Joplin 笔记转换成 Hexo 博文。我借鉴了 mark-magic 一些idea,比如按标签筛选、按笔记本生成分类、以及在生成前清空目录等,然后用 Python 实现了它们。也就是说,这个脚本主要满足了有下面的需求:

  • 按标签筛选: 我不想发布我写的每一篇笔记。脚本需要能找到那些被标记了“blog”标签的笔记。

  • 处理图片: 手动导出图片、重命名、更新链接是最繁琐的部分。脚本必须能完全自动化这个过程。

  • 保留分类: 在 Joplin 中,我用嵌套的笔记本(如 技术 -> Python)来组织笔记。自然希望能自动将这个结构转换成 Hexo 的分类。

  • 简单且可靠: 每次都执行一次“全新构建”(删除所有之前生成的文件,生成全新的Hexo post文件),确保博客内容和我的笔记保持一致。

同样在LLM的帮助下,花了几个晚上,Joplin-to-Hexo 终于算是可以发布了,虽然再发布之前我自己已经试过好几次了。它连接到 Joplin API(感谢 joppy ),找到笔记,下载所有链接的图片,并生成可直接发布的 Markdown 文件。

具体如何使用,在我的Github仓库readme中已经写得很清楚了,快来试试吧,欢迎反馈和issue。
项目地址:https://github.com/dinayuil/joplin-to-hexo

问LLM一些代码问题,如果是大家公用的库结果可能还好,但是一些专门的领域出错的概率感觉就大很多。最近问Gemini有关NS-3的代码,结果就不尽如人意。但是想到Gemini支持百万级别的上下文,我就想或许可以把NS-3的API文档喂给Gemini。省流,最后还是失败了。官方也只有HTML版本,可能也是因为文档太庞大了不好生成pdf吧。

尝试的过程

API文档没法直接生成PDF,默认是生成HTML,可以修改配置文件生成Latex或者Docbook。Docbook没听说过,但是Latex可以用来生成PDF,这就好办了。

Latex

先修改一下NS-3项目下doc/doxygen.conf文件,配置下面三个条目

1
2
3
GENERATE_LATEX         = YES
USE_PDFLATEX = YES
LATEX_OUTPUT = latex

保存之后运行:

1
./ns3 docs doxygen

之后就能在doc/latex文件夹下找到生成的latex文件。然后用latex编译工具编译成pdf文档。

可惜就在这一步失败了,首先尝试用这个命令编译

1
latexmk -pdf refman.tex

但是报错

1
2
3
! LaTeX Error: Unicode character ┌ (U+250C)

not set up for use with LaTeX.

Gemini建议是在latex/refman.tex文件里加入一个package,

1
\usepackage{fontspec}

并且改用xelatex编译

1
latexmk -xelatex refman.tex

虽然这解决了字符问题,但是新的问题又出现了,编译继续报错

1
TeX capacity exceeded, sorry [pool size=...] 

搜了下解决方案,尝试修改texlive\2025\texmf-dist\web2c\texmf.cnf里的pool_size,也试了在doc/doxygen.conf里禁用生成一些图表

1
2
3
4
5
CALL_GRAPH            = NO
CALLER_GRAPH = NO
COLLABORATION_GRAPH = NO
INCLUDE_GRAPH = NO
INCLUDED_BY_GRAPH = NO

然而都没用,依然报同样的错误,只能作罢。

Docbook

其实在latex编译失败搜索一会找不到解决方法之后就准备放弃了,但是想起来doc/doxygen.conf里提到可以生成Docbook来帮助生成pdf,还是试一试吧。

首先还是修改doc/doxygen.conf,不生成Latex,开启生成Docbook。

1
2
GENERATE_LATEX         = NO
GENERATE_DOCBOOK = YES

依然是运行./ns3 docs doxygen,这次会在doc/docbook文件夹下生成Docbook格式文档。

然后需要安装一些工具,用来把Docbook转换成FO,然后转换成PDF。

1
sudo apt install docbook-xsl xsltproc fop

之后在docbook文件夹下运行命令

1
xsltproc --xinclude /usr/share/xml/docbook/stylesheet/docbook-xsl/fo/docbook.xsl index.xml > refman.fo

需要--xinclude这个选项,不加的话会出现一堆这个错误

1
Element include in namespace 'http://www.w3.org/2001/XInclude' encountered in chapter, but no template matches. 

之后就是等,xsltproc是个线性过程单线程运行,NS-3的API文档又十分庞大,要花很长时间。
结果等到了第二天,还是没跑完,而且也没有任何进度显示,于是还是终止了程序。

HTML转PDF

都试了这么多了,本来想放弃的,但还是继续试了下去,就想看看能不能成功。这次就看看有没有能把HTML文档批量转换成单个PDF文档的工具了。

确实是找到了一个叫wkhtmltopdf的工具,不过也踩了坑。先是直接用apt install,结果一旦使用toc选项,运行就会报错

1
Exit with code 1, due to unknown error. 

Gemini说可能是Ubuntu软件源的问题,建议从官网下载https://github.com/wkhtmltopdf/wkhtmltopdf

先卸载

1
sudo apt remove wkhtmltopdf

然后从deb文件安装

1
sudo dpkg -i xxx.deb

如果提示缺依赖

1
sudo apt -f install

还真是,从官网下载的就可以用toc选项了,但是用这个命令尝试最终生成单个pdf的时候还是报错了

1
wkhtmltopdf --enable-local-file-access --allow /home/liup03/ns-3-dev/doc/html --load-error-handling ignore toc $(find . -name "*.html" | sort) ns3-documentation.pdf

而且也没有详细的错误提示,也只能放弃了

1
Exit with code 1 due to network error: ContentAccessDenied 

意料之外……

突然发现Gemini可以直接导入Github的仓库了,说是仓库文件最多可以有5000个,虽然只试了几个小仓库,但是感觉问答也没什么问题,后面可以试试把NS-3仓库喂给它。

https://wiki.archlinux.org/title/TeX_Live

I followed the instruction for Native TeX Live

After installing, I also need to add some environment variable. I edited ~/.bash_profile file, added the following lines at the end of the file:

1
2
3
4
# TeX Live paths
export PATH="~/texlive/bin/x86_64-linux:$PATH"
export MANPATH="~/texlive/texmf-dist/doc/man:$MANPATH"
export INFOPATH="~/texlive/texmf-dist/doc/info:$INFOPATH"

Because I install Tex live at ~/texlive folder, I use the paths above.

To apply them immediately to the current terminal session, run the source command:

1
source ~/.bash_profile

I use Joplin for note taking, and it’s a necessary software for me now. The Joplin data folder is in the NTFS driver so they are safe after I install Arch. It is known for a long time that Joplin does not allow (at least officially inside Joplin) the user to set a custom path for data storage.

Install from Discover (flatpak)

I first tried to install Joplin on Arch from the KDE Plasma’s Discover. I saw Joplin created a data folder (profile folder) at ~/.config/joplin-desktop.

Then I created a symbolink: I link ~/.config/joplin-desktop to the folder in the NTFS drive.

1
ln -s [TARGET] [LINK_NAME]

Before I use symbolink Joplin can start normally, however, after I use the link Joplin GUI no longer appear. Though I can see in the system monitor that Joplin is running, there is not even an error message popped up.

Install from AUR

I don’t know what cause the problem, but I can try to use other versions.
Thus, I tried to install Joplin from AUR. I didn’t managed to do that. Installation failed because it requires nodejs<23. I don’t understand, but I tried to install nodejs and saw the version is higher than 23. Well, I’d not bother with the versioning things. So, I gave up this way.

Install from AppImage

In fact, we don’t even need to “install”. Just make the file executable and double click, then it will run. And, importantly, it works with the symbolink profile folder.

enable bluetooth

安装好Arch linux之后发现没有蓝牙,在设置里也启用不了,才发现要用命令行

1
sudo systemctl enable --now bluetooth

https://arch.icekylin.online/guide/rookie/desktop-env-and-app#_11-启动蓝牙-若有

install Chinese fonts

There is a list of Chinese fonts:
https://wiki.archlinux.org/title/Localization/Simplified_Chinese

just just pacman to install one and then the firefox display Chinese characters correctly.

Laggy and flickering external monitor

Desktop environment: KDE plasma.

My laptop has an Intel integrated GPU and a GTX 1050 GPU. At the arch linstallation step, I choose the “all open source” for GPU drivers.

Once I connected an external monitor to my laptop, the good news was that the monitor was recognized and showed graphics; while the bad news was that there was tearing or laggy on the external dispay. The first idea was to install the nvidia drivers.

https://arch.icekylin.online/guide/rookie/graphic-driver#独立显卡

https://wiki.archlinux.org/title/NVIDIA

I installed nvidia nvidia-settings packages. After reboot, the external display was no longer laggy, but became flickering.

Nvidia Optimus

It seems a tool to make it easier to switch between integrated GPU and the descrete GPU. However, after installed, I found that it doesn’t support wayland. This gave me a hint that the problem might due to some incompatibility between Nvidia driver and wayland.

Although I later switched from wayland to xorg, I didn’t use it as I don’t understand its configurations. As long as now my external monitor works well, I don’t bother with it.

Solution

Switch from wayland to xorg session.

https://archlinux.org/news/plasma-640-will-need-manual-intervention-if-you-are-on-x11/

  1. Install plasma-x11-session.
  2. Log out.
  3. Log in with Xorg session.

Done!

vertical panel date time too small

When I changed the panel from bottom to left vertical, the clock and date became very small, nearly not readable. After some exploration, I found that KDE Plasma offers a flexible way to customize the desktop panels.

I can create multiple panels on the desktop, and each panel can contain multiple widgets. The Clock is just a widget. So, I create an Application Menu Bar panel at the top, and move the clock widget to that panel.

French input method with QWERTY keyboard

https://chakra-zh.blogspot.com/2012/09/chakra.html

  1. First need to install Fcitx5
  2. Settign -> Input Method -> Add Input Method…
    • Find “Keyboard - English (US) - English (US, intl., with dead keys)”

Auto mount NTFS disk

There are two storage drives on my lapto, one is used for OS, another is for data storage. Of course, both are originally used under Windows so they used NTFS file system. The one used for installing Arch OS has been formatted to ext4. The other one is not changed. After all, I don’t want to erase the data on it. Thus, I choose to cotinue use NTFS under Arch OS. Fortunately it’s not a big problem, Arch kernel already support NTFS file system.

  1. use the following command to list available disks
1
lsblk -f

In my case, I see my unmounted disk is sda, and the largest partition is sda2, and we get the UUID of it. I decide to mount this device to /mnt/ntfsssd.

  1. edit the file /etc/fstab, add the disk partition, save the file.
1
2
# <file system>        <mount point>   <type>   <options>                                <dump>  <pass>
UUID=8E76D90B76D8F545 /mnt/ntfsssd ntfs defaults,uid=1000,gid=1000,windows_names 0 0

Options explaination

  • UUID=8E76D90B76D8F545: This is the unique identifier for your disk partition. Using the UUID is more reliable than using the device path (e.g., /dev/sda2).

  • /mnt/ntfsssd: The directory where the filesystem will be mounted. You must create this directory first if it doesn’t exist: sudo mkdir -p /mnt/ntfsssd.

  • ntfs3: This specifies the filesystem type.

  • defaults,uid=1000,gid=1000,windows_names: These are the mount options.

    • defaults: A standard set of options suitable for most cases.

    • uid=1000, gid=1000: These set the ownership of the mounted files to your user. NTFS doesn’t support standard Linux permissions, so this makes your user the owner, giving you full read/write access. You can find your specific uid and gid by running the id command in your terminal. 1000 is the standard for the first user created on most systems.

    • windows_names: This option prevents you from creating files with names or characters that are illegal on Windows, which is useful for cross-platform compatibility.

  • 0 (dump): This disables the dump utility for this filesystem, which is standard for NTFS.

  • 0 (pass): This tells the fsck utility not to check this filesystem for errors at boot time, as Linux’s fsck can’t repair NTFS partitions.

  1. test if it works
1
sudo mount -a

After running the command, I get this hint:

mount: (hint) your fstab has been modified, but systemd still uses
the old version; use ‘systemctl daemon-reload’ to reload.

The NTFS drive now works fine.

Manage AppImages

Although it might be a preferable way to install software on Arch by using pacman or yay (AUR), I still find that AppImage is a simple “ready to use” way.

I also firstly tried to install an AppImage manager from Discover, called Gear Lever. Unfortunately, it doesn’t work - adding AppImage files into Gear Lever always failed.

I then installed another one called AppImageLauncher (https://github.com/TheAssassin/AppImageLauncher), and it works.

However, when I tried to run QQ AppImage file(downloaded from official site), AppImageLauncher didn’t managed to create a shortcut in the start menu, with an error message Failed to register AppImage in system via libappimage.

Show Caps Lock and Num Lock status

Although there is no on screen notification for status change of Caps lock and Num lock, there is a way to show the status by system tray. The System Tray widget has an entry Lock Keys Status. Set it to always shown or shown when relevant, then a status of lock keys will be shown in the system tray when enabled.

https://discuss.kde.org/t/caps-lock-numpad-osd-indicator/12934

0%