Created
November 30, 2011 07:51
-
-
Save fannheyward/1408378 to your computer and use it in GitHub Desktop.
Import XML of Picky to Octopress
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
require 'fileutils' | |
require 'date' | |
require 'yaml' | |
require 'uri' | |
require 'rexml/document' | |
include REXML | |
doc = Document.new File.new(ARGV[0]) | |
FileUtils.mkdir_p "_posts" | |
doc.elements.each("feed/entry") do |e| | |
post = e.elements | |
slug = post['slug'].text | |
date = DateTime.parse(post['published'].text) | |
name = "%02d-%02d-%02d-%s.markdown" % [date.year, date.month, date.day, slug] | |
content = post['content'].text | |
puts content | |
content = content.gsub(/<code>(.*?)<\/code>/, '`\1`') | |
## 追加 | |
content = content.gsub(/<pre lang="([^"]*)">(.*?)<\/pre>/m, '<div class="bogus-wrapper"><notextile><figure class="code"><figcaption><span>lang:\1 </span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class="line-number">1</span></pre></td><td class="code"><pre><code class=''><span class="line">\2</span></code></pre></td></tr></table></div></figure></notextile></div>') | |
(1..3).each do |i| | |
content = content.gsub(/<h#{i}>([^<]*)<\/h#{i}>/, ('#'*i) + ' \1') | |
end | |
File.open("_posts/#{name}", "w") do |f| | |
f.puts "---" | |
#f.puts data | |
f.puts "layout: post" | |
f.puts "comment: true" | |
f.puts "title: \"#{post['title'].text}\"" | |
f.puts "---" | |
f.puts content | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment