Class: JekyllImport::Importers::Ghost
Class Method Summary
collapse
inherited, run, stringify_keys, subclasses
Class Method Details
.fetch_posts(dbfile) ⇒ Object
31
32
33
34
35
|
# File 'lib/jekyll-import/importers/ghost.rb', line 31
def fetch_posts(dbfile)
db = Sequel.sqlite(dbfile)
query = "SELECT `title`, `slug`, `markdown`, `created_at`, `published_at`, `status`, `page` FROM posts"
db[query]
end
|
.process(options) ⇒ Object
18
19
20
21
22
23
24
25
26
27
|
# File 'lib/jekyll-import/importers/ghost.rb', line 18
def self.process(options)
posts = fetch_posts(options.fetch("dbfile", "ghost.db"))
unless posts.empty?
FileUtils.mkdir_p("_posts")
FileUtils.mkdir_p("_drafts")
posts.each do |post|
write_post_to_file(post)
end
end
end
|
.require_deps ⇒ Object
8
9
10
11
12
13
14
15
16
|
# File 'lib/jekyll-import/importers/ghost.rb', line 8
def self.require_deps
JekyllImport.require_with_fallback(%w(
rubygems
sequel
sqlite3
fileutils
safe_yaml
))
end
|
.specify_options(c) ⇒ Object
4
5
6
|
# File 'lib/jekyll-import/importers/ghost.rb', line 4
def self.specify_options(c)
c.option "dbfile", "--dbfile", "Database file (default: ghost.db)"
end
|
.write_file(filename, frontmatter, content) ⇒ Object
71
72
73
74
75
76
77
|
# File 'lib/jekyll-import/importers/ghost.rb', line 71
def write_file(filename, frontmatter, content)
File.open(filename, "w") do |f|
f.puts frontmatter
f.puts "---"
f.puts content
end
end
|
.write_post_to_file(post) ⇒ Object
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
|
# File 'lib/jekyll-import/importers/ghost.rb', line 37
def write_post_to_file(post)
draft = post[:status].eql?("draft")
page = post[:page]
date = Time.at(post[draft ? :created_at : :published_at].to_i)
if page
filename = "#{post[:slug]}.markdown"
else
directory = draft ? "_drafts" : "_posts"
filename = File.join(directory, "#{date.strftime("%Y-%m-%d")}-#{post[:slug]}.markdown")
end
frontmatter = {
"layout" => page ? "page" : "post",
"title" => post[:title],
}
frontmatter["date"] = date if !page && !draft frontmatter["published"] = false if page && draft frontmatter.delete_if { |_k, v| v.nil? || v == "" }
write_file(filename, frontmatter.to_yaml, post[:markdown])
end
|