Class: Abqari::Importers::Ghost
- Defined in:
- lib/abqari/importers/ghost.rb
Overview
Ghost JSON-export importer.
Ghost's export shape (5.x / 6.x):
{
"db": [{
"data": {
"posts": [ { id, slug, title, html, mobiledoc,
published_at, status, visibility,
feature_image, custom_excerpt, ... } ],
"tags": [ { id, name, slug, ... } ],
"posts_tags": [ { post_id, tag_id, ... } ],
"users": [ { id, name, ... } ]
}
}]
}
We resolve tags via the join table. mobiledoc is a richer
source representation than html but Ghost's renderer
already produces the HTML field for us — using html keeps
the importer simple. Sites that need fancier conversion (e.g.
preserving Ghost bookmark cards as native blocks) can add
mobiledoc parsing in a later pass.
Instance Attribute Summary
Attributes inherited from Base
Class Method Summary collapse
Instance Method Summary collapse
Methods inherited from Base
#initialize, #run!, short_name
Constructor Details
This class inherits a constructor from Abqari::Importers::Base
Class Method Details
.strip_selectors ⇒ Object
31 32 33 34 35 36 37 38 39 |
# File 'lib/abqari/importers/ghost.rb', line 31 def self.strip_selectors %w[ figure.kg-bookmark-card div.kg-callout-card figure.kg-product-card figure.kg-signup-card figure.kg-button-card ] end |
Instance Method Details
#each_post ⇒ Object
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 |
# File 'lib/abqari/importers/ghost.rb', line 41 def each_post data = load_data tag_lookup = index_by(data['tags'] || [], 'id') { |t| t['name'] } post_tag_join = (data['posts_tags'] || []).group_by { |j| j['post_id'] } (data['posts'] || []).each do |post| next unless publishable?(post) tag_ids = (post_tag_join[post['id']] || []).map { |j| j['tag_id'] } = tag_ids.map { |id| tag_lookup[id] }.compact yield Base::ImportedPost.new( title: post['title'], slug: post['slug'], date: parse_date(post['published_at']), body_html: post['html'].to_s, tags: , description: post['custom_excerpt'] || post['meta_description'], feature_image_url: post['feature_image'], source_url: nil, # Ghost export omits the canonical site URL source_slug: post['slug'], extra_frontmatter: ghost_extras(post) ) end end |