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

推荐订阅源

WordPress大学
WordPress大学
L
LangChain Blog
酷 壳 – CoolShell
酷 壳 – CoolShell
罗磊的独立博客
J
Java Code Geeks
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
博客园 - 叶小钗
小众软件
小众软件
博客园 - Franky
D
Docker
Google DeepMind News
Google DeepMind News
Microsoft Azure Blog
Microsoft Azure Blog
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
U
Unit 42
宝玉的分享
宝玉的分享
C
Check Point Blog
B
Blog
V
V2EX
博客园 - 三生石上(FineUI控件)
MyScale Blog
MyScale Blog
The Cloudflare Blog
博客园 - 聂微东
博客园_首页
Engineering at Meta
Engineering at Meta

林中阴影

林中阴影 | 关于蓝光刻录的一些调查 林中阴影 | 与IPv6地址战斗 林中阴影 | 半年前的NAS升级 林中阴影 | “智能” 家居笔记:一→两年后的回顾 林中阴影 | 旧手机做RDP客户端的一些尝试 林中阴影 | 一些矿渣的耗电量 林中阴影 | 穷人的IP-KVM远程访问 林中阴影 | 内网访问第三季:在运营商的CGNAT网络下 林中阴影 | “智能”家居笔记,其之二 林中阴影 | “智能”家居笔记,其之一 林中阴影 | 仅IPv6家庭内网服务实现v6+v4双栈访问 林中阴影 | 下载装小蜜监理拍摄的图片 林中阴影 | 几物互联 林中阴影 | 整了个“新”平板 林中阴影 | 获取招商信用卡账单的另一种方法 林中阴影 | 我在GitHub的⭐ 林中阴影 | Python与光学计算,2021 林中阴影 | 你可能并不需要内网穿透 林中阴影 | 2020 林中阴影 | 和(基本上)什么也不能连的电脑传递信息 林中阴影 | 我将贻笑于大方之家 林中阴影 | 一个新主题 林中阴影 | 2019过去了,我…… 林中阴影 | Beancount试用,半年后 林中阴影 | 自动输入剪贴板中的内容 林中阴影 | Unicode与数学公式 林中阴影 | Python中光学计算相关的库/Awesome Python for Optics 林中阴影 | 一本厕纸小说 林中阴影 | 震惊!为了在Windows上访问EXT4分区,他竟然做出了这样的事! 林中阴影 | 我的2018
林中阴影 | 由wordpress到hugo:I
2017-06-07 · via 林中阴影

我之前的wordpress博客是建在redhat公司的OpenShift服务上的,距上次我更换博客后台过了快两年时间,wordpress(或是PHP)再次把空间占满了,而不懂PHP的我只能对着SFTP干瞪眼。于是,我又种了一棵新的树苗。

wordpress的文章是通过wordpress-to-hugo-exporter导出的,但是导出的文件有一些小问题:

  • 标题里都是<span>
  • 正文还是HTML格式
  • imgcode需要修改

对于正文,可以用pandocpypandoc转换:

import pypandoc,os
root = "./content"

for rt, dirs, files in os.walk(root):
    for filename in files:
        with open(os.path.join(rt, filename), 'r', encoding='utf-8') as fin:
            data = fin.read()
        ds = data.split('---')
        ds[2] = pypandoc.convert_text(ds[2], 'md', format='html')
        do = '---\n'.join(ds)
        with open(filename, 'w', encoding='utf-8') as file:
            file.write(do)

其他的……手改保平安……

……

……………

漫长的修改过后,用hugo server -w预览。

这时候还有一个小问题:hugo生成URL不一定遵循文件头url定义,比如,对 /2016/06/13/qart-coder:更友好的qr码/hugo会解析为/2016/06/13/qart-coder更友好的qr码/。看出区别了吗?

为了保证(不知道和谁的)兼容性,可以在文件头中增加aliases行,可以将原来的地址转发到新地址。

同样的,我也写了一个辣鸡脚本:

import pypandoc
import os
root = "./content"
for rt, dirs, files in os.walk(root):
    for filename in files:
        with open(os.path.join(rt, filename), 'r', encoding='utf-8') as fin:
            data = fin.readlines()
            try:
                urlIndex = [n for n, l in enumerate(data) if l.find("url:") != -1][0]
                url = data[urlIndex].split("url:")[1]
                aliasLine = "  -" + url
                data.insert(urlIndex + 1, aliasLine)
                data.insert(urlIndex + 1, "aliases:\n")
            except:
                pass
        with open(filename, 'w', encoding='utf-8') as file:
            for d in data:
                file.write(d)