Insert images in hexo with tag plugin instead of markdown

Use markdown syntax can only show the images in articles but not in homepage and archive.
So, just write a python script to replace markdown image syntax with hexo tag plugin.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
import os
import re

os.chdir('./source/_posts')
for md in os.listdir('.'):
# md = os.path.join(root, md)
md = os.path.abspath(md)
print(md)
if os.path.isfile(md):
with open(md) as r:
s = r.read()

with open(md, 'w') as w:
s = re.sub(r"!\[([\S ]+)\]\((\S+)\)", r"{% asset_img \2 \1 %}", s)
w.write(s)