Skip to content

Instantly share code, notes, and snippets.

@meredrica
Last active September 23, 2016 01:40
Show Gist options
  • Save meredrica/088f5a593a2a7184202850c58bcb48d1 to your computer and use it in GitHub Desktop.
Save meredrica/088f5a593a2a7184202850c58bcb48d1 to your computer and use it in GitHub Desktop.
script to migrate my blogs from blogger to hexo
#!/bin/bash
# remove what's there
rm source/_posts/*.md
# download blogs
node_modules/.bin/hexo migrate blogger 'http://blog.meredrica.org/feeds/posts/default?alt=json&max-results=10000'
node_modules/.bin/hexo migrate blogger 'http://jujitsu.westreicher.org/feeds/posts/default?alt=json&max-results=10000'
# fix image links generated by migrate
# they will look like this: [![](link to small img)](link to larg img)
# this is an image that is the anchor text to the big immage
# this perl command replaces the anchor and inserts a new image tag that points to the large one
#
# regex broken down
#
# \[!\[]\(http.*?\)]
# matches the start of the anchor tag like: [![] (http:...)]
#
# (\(http.*?\))
# matches the second part (http:....) including the brackets and captures it in group 1
#
# this part of the regex produces the new image tag with the matched group 1
# ![]\1
#
perl -p -i -e 's/\[!\[]\(http.*?\)](\(http.*?\))/![]\1/g' source/_posts/*
# download the images to the local folder
node_modules/.bin/hexo migrate image
# strip all html tags and their attributes
perl -p -i -e 's/<.*?>//g' source/_posts/*
# replace all occurances of mor than 3 empty lines with just two of them
# this is required because the blogger migrate creates a lot of empty lines
# the tag replacement from above then creates even more
perl -0 -p -i -e 's/\n{3,}/\n\n/g' source/_posts/*
# remove all generated .bak files
rm source/_posts/*.bak
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment