将gitblog 的头转换成hugo 的头
使用命令运行
find . -name "*.md"|while read file; do python gitlab2hugo.py $file; done
保存文件为 gitlab2hugo.py
import os
import re
import sys
file=sys.argv[1]
head=""
body=""
step=0
info={}
for line in open(file):
#print(line)
if line=="<!--\n":
step=1
continue
if line=="-->\n":
step=2
continue
if step==1:
key,value=line.split(":")
info[key]=value.strip()
if step==2:
body+=line
if step<2:
print("no info")
sys.exit(0)
head+="+++\n"
head+="title = \"" + info["title"] +"\"\n"
head+="date= \"" + info["date"] +"\"\n"
head+="categories= [\"" + info["category"] +"\"]\n"
head+="+++\n"
#print(head)
#print(body)
fo = open(file, "w")
fo.write(head)
fo.write(body)
fo.close()