Skip to content

Instantly share code, notes, and snippets.

@yutingzhao1991
Created September 9, 2014 00:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yutingzhao1991/86238c8a61e5620bdcfe to your computer and use it in GitHub Desktop.
Save yutingzhao1991/86238c8a61e5620bdcfe to your computer and use it in GitHub Desktop.
将点点网的BLOG导出的XML转化Markdown格式的文件
var cheerio = require('cheerio')
var fs = require('fs')
var moment = require('moment')
var upndown = require('upndown')
var text = fs.readFileSync("blogs.xml", 'utf8')
var $ = cheerio.load(text)
var posts = $('post')
posts.each(function () {
var post = $(this)
var title = post.find('Title').text()
var htmlText = post.find('Text').text()
var date = new Date(parseInt(post.find('CreateTime').text()))
var dashDate = moment(date).format('YYYY-MM-DD')
// date: 9:29 2013/7/28
var blogDate = moment(date).format('HH:mm YYYY/MM/DD')
var fileName = dashDate + '-' + title.replace(/\s/g, '_')
var und = new upndown()
var markdown = und.convert(htmlText)
var content = '---\n\
title: ' + title + '\n\
date: ' + blogDate + '\n\
layout: post\n\
---\n' + markdown
fs.writeFileSync(fileName + '.md', content, {
encoding: 'utf8',
flag: 'w'
})
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment