hikkoshi-ghost 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +14 -0
- data/Gemfile +7 -0
- data/LICENSE.txt +22 -0
- data/README.md +26 -0
- data/Rakefile +2 -0
- data/hikkoshi-ghost.gemspec +26 -0
- data/lib/hikkoshi/ghost.rb +12 -0
- data/lib/hikkoshi/ghost/exporter.rb +114 -0
- data/lib/hikkoshi/ghost/post_processor/table_downgrader.rb +65 -0
- data/lib/hikkoshi/ghost/tag.rb +29 -0
- data/lib/hikkoshi/ghost/version.rb +5 -0
- metadata +111 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 7afa9331bd1948490bab6e8597ada9c1d6d987be
|
4
|
+
data.tar.gz: 960c0d2865faa81821efdacb1f8a42252c7c7f18
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: c5e475355a779bc9390db4a75783155b739deca209b0e5c4dd3ff5eeed7186405a5b27e4bb1e06a1f168e571858a65b44865b3bc0be134d72a6d81e3cdac2353
|
7
|
+
data.tar.gz: 6e16f69e18ee22aec2baac073598a2a5f722ac5d0649246f967f9b0685bce79b05e376ebd92ec512343edfbd026a420f6d5018f13044fe87d9ff84cd677975e3
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Yu-Cheng Chuang
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# Hikkoshi::Ghost
|
2
|
+
|
3
|
+
Hikkoshi support for Ghost.
|
4
|
+
|
5
|
+
$ gem install hikkoshi-ghost
|
6
|
+
|
7
|
+
## Usage
|
8
|
+
|
9
|
+
TODO: Write usage instructions here
|
10
|
+
|
11
|
+
## Known Issues
|
12
|
+
|
13
|
+
* Ghost does not currently support Table syntax in Markdown. These tables will be downgraded to HTML and the original Markdown source will be embedded below the HTML within HTML comments.
|
14
|
+
* Although Ghost support multiple-users, only single-user is supported.
|
15
|
+
|
16
|
+
## Contributing
|
17
|
+
|
18
|
+
1. Fork it ( https://github.com/[my-github-username]/hikkoshi-ghost/fork )
|
19
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
20
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
21
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
22
|
+
5. Create a new Pull Request
|
23
|
+
|
24
|
+
## Credits
|
25
|
+
|
26
|
+
The concept of this tool was from [evilsocket/octoghost](https://github.com/evilsocket/octoghost). I re-built it in Ruby and added some features for me. Thank you, [Simone Margaritelli](https://github.com/evilsocket)!
|
data/Rakefile
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'hikkoshi/ghost/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "hikkoshi-ghost"
|
8
|
+
spec.version = Hikkoshi::Ghost::VERSION
|
9
|
+
spec.authors = ["Yu-Cheng Chuang"]
|
10
|
+
spec.email = ["ducksteven@gmail.com"]
|
11
|
+
spec.summary = %q{Hikkoshi for Ghost}
|
12
|
+
spec.description = %q{Ghost processor for Hikkoshi the Blog Moving Tool}
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_dependency "hikkoshi", "~> 0.0.1"
|
22
|
+
spec.add_dependency "redcarpet", "~> 3.2.0"
|
23
|
+
|
24
|
+
spec.add_development_dependency "bundler", "~> 1.7"
|
25
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
26
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
require "hikkoshi/ghost/version"
|
2
|
+
|
3
|
+
module Hikkoshi
|
4
|
+
module Ghost
|
5
|
+
autoload :Tag, "hikkoshi/ghost/tag"
|
6
|
+
autoload :Exporter, "hikkoshi/ghost/exporter"
|
7
|
+
|
8
|
+
module PostProcessor
|
9
|
+
autoload :TableDowngrader, "hikkoshi/ghost/post_processor/table_downgrader"
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,114 @@
|
|
1
|
+
require 'json'
|
2
|
+
require 'hikkoshi/ghost/post_processor/table_downgrader'
|
3
|
+
|
4
|
+
module Hikkoshi::Ghost
|
5
|
+
class Exporter < Hikkoshi::Exporter
|
6
|
+
extend Hikkoshi::Support::Slugify
|
7
|
+
|
8
|
+
GHOST_DB_VERSION = "003"
|
9
|
+
|
10
|
+
def initialize(posts)
|
11
|
+
@posts = posts
|
12
|
+
|
13
|
+
number_posts(@posts)
|
14
|
+
|
15
|
+
@posts.each do |post|
|
16
|
+
post.content = Hikkoshi::Ghost::PostProcessor::TableDowngrader.new(post.content).downgrade
|
17
|
+
end
|
18
|
+
|
19
|
+
@registered_tags = {} # name => Tag instance
|
20
|
+
|
21
|
+
@posts_tags = register_posts_tags(@posts)
|
22
|
+
end
|
23
|
+
|
24
|
+
def export(path)
|
25
|
+
File.open(path, "w") do |fout|
|
26
|
+
fout.write JSON.pretty_generate({
|
27
|
+
meta: {
|
28
|
+
exported_on: Time.now.to_i * 1_000, # in milliseconds
|
29
|
+
version: GHOST_DB_VERSION
|
30
|
+
},
|
31
|
+
data: {
|
32
|
+
posts: @posts.map {|post| post_as_json(post) },
|
33
|
+
tags: @registered_tags.values.map(&:as_json),
|
34
|
+
posts_tags: @posts_tags
|
35
|
+
}
|
36
|
+
})
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
private
|
41
|
+
def number_posts(posts)
|
42
|
+
posts.each_with_index do |post, i|
|
43
|
+
post.extra_metadata.id = i + 1
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def register_posts_tags(posts)
|
48
|
+
posts_tags = []
|
49
|
+
|
50
|
+
posts.each do |post|
|
51
|
+
[post.tags, post.categories].flatten.compact.each do |tag_name|
|
52
|
+
tag = find_or_create_tag(tag_name)
|
53
|
+
|
54
|
+
posts_tags << new_post_tag(post.extra_metadata.id, tag.id)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
posts_tags
|
59
|
+
end
|
60
|
+
|
61
|
+
def find_or_create_tag(name)
|
62
|
+
slug = self.class.slugify(name)
|
63
|
+
|
64
|
+
if tag = @registered_tags[slug]
|
65
|
+
return tag
|
66
|
+
else
|
67
|
+
tag = new_tag(name, slug)
|
68
|
+
|
69
|
+
@registered_tags[slug] = tag
|
70
|
+
|
71
|
+
return tag
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
def new_tag(name, slug)
|
76
|
+
Hikkoshi::Ghost::Tag.new({
|
77
|
+
slug: slug,
|
78
|
+
name: name
|
79
|
+
})
|
80
|
+
end
|
81
|
+
|
82
|
+
def new_post_tag(post_id, tag_id)
|
83
|
+
{
|
84
|
+
post_id: post_id,
|
85
|
+
tag_id: tag_id
|
86
|
+
}
|
87
|
+
end
|
88
|
+
|
89
|
+
def post_as_json(post)
|
90
|
+
{
|
91
|
+
id: post.extra_metadata.id,
|
92
|
+
title: post.title,
|
93
|
+
slug: post.slug,
|
94
|
+
markdown: post.content,
|
95
|
+
# html: "the <i>html</i> formatted post body",
|
96
|
+
# image: null,
|
97
|
+
# featured: 0, // boolean indicating featured status
|
98
|
+
page: (post.layout == 'page' ? 1 : 0), # boolean indicating if this is a page or post
|
99
|
+
status: post.status,
|
100
|
+
language: "en_US",
|
101
|
+
# meta_title: null,
|
102
|
+
# meta_description:null,
|
103
|
+
# author_id: 1, // the first user created has an id of 1
|
104
|
+
created_at: post.published_at.to_i * 1_000, # in milliseconds
|
105
|
+
# created_by: 1, // the first user created has an id of 1
|
106
|
+
updated_at: post.updated_at.to_i * 1_000, # in milliseconds
|
107
|
+
# updated_by: 1, // the first user created has an id of 1
|
108
|
+
published_at: post.published_at.to_i * 1_000, # in milliseconds
|
109
|
+
# published_by: 1 // the first user created has an id of 1
|
110
|
+
}
|
111
|
+
end
|
112
|
+
|
113
|
+
end
|
114
|
+
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
require 'redcarpet'
|
2
|
+
|
3
|
+
module Hikkoshi::Ghost::PostProcessor
|
4
|
+
class TableDowngrader
|
5
|
+
CONVERTER = Redcarpet::Markdown.new(Redcarpet::Render::HTML, tables: true)
|
6
|
+
|
7
|
+
def initialize(content)
|
8
|
+
@lines = content.lines
|
9
|
+
end
|
10
|
+
|
11
|
+
def downgrade
|
12
|
+
flag_of_table = Array.new(@lines.size)
|
13
|
+
|
14
|
+
parts = []
|
15
|
+
current_part = Part.new(is_table: false)
|
16
|
+
|
17
|
+
@lines.each_with_index do |line, i|
|
18
|
+
current_line_is_table = line.start_with? "|"
|
19
|
+
|
20
|
+
if current_line_is_table != current_part.table?
|
21
|
+
# change to new part
|
22
|
+
parts << current_part
|
23
|
+
current_part = Part.new(is_table: current_line_is_table)
|
24
|
+
end
|
25
|
+
|
26
|
+
current_part << line
|
27
|
+
end
|
28
|
+
|
29
|
+
# last part
|
30
|
+
parts << current_part
|
31
|
+
|
32
|
+
parts.map(&:converted_text).join
|
33
|
+
end
|
34
|
+
|
35
|
+
class Part
|
36
|
+
attr_reader :text
|
37
|
+
|
38
|
+
def initialize(is_table:)
|
39
|
+
@text = ""
|
40
|
+
@is_table = is_table
|
41
|
+
end
|
42
|
+
|
43
|
+
def table?
|
44
|
+
@is_table
|
45
|
+
end
|
46
|
+
|
47
|
+
def <<(text)
|
48
|
+
@text << text
|
49
|
+
end
|
50
|
+
|
51
|
+
def converted_text
|
52
|
+
if self.table?
|
53
|
+
# TODO: make this optional
|
54
|
+
convert_table(@text) + "\n<!--\n#{@text}\n-->\n"
|
55
|
+
else
|
56
|
+
@text
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
def convert_table(text)
|
61
|
+
CONVERTER.render(text)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'securerandom'
|
2
|
+
|
3
|
+
module Hikkoshi::Ghost
|
4
|
+
class Tag
|
5
|
+
extend Hikkoshi::Support::Slugify
|
6
|
+
|
7
|
+
@@current_id = 1
|
8
|
+
|
9
|
+
attr_reader :id, :name, :slug
|
10
|
+
|
11
|
+
def initialize(name:, slug: self.class.slugify(name))
|
12
|
+
@id = @@current_id
|
13
|
+
|
14
|
+
@name = name
|
15
|
+
@slug = slug
|
16
|
+
|
17
|
+
@@current_id += 1
|
18
|
+
end
|
19
|
+
|
20
|
+
def as_json
|
21
|
+
{
|
22
|
+
id: @id,
|
23
|
+
name: @name,
|
24
|
+
slug: @slug,
|
25
|
+
description: @description
|
26
|
+
}
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
metadata
ADDED
@@ -0,0 +1,111 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: hikkoshi-ghost
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Yu-Cheng Chuang
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-12-28 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: hikkoshi
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.0.1
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.0.1
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: redcarpet
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 3.2.0
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 3.2.0
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.7'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.7'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '10.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '10.0'
|
69
|
+
description: Ghost processor for Hikkoshi the Blog Moving Tool
|
70
|
+
email:
|
71
|
+
- ducksteven@gmail.com
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- ".gitignore"
|
77
|
+
- Gemfile
|
78
|
+
- LICENSE.txt
|
79
|
+
- README.md
|
80
|
+
- Rakefile
|
81
|
+
- hikkoshi-ghost.gemspec
|
82
|
+
- lib/hikkoshi/ghost.rb
|
83
|
+
- lib/hikkoshi/ghost/exporter.rb
|
84
|
+
- lib/hikkoshi/ghost/post_processor/table_downgrader.rb
|
85
|
+
- lib/hikkoshi/ghost/tag.rb
|
86
|
+
- lib/hikkoshi/ghost/version.rb
|
87
|
+
homepage: ''
|
88
|
+
licenses:
|
89
|
+
- MIT
|
90
|
+
metadata: {}
|
91
|
+
post_install_message:
|
92
|
+
rdoc_options: []
|
93
|
+
require_paths:
|
94
|
+
- lib
|
95
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
96
|
+
requirements:
|
97
|
+
- - ">="
|
98
|
+
- !ruby/object:Gem::Version
|
99
|
+
version: '0'
|
100
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
101
|
+
requirements:
|
102
|
+
- - ">="
|
103
|
+
- !ruby/object:Gem::Version
|
104
|
+
version: '0'
|
105
|
+
requirements: []
|
106
|
+
rubyforge_project:
|
107
|
+
rubygems_version: 2.2.2
|
108
|
+
signing_key:
|
109
|
+
specification_version: 4
|
110
|
+
summary: Hikkoshi for Ghost
|
111
|
+
test_files: []
|