Skip to content

Instantly share code, notes, and snippets.

@apaleslimghost
Created February 9, 2014 21:08
Show Gist options
  • Save apaleslimghost/8905941 to your computer and use it in GitHub Desktop.
Save apaleslimghost/8905941 to your computer and use it in GitHub Desktop.
Convert Tumblr dump to Jekyll posts
{posts, blog} = require './download.json'
pandoc = require \pandoc
fs = require \fs
photos = (.join '') . (.map -> """<img src="#{it.original_size.url}" width="#{it.original_size.width}" height="#{it.original_size.height}" alt="#{it.caption}">""")
pad = (n, s)->
p = n - s.to-string!length
('0' * p) + s
for let post in posts
date = new Date post.timestamp * 1000
date-str = "#{date.get-full-year!}-#{pad 2 date.get-month! + 1}-#{pad 2 date.get-date!}"
filename = "#{date-str}-#{post.slug}.html"
preamble = post{slug, id, title, type, date, tags, url}
body = switch
| post.body => that
| post.description => that
| post.photos => post.caption + photos post.photos
| post.player => (post.player.0.embed_code ? post.player) + post.caption
| otherwise => ' '
<- fs.write-file do
"_posts/#filename"
"""
---
#{JSON.stringify preamble, null 2}
---
#body
"""
console.log filename
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment