jekyll_ghost_importer 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2deb5326c0dbc5b5cf946af8ae188c1690c965f2
4
- data.tar.gz: 6c641eb72b436c202a5ac7ab85c9fb3ccf9d4adb
3
+ metadata.gz: c1482339e32652c4e370beafe41755bc0f4f03da
4
+ data.tar.gz: 91bdfad5e617caaebd3873f283dce011e6d05620
5
5
  SHA512:
6
- metadata.gz: 66a0aa71037c0720e8cd25f04dd928fd6b1a5d42f6797c03243fc139ada08bfb0817fe1b22de48cb34c938d689232c1b2f7a10eca85369f39a72e9ad88db5c1c
7
- data.tar.gz: d440bcd60c1237a08848236d41c17d82674a2eb84c21fa680362e3855d2be267c76db3e14d4d532f06544489e3fd891fd747295de45163521debf602358e01ac
6
+ metadata.gz: bf1a62a1172c46ee499571652c7355f659d3feae45116d0d6e47f10c2356f64baba5d43b43e856f7df78e438b29b33c96798a0342d309fe0af5c535b8db32e58
7
+ data.tar.gz: 026f9c9da18f84e2ef63e48fd422d054000896f99078bf0ff8eec74484d8d59ca79e7b8d8b719737a673c57bd60f70bc10f8dcc27fa5ecb301d36d61f9fccd72
@@ -16,8 +16,15 @@ else
16
16
  posts = json[:db].first[:data][:posts]
17
17
  end
18
18
 
19
+ @imported = Hash.new(0)
20
+
19
21
  posts.each do |post|
20
- date = DateTime.parse(post[:published_at]) if post[:published_at]
22
+ date = case post[:published_at]
23
+ when String
24
+ DateTime.parse(post[:published_at])
25
+ when Integer
26
+ Time.at(post[:published_at] / 1000).utc.to_datetime
27
+ end
21
28
  slug = post[:slug]
22
29
  front_matter_hash = {
23
30
  'layout' => "post",
@@ -34,6 +41,10 @@ posts.each do |post|
34
41
  end
35
42
  folder = draft ? '_drafts' : '_posts'
36
43
  filename = File.join folder, basename
37
- puts "Importing filename..."
44
+ puts "Importing #{ filename }"
38
45
  File.write filename, body
46
+ @imported[:posts] += 1
47
+ @imported[:drafts] += 1 if draft
39
48
  end
49
+
50
+ puts "#{ @imported[:posts] } posts imported ( #{ @imported[:drafts] } draft )"
@@ -0,0 +1,130 @@
1
+ {
2
+ "db": [
3
+ {
4
+ "meta": {
5
+ "exported_on": 1424346829618,
6
+ "version": "003"
7
+ },
8
+ "data": {
9
+ "posts": [
10
+ {
11
+ "id": 1,
12
+ "uuid": "ccb64228-dfbd-49e6-a02f-f4cf4651c4fd",
13
+ "title": "Welcome to Ghost",
14
+ "slug": "welcome-to-ghost",
15
+ "markdown": "You're live!",
16
+ "html": "<p>You're live!</p>",
17
+ "image": null,
18
+ "featured": 0,
19
+ "page": 0,
20
+ "status": "published",
21
+ "language": "en_US",
22
+ "meta_title": null,
23
+ "meta_description": null,
24
+ "author_id": 1,
25
+ "created_at": 1424346554951,
26
+ "created_by": 1,
27
+ "updated_at": 1424346554951,
28
+ "updated_by": 1,
29
+ "published_at": 1424346554966,
30
+ "published_by": 1
31
+ },
32
+ {
33
+ "id": 2,
34
+ "uuid": "287617c1-572e-43e1-8a3c-f7ad0d7bb71e",
35
+ "title": "new_post",
36
+ "slug": "new_post",
37
+ "markdown": "some test text\n\n some code\n \nfarewell",
38
+ "html": "<p>some test text</p>\n\n<pre><code>some code\n</code></pre>\n\n<p>farewell</p>",
39
+ "image": null,
40
+ "featured": 0,
41
+ "page": 0,
42
+ "status": "published",
43
+ "language": "en_US",
44
+ "meta_title": null,
45
+ "meta_description": null,
46
+ "author_id": 1,
47
+ "created_at": 1424346744945,
48
+ "created_by": 1,
49
+ "updated_at": 1424346784919,
50
+ "updated_by": 1,
51
+ "published_at": 1424346784919,
52
+ "published_by": 1
53
+ },
54
+ {
55
+ "id": 3,
56
+ "uuid": "7beab6be-116a-45da-8a0d-7143ef74f952",
57
+ "title": "test draft",
58
+ "slug": "test-draft",
59
+ "markdown": "Something here",
60
+ "html": "<p>Something here</p>",
61
+ "image": null,
62
+ "featured": 0,
63
+ "page": 0,
64
+ "status": "draft",
65
+ "language": "en_US",
66
+ "meta_title": null,
67
+ "meta_description": null,
68
+ "author_id": 1,
69
+ "created_at": 1424346793572,
70
+ "created_by": 1,
71
+ "updated_at": 1424346812457,
72
+ "updated_by": 1,
73
+ "published_at": null,
74
+ "published_by": null
75
+ }
76
+ ],
77
+ "users": [
78
+ {
79
+ "id": 1,
80
+ "uuid": "6a013e8f-24d3-4c77-901a-7e57f6537f47",
81
+ "name": "test test2",
82
+ "slug": "test",
83
+ "password": "some_password",
84
+ "email": "my_email",
85
+ "image": null,
86
+ "cover": null,
87
+ "bio": null,
88
+ "website": null,
89
+ "location": null,
90
+ "accessibility": null,
91
+ "status": "active",
92
+ "language": "en_US",
93
+ "meta_title": null,
94
+ "meta_description": null,
95
+ "last_login": 1424346712870,
96
+ "created_at": 1424346562473,
97
+ "created_by": 1,
98
+ "updated_at": 1424346712870,
99
+ "updated_by": 1
100
+ }
101
+ ],
102
+ "tags": [
103
+ {
104
+ "id": 1,
105
+ "uuid": "befcb6c7-c777-4a65-a272-6e2577cade61",
106
+ "name": "Getting Started",
107
+ "slug": "getting-started",
108
+ "description": null,
109
+ "image": null,
110
+ "hidden": 0,
111
+ "parent_id": null,
112
+ "meta_title": null,
113
+ "meta_description": null,
114
+ "created_at": 1424346554967,
115
+ "created_by": 1,
116
+ "updated_at": 1424346554967,
117
+ "updated_by": 1
118
+ }
119
+ ],
120
+ "posts_tags": [
121
+ {
122
+ "id": 1,
123
+ "post_id": 1,
124
+ "tag_id": 1
125
+ }
126
+ ]
127
+ }
128
+ }
129
+ ]
130
+ }
@@ -234,3 +234,30 @@ Feature: Import posts
234
234
  """
235
235
  Something here
236
236
  """
237
+
238
+ Scenario: Import a backup file with a new format
239
+ Given a ghost backup file version 003 with some sample posts
240
+ When I run `jekyll_ghost_importer GhostBackup.json`
241
+ Then it should pass with:
242
+ """
243
+ 3 posts imported ( 1 draft )
244
+ """
245
+ And a directory named "_posts" should exist
246
+ And the following files should exist:
247
+ | _posts/2015-02-19-welcome-to-ghost.markdown |
248
+ | _posts/2015-02-19-new_post.markdown |
249
+ And the file "_posts/2015-02-19-welcome-to-ghost.markdown" should contain:
250
+ """
251
+ ---
252
+ layout: post
253
+ title: Welcome to Ghost
254
+ date: '2015-02-19 11:49:14'
255
+ ---
256
+
257
+ You're live!
258
+ """
259
+ And a directory named "_drafts" should exist
260
+ And the file "_drafts/test-draft.markdown" should contain:
261
+ """
262
+ Something here
263
+ """
@@ -0,0 +1,4 @@
1
+ Given(/^a ghost backup file version (\d+) with some sample posts$/) do |version|
2
+ fixture = File.join __dir__, '..', 'fixtures', "version-#{ version }.json"
3
+ write_file 'GhostBackup.json', File.read(fixture)
4
+ end
@@ -1,3 +1,3 @@
1
1
  module JekyllGhostImporter
2
- VERSION = "0.2.0"
2
+ VERSION = "0.3.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jekyll_ghost_importer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eloy Espinaco
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-09-15 00:00:00.000000000 Z
11
+ date: 2015-02-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -110,7 +110,9 @@ files:
110
110
  - README.md
111
111
  - Rakefile
112
112
  - bin/jekyll_ghost_importer
113
+ - features/fixtures/version-003.json
113
114
  - features/import_posts.feature
115
+ - features/step_definitions/backup_files.rb
114
116
  - features/support/requires.rb
115
117
  - jekyll_ghost_importer.gemspec
116
118
  - lib/jekyll_ghost_importer.rb
@@ -134,11 +136,13 @@ required_rubygems_version: !ruby/object:Gem::Requirement
134
136
  version: '0'
135
137
  requirements: []
136
138
  rubyforge_project:
137
- rubygems_version: 2.2.2
139
+ rubygems_version: 2.4.5
138
140
  signing_key:
139
141
  specification_version: 4
140
142
  summary: Import your posts from a ghost backup file.
141
143
  test_files:
144
+ - features/fixtures/version-003.json
142
145
  - features/import_posts.feature
146
+ - features/step_definitions/backup_files.rb
143
147
  - features/support/requires.rb
144
148
  has_rdoc: