转移hexo文章至Hugo

Github源代码地址:https://github.com/aimer1124/python-format-md 为什么做这个: 把原来博客的文章从Hexo转移至Hugo,但两者在MD文件头部处理不一致。 Hexo格式 1 2 3 4 5 6 7 8 9 title: 'Http-Header' tags: - API测试 - SuperTest categories: - Tool date: 2016-02-29 20:14:00 thumbnail: /img/a.png --- Hugo格式 1 2 3 4 5 6 7 8 9 --- title: 'Http-Header' tags: - API测试 - SuperTest categories: - Tool date: 2016-02-29 20:14:00 --- 暂时发现,需要处理的内容有两处: 在文件首行添加--- 删除MD文件Header中的thumbnail字段(nice to have) Function Read MD file content Create source MD file Create covert file Read MD file Save the change to MD file Make Change to the MD file Save the change to New file Add --- to the first line of the MD file Delete thumbnail in the file format Find thumbnail line Delete the line Batch to update MD files in the folder read the list in the folder make the convert to the file in the list save the new file to the new folder Day by Day Day 1 Set source md file, source.md Create convert.py as convert controller Use open(file, "r").read() to get MD file content Day 2 Make Change and save to new MD file Add --- to new MD file Delete the line with thumbnail 1 2 lines = (i for i in sourceFile if 'thumbnail' not in i ) targetFile.writelines(lines) Use readlines to convert file: list.insert(index,obj) for add --- and list.remove(obj) for delete thumbnail 1 2 3 4 5 6 7 8 9 sourceFileList = sourceFile.readlines() sourceFileList.insert(0,"---\n") for line in sourceFileList: print(line) if "thumbnail" in line: sourceFileList.remove(line) targetFile.writelines(sourceFileList) Day 3 Refactor the code 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 def convert(sourceFile, targetFile): sourceFile = open(source, "r") targetFile = open(target,"w") sourceFileList = sourceFile.readlines() sourceFileList.insert(0,"---\n") for line in sourceFileList: # print(line) if "thumbnail" in line: sourceFileList.remove(line) targetFile.writelines(sourceFileList) targetFile.close() sourceFile.close() Get the list in the folder 1 2 import os sourceFileList = os.listdir(sourcePath) Convert the files 1 2 3 4 5 for fileName in sourceFileList: print("Convert file: " + fileName) target = "./target.md" convert(sourcePath + fileName, targetPath + fileName) 参考 文件读写: https://www.runoob.com/python/python-files-io.html Python List: https://www.runoob.com/python/python-lists.html Python File: https://www.runoob.com/python/os-listdir.html

March 31, 2020 · 2 min · Yuanjie

选择一个好的Hexo主题

诉求:找一个好用的Hexo主题 方法 去官网看了下,Theme有285个,按名字排名。没有任何星级或者推荐之类的,看了下,眼花缭乱。https://hexo.io/themes/ 在知乎上面搜索了下,高赞答案:爬取Theme的Star数量,用数据说话。https://www.zhihu.com/question/24422335/answer/46357100。但数据是2015年的,过去5年了。 要不自己写个爬虫玩一玩?爬下现在的数据是怎样的 Repo:https://github.com/aimer1124/hexo-theme-spider 需求管理:https://github.com/aimer1124/hexo-theme-spider/projects/1 结果展示:

January 4, 2020 · 1 min · Yuanjie

个人网站搭建

套餐 Github + Hexo + Travis Github 源文件和网站资源的管理 Hexo 网站内容的生成 Travis 打通Github+Travis ...

February 18, 2019 · 2 min · Yuanjie

站点搭建过程

20220325 更新hugo版本,重新写起来 更新hugo版本至0.95 添加HCIA文章 20200402 启用网站本地搜索功能 启用本地搜索功能 使用百度搜索 20200401 CodeStyle变更为monokai 调整Code Style为monokai 20200325 ECS+备案 重大更新 站点生成从Hexo转移至Hugo 将源公开站点信息拖管至Github的Private仓库 将站点资源部署在阿里云的ECS中,在阿里云中申请SSL证书并关联网站 申请网站备案号 原有busuanzi统计全部失效,重新统计 按类型整理源文章,更新至对应的Folder 20200108 Donate 增加Donate功能(Alipay & wechat) 关闭右侧Tag功能 20200104 icarus主题 添加Theme Module,切换Theme至icarus git submodule add https://github.com/aimer1124/hexo-theme-icarus themes/icarus 20191225 更新Hexo版本 更新Node:12, Hexo:4 20191217 增加HTTPS 增加站点的HTTPS的功能,https://shiyuanjie.cn 20191216 替换留言功能Valine 更新留言功能至Valine,Theme Update git submodule update --init --remote -- themes/themeHexo ga themes/themeHexo gc -m 'Update Comments Plugin' gp 20181018 弃用Qiniu 由于qiniu官网的更新 每30天就会更换测试域名的地址,如果继续用未备案的域名的话,每30天就要把整个网站床图地址更新一遍,用了后期便于维护,把所有相关的图片都从qiniu迁移至github进行托管 20181017 启用卜算子统计 更新busuanzi官方链接:busuanzi.ibruce.info 20170322 评论转为Disqus 由于之前用的评论插件多说要关闭服务了,所以将评论的内容转移至Disqus 由于迁移后的原评论无法直接导入,所以原有评论均被清空了 , 20160926 添加本站的累积访问数据 添加页脚的访问总量和访客数 ...

January 30, 2016 · 4 min · Yuanjie