从 Typecho 迁移至 Pelican

2021-03-01
1 min read
  1. 通过 phpMyAdmin 导出 json 格式的 tyecho_content 数据表

  2. 删除文件头部注释信息

  3. 执行脚本,生成pelican内容文件。

#!/usr/bin/python3
import time
import json
f = read('typecho_contents.json','r')
j = json.load(f)
f.close()
for i in j:
    title = i['title']
    slug = i['slug']
    cid = i['cid']
    date = time.strftime("%Y-%m-%d %H:%M:%S",time.localtime(int(i['created'])))
    modified = time.strftime("%Y-%m-%d %H:%M:%S",time.localtime(int(i['modified'])))
    text = i['text'].replace('<!--markdown-->','')
    if 'png' not in i['title'] and 'jpg' not in i['title']:
        otext = 'title:{title}\ndate:{date}\nmodified:{modified}\nslug:{slug}\n{text}'.format(title=title,date=date,modified=modified,slug=slug,text=text)
        ofile = open('./output/'+title+'.md','w')
        ofile.write(otext)
        ofile.close()