class Hikkoshi::Jekyll::Exporter

@example Basic Usage

posts = Hikkoshi::Logdown::Importer.new("~/blog-backup/")
exporter = Hikkoshi::Jekyll::Exporter.new(posts)
exporter.export("~/new-blog/_posts")

@example Customize file name

posts = Hikkoshi::Logdown::Importer.new("~/blog-backup/")
exporter = Hikkoshi::Jekyll::Exporter.new(posts)
exporter.filename_formatter = -> (post) {
  "#{post.date.strftime('%F')}-#{post.slug}.md"
}
exporter.export("~/new-blog/_posts")

Attributes

filename_formatter[RW]

Public Instance Methods

export(path) click to toggle source
# File lib/hikkoshi/jekyll/exporter.rb, line 18
def export(path)
  path = File.expand_path(path)

  @posts.each do |post|
    generate_post(post, path)
  end
end

Private Instance Methods

format_post(post) click to toggle source
# File lib/hikkoshi/jekyll/exporter.rb, line 40
def format_post(post)
  "#{YAML.dump(metadata(post))}\n---\n#{post.content}"
end
generate_post(post, into_path) click to toggle source
# File lib/hikkoshi/jekyll/exporter.rb, line 32
def generate_post(post, into_path)
  path = File.join(into_path, filename_formatter(post))

  File.open(path, "w") do |fout|
    fout.write format_post(post)
  end
end
metadata(post) click to toggle source
# File lib/hikkoshi/jekyll/exporter.rb, line 44
def metadata(post)
  {
    "layout" => post.layout,
    "title" => post.title,
    "published" => post.status == "published",
    "date" => post.published_at.strftime("%F %R"),
    "tags" => post.tags,
    "categories" => post.categories,
    "comments" => post.comments
  }
end