Typecho 迁移 Hexo 指南
秉着将白嫖进行到底的宗旨,决定不再续费 VPS,博客从转移到 Github,使用 Hexo。
第一步:将 Typecho 文章转为 Hexo 文章格式
Hexo 的文章在网站\source\_posts\
目录下,Markdown 格式,内容包含了文章标题、发布时间、更新时间、分类、标签、固定连接、文章内容等信息,所以流程就是从 Typecho 数据库中查询出这些数据,拼接成 Hexo 文章的格式,写入.md
文件。
查询文章 SQL:
select title,slug,text,created,modified,category,tags from typecho_contents c,(select cid,group_concat(m.name) tags from typecho_metas m,typecho_relationships r where m.mid=r.mid and m.type='tag' group by cid ) t1,(select cid,m.name category from typecho_metas m,typecho_relationships r where m.mid=r.mid and m.type='category') t2 where t1.cid=t2.cid and c.cid=t1.cid
结果入下:
slug
为固定链接,需要将文件名设置为此;text
为文章内容,由于我Typecho文章设置的是 Markdown 格式,所以只需要将<!--markdown-->
这段内容替换为空即可;created
和modified
为发布时间和更新时间,需要转换为字符串,moment.unix(post.created).format("YYYY-MM-DD HH:mm:ss")
;category
和tags
可能有多个,"tags:\n- " + tags.replace(',',"\n- ") + "\n"
;