Recently I migrated from Wordpress to static blog generator Hexo.io. I also modified default hexo-wordpress-migrator a little bit in order to support Yoast seo meta keywords and description, [code] blocks and more tag.

But Wordpress is great, why did I switch from it?

While Wordpress has a lot of great features and modules, I was not using them. I felt that Wordpress had just too much functions and code for such a simple blog as mine. And what could be simpler than Markdown and static files?

Also wysiwyg online interface didn’t work well for me. I usually post some code examples and have to manually prepare them in some other editor before posting into Wordpress. I do proper formatting as it’s impossible to do TAB or Shift+TAB and other things in browser.

It would be great to use just one editor to do it all, that is VS Code, which btw is great!:)

Also as I switched to Node.js/Javascript a year ago, keeping PHP running on the server was somewhat annoying.

All in all Wordpress seemed like an overkill.

Hexo

Hexo.io is a static blog generator which supports Markdown. It seems pretty mature, stable and has a lot of modules and themes. That means I have to spend less time setting up blog and more time writing.

And it’s javascript! So I already had everything in order to run it.

Installation is pretty simple, install it from npm, init new blog and create some markdown files. There are several automatic deploy options provided or you can just copy all your files to remote server.

Hexo provides migration options as well. In order to migrate from Wordpress there is hexo-migrator-wordpress plugin (https://hexo.io/docs/migration.html#WordPress)

Migrating from Wordpress with yoast plugin to Hexo

My WP blog was using Yoast seo plugin and it was not supported by default migrator plugin. So I had to add it manually. Then I added <!--more--> wordpress tag support as my theme allowed it. Also I converted [code] tags to markdown code and removed <pre> tags.

If you need it, here is what to do. Feel free to modify as needed.

In your blog directory open node_modules/hexo-migrator-wordpress/index.js

Find lines with fiels definitions and modify as follows

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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
...
var title = item.title[0],
id = item['wp:post_id'][0],
date = item['wp:post_date'][0],
slug = item['wp:post_name'][0],
content = item['content:encoded'][0],
comment = item['wp:comment_status'][0],
status = item['wp:status'][0],
type = item['wp:post_type'][0],
meta_description = item['wp:postmeta'].find(meta => meta['wp:meta_key'] == '_yoast_wpseo_metadesc'), // added
meta_keywords = item['wp:postmeta'].find(meta => meta['wp:meta_key'] == '_yoast_wpseo_metakeywords') // added
categories = [],
tags = [];
if (!title && !slug) return next();
if (type !== 'post' && type !== 'page') return next();
if (typeof content !== 'string') content = '';
content = tomd(content).replace(/\r\n/g, '\n');
count++;
if (item.category){
item.category.forEach(function(category, next){
var name = category._;
switch (category.$.domain){
case 'category':
categories.push(name);
break;
case 'post_tag':
tags.push(name);
break;
}
});
}
if(meta_keywords) { // added
tags = tags.concat(meta_keywords['wp:meta_value'][0].split(',').map(s => s.trim()))
}
var data = {
title: title || slug,
id: +id,
date: date,
content: content,
layout: status === 'draft' ? 'draft' : 'post',
description: meta_description ? meta_description['wp:meta_value'][0] : title, // added
}
data.content = data.content // added - convert [code] to markdown and remove pre tags
.replace(/<pre>/gim, '')
.replace(/<\/pre>/gim, '')
.replace(/\n\n/gim, '\n \n')
.replace(/(\[code(.*?)\])/gim, '```$2')
.replace(/(\[\/code(.*?)\])/gim, '```$2')
if(data.content.indexOf('<!--more-->') === -1) { // added - more tag
data.content +='<!--more-->';
}

That’s it, your new blog posts will get nice tags and description and native markdown code formatting. You probably will still have to fix some things manually, but it’s a good place to start.