最近又重装了一下系统,之前博客是在Windows下面的,最近我把那个Windows系统删了,先在OSX上面用一段时间。但是发现整个博客的程序近乎报废,图片加载不了,公式显示不了。。。然后开始一步一步修理。
重装 node
装 hexo
新建一个目录,在里面
hexo init
,删除 post 里面的 hello world把原来博客的_config.yml, scaffolds, source, themes,这四个东西复制到新的 blog 里面
hexo clean && hexo s -g
本地启动一下博客,进入 blog 里面看看有什么错误提示,缺什么插件就装什么插件卸载默认的 render:
npm un hexo-renderer-marked -save
安装新的 render:
npm install hexo-renderer-kramed --save
,然后修改 node_modules\kramed\lib\rules\inline.js修改以下内容:
1 2
//escape: /^\\([\\`*{}\[\]()#$+\-.!\_>])/, escape: /^\\([`*\[\]()#$+\-.!_>])/,
1 2
//em: /^\b_((?:__|[\s\S])+?)_\b|^\*((?:\*\*|[\s\S])+?)\*(?!\*)/, em: /^\*((?:\*\*|[\s\S])+?)\*(?!\*)/,
npm install https://github.com/7ym0n/hexo-asset-image --sa
,装这个修正后的图片工具然后要写一个程序,把所有文章里面的
![Figure2](Fig2.png)
这个 markdown 插入图片的语法,换成\{\% asset_img Fig2.png Figure2 \%\}
,这里需要把我自己加的这四个反斜杠""去掉,我这里加上是因为如果不加的话,这里就变成图片了。。。先备份好博客,然后运行下面的代码即可。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
import re import os folder = 'source/_posts/' pattern = re.compile('!\[(.*?)\]\((.*?)\)') for fname in os.listdir(folder): if not fname.endswith('.md'): continue path = os.path.join(folder, fname) with open(path, 'r') as f: content = f.read() markdown_pics = re.findall(pattern, content) for desc, pic_name in markdown_pics: original_str = '![{}]({})'.format(desc, pic_name) if ' ' in desc: desc = '"' + desc + '"' if ' ' in pic_name: pic_name = '"' + pic_name + '"' target_str = '{![{}](/blog/images/博客重装/{})}'.format(pic_name, desc) content = content.replace(original_str, target_str) print(fname, original_str, target_str) with open(path, 'w') as f: f.write(content)
然后就OK了,心情舒畅~