Migrate From Wordpress to Farbox

Migrate From Wordpress to Farbox

Category & Tags:

see also: Blogs, Knowledge base

Backup wordpress #

  1. Manually backup everything: db & files. // or using Updraftplubs.
  2. Change permalinks to not containing post-names.
  3. Using wp plugin Simply Static to generate .html files as 2nd backup, cuz hexo will lose something when converting to .md files.

Moving Post Content #

OBS: see those following notes before proceed to migrate:

  • embedded multi-media and comments will be lost.
  • the official wp2md.farbox.com is not working well, so I used hexo’s plugin
  • hexo didn’t generate the original url in md meta-data, to optimize for farbox, see here.
  • utf-post-name causes md file names to be html-encoded. fixed by @dengshilong, github. My origin solution: modify db: `ALTER TABLE wp_posts DROP COLUMN post_name;``
  • someone suggests WordPress Jekyll Exporter, cuz it can support more html content (only iframe is not supported) but got timeout no response error.
  • ref 1 , ref 2.

steps for moving posts (using windows) #

  1. Export to .xml: wp-admin > control panel > tool > export > all.
  2. Import: convert .xml to .md.
    (1). install Github deskop for windows
    (2). install node.js windows 64bit
    (3). start > all > Gti Shell > cd c:\folder.and.path\to\some.new.hexo.site.folder to the folder you want to save .md files.
    (4). convert .xml to .md using the code showing below, and mv .md to farbox site folder.
npm install -g hexo -verbose  # ignore WARNs. only errors will be considered.
hexo init # only for first-time. for copying from other place, ignore this.
npm install # for hexo dependencies
hexo server # or hexo s, to start a local server at localhost://4000
# after checking hexo is ok, ctrl+c to quit server
npm install hexo-migrator-wordpress --save
hexo migrate wordpress yourBlog.wordpress.exported.file.YYYY-mm-dd.xml

Routing #

As I used only post date, time and id in the URL, redirection is necessary for old URLs and SEO.
Old style: /year/mon/day/id/post-name.html
New style: /year/mon/day/id/

part 1: js. #

Using site.com/template/404.html
Just add this at the top of template:

var path = "{{ request.path }}";
if (path.match(/html/g)) {
  window.location.href =
    "http://dmml.nu/" +
    path.replace(/(\d+\/)(\d+\/)(\d+\/)(\d+\/)(.*)html/g, "$1$2$3$4");

Problem: it will give 404 http header.

part 2: template: jinja2/jade #

To avoid xxx.farbox.com domain, force personal domain:

{% if request.host == 'your.farbox.com' %} {{ redirect('http://yourdomain.com' + request.url_without_host ) }}{%endif%}

This should be done for all template files
See ref here.

Sync #

option 1: using Farbox Editor #

So we can uses any folder in hard drive, farbox editor will take care of the sync.
When using another device, web editor can be used.

option 2: using dropbox #

I have to admit that dropbox is the best sync service.
It is proved again.
Farbox Editor is ok for a normal user, but for a programmer, it cannnot handle complicated situation.
Thus, I am using dropbox now.

Category #

No need to worry, the same as wordpress.

Sitemap #

See here

Rss #

Similar to wp.

Spider #

pro-active baidu submit #

Append to base.jade:

script(function () {
  var bp = document.createElement("script");
  var curProtocol = window.location.protocol.split(":")[0];
  if (curProtocol === "https") {
    bp.src = "https://zz.bdstatic.com/linksubmit/push.js";
  } else {
    bp.src = "http://push.zhanzhang.baidu.com/push.js";
  var s = document.getElementsByTagName("script")[0];
  s.parentNode.insertBefore(bp, s);

robots.txt #

The same as wordpress.
s.parentNode.insertBefore(bp, s);

## robots.txt

The same as wordpress.