hikkoshi-jekyll 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 2e7fe08a3e8d6b6d33799bcc9caa0c6e33353d2a
4
+ data.tar.gz: 3c447df56afd586946349f991166bc13b12fabe7
5
+ SHA512:
6
+ metadata.gz: c1c07a8bef31b91592403ab9b4d8a202c10683ba3e251fdb7d1766f80764b372f5b46f05a67f2197b54ca74acbf5be04ac3cad076dceeccf57bafedfd19d10a3
7
+ data.tar.gz: 9df3044886bc93e0cfdc9320997ab73c58066d480209bf8409550ec529bf32caeeb533249e337577935f9f5dc3996087685c671972fd1f9133877538e2846aa4
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in hikkoshi-jekyll.gemspec
4
+ gemspec
5
+
6
+ gem "hikkoshi", :path => '../hikkoshi', :group => :development
@@ -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.
@@ -0,0 +1,19 @@
1
+ # Hikkoshi::Jekyll
2
+
3
+ Hikkoshi support for Jekyll.
4
+
5
+ ## Installation
6
+
7
+ $ gem install hikkoshi-jekyll
8
+
9
+ ## Usage
10
+
11
+ TODO: Write usage instructions here
12
+
13
+ ## Contributing
14
+
15
+ 1. Fork it ( https://github.com/[my-github-username]/hikkoshi-jekyll/fork )
16
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
17
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
18
+ 4. Push to the branch (`git push origin my-new-feature`)
19
+ 5. Create a new Pull Request
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'hikkoshi/jekyll/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "hikkoshi-jekyll"
8
+ spec.version = Hikkoshi::Jekyll::VERSION
9
+ spec.authors = ["Yu-Cheng Chuang"]
10
+ spec.email = ["ducksteven@gmail.com"]
11
+ spec.summary = %q{Hikkoshi for Jekyll}
12
+ spec.description = %q{Jekyll 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
+
23
+ spec.add_development_dependency "bundler", "~> 1.7"
24
+ spec.add_development_dependency "rake", "~> 10.0"
25
+ end
@@ -0,0 +1,19 @@
1
+ require "hikkoshi/jekyll/version"
2
+
3
+ require "yaml"
4
+
5
+ require "hikkoshi"
6
+
7
+ module Hikkoshi
8
+ module Jekyll
9
+ autoload :Post, "hikkoshi/jekyll/post"
10
+ autoload :Tag, "hikkoshi/jekyll/tag"
11
+ autoload :Exporter, "hikkoshi/jekyll/exporter"
12
+ autoload :Importer, "hikkoshi/jekyll/importer"
13
+
14
+ module PostProcessor
15
+ autoload :Date, "hikkoshi/jekyll/post_processor/date"
16
+ autoload :Slug, "hikkoshi/jekyll/post_processor/slug"
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,56 @@
1
+ module Hikkoshi::Jekyll
2
+ # @example Basic Usage
3
+ # posts = Hikkoshi::Logdown::Importer.new("~/blog-backup/")
4
+ # exporter = Hikkoshi::Jekyll::Exporter.new(posts)
5
+ # exporter.export("~/new-blog/_posts")
6
+ #
7
+ # @example Customize file name
8
+ # posts = Hikkoshi::Logdown::Importer.new("~/blog-backup/")
9
+ # exporter = Hikkoshi::Jekyll::Exporter.new(posts)
10
+ # exporter.filename_formatter = -> (post) {
11
+ # "#{post.date.strftime('%F')}-#{post.slug}.md"
12
+ # }
13
+ # exporter.export("~/new-blog/_posts")
14
+ #
15
+ class Exporter < Hikkoshi::Exporter
16
+ attr_accessor :filename_formatter
17
+
18
+ def export(path)
19
+ path = File.expand_path(path)
20
+
21
+ @posts.each do |post|
22
+ generate_post(post, path)
23
+ end
24
+ end
25
+
26
+ # Override this method to customize file name format
27
+ def filename_formatter(post)
28
+ "#{post.published_at.strftime('%F')}-#{post.slug}.md"
29
+ end
30
+
31
+ private
32
+ def generate_post(post, into_path)
33
+ path = File.join(into_path, filename_formatter(post))
34
+
35
+ File.open(path, "w") do |fout|
36
+ fout.write format_post(post)
37
+ end
38
+ end
39
+
40
+ def format_post(post)
41
+ "#{YAML.dump(metadata(post))}\n---\n#{post.content}"
42
+ end
43
+
44
+ def metadata(post)
45
+ {
46
+ "layout" => post.layout,
47
+ "title" => post.title,
48
+ "published" => post.status == "published",
49
+ "date" => post.published_at.strftime("%F %R"),
50
+ "tags" => post.tags,
51
+ "categories" => post.categories,
52
+ "comments" => post.comments
53
+ }
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,18 @@
1
+ module Hikkoshi::Jekyll
2
+ class Importer < Hikkoshi::Importer
3
+ EXTENSIONS = "*.{md,markdown,mkdn}"
4
+
5
+ def initialize(path)
6
+ @path = File.expand_path(path)
7
+
8
+ @posts = read_posts
9
+ end
10
+
11
+ private
12
+ def read_posts
13
+ Dir.glob(File.join(@path, EXTENSIONS)).map {|filename|
14
+ Hikkoshi::Jekyll::Post.new(filename)
15
+ }
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,95 @@
1
+ require 'yaml'
2
+ require 'ostruct'
3
+ require 'time'
4
+
5
+ module Hikkoshi::Jekyll
6
+ class Post < Hikkoshi::Post
7
+ include Hikkoshi::Support::TimeParser
8
+ include PostProcessor::Slug
9
+
10
+ SEPARATOR = /---\r?\n/
11
+
12
+ def initialize(filename)
13
+ super()
14
+
15
+ @filename = filename
16
+ @original_metadata, @content = load_file(@filename)
17
+
18
+ cast_metadata
19
+ post_process
20
+ end
21
+
22
+ def slug=(slug)
23
+ @slug = slug
24
+ end
25
+
26
+ def published=(published)
27
+ if published == false
28
+ @status = "draft"
29
+ else
30
+ # by default it is published
31
+ @status = "published"
32
+ end
33
+ end
34
+
35
+ def date=(date)
36
+ @published_at = parse_time(date)
37
+ end
38
+
39
+ def categories=(categories)
40
+ @categories += categories if categories.is_a? Array
41
+ end
42
+
43
+ def category=(category)
44
+ @categories << category
45
+ end
46
+
47
+ def tags=(tags)
48
+ @tags += tags if tags.is_a? Array
49
+ end
50
+
51
+ private
52
+ def load_file(filename)
53
+ fulltext = File.read(filename)
54
+
55
+ # Hexo does not insert "---" at the first line.
56
+ # This hack is to unify the formats of all the files
57
+ fulltext.sub!(/^#{SEPARATOR}/, '')
58
+
59
+ raw_metadata, content = fulltext.split(SEPARATOR, 2)
60
+
61
+ metadata = OpenStruct.new(YAML.load(raw_metadata))
62
+
63
+ return [metadata, content]
64
+ end
65
+
66
+ def cast_metadata
67
+ @original_metadata.each_pair do |name, value|
68
+ if self.respond_to?(:"#{name}=")
69
+ self.send(:"#{name}=", value)
70
+ else
71
+ STDERR.puts "Unknown property: #{name}"
72
+ end
73
+ end
74
+ end
75
+
76
+ def post_process
77
+ post_process_slug
78
+ post_process_time
79
+ end
80
+
81
+ def post_process_slug
82
+ if @slug.nil? || @slug.blank?
83
+ @slug = slug_from_filename(@filename) or slug_from_title(@title)
84
+ end
85
+ end
86
+
87
+ def post_process_time
88
+ @published_at ||= date_from_filename(@filename)
89
+
90
+ # default values for created / updated
91
+ @created_at ||= @published_at
92
+ @updated_at ||= @published_at
93
+ end
94
+ end
95
+ end
@@ -0,0 +1,17 @@
1
+ module Hikkoshi::Jekyll
2
+ module PostProcessor
3
+ module Date
4
+ private
5
+ def date_from_filename(filename)
6
+ basename = File.basename(filename, ".*")
7
+ extracted = basename.match(/^(\d\d\d\d-\d\d-\d\d)/)[1]
8
+
9
+ if extracted.empty?
10
+ return nil
11
+ else
12
+ return parse_time(extracted)
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,28 @@
1
+ module Hikkoshi::Jekyll
2
+ module PostProcessor
3
+ module Slug
4
+ extend Hikkoshi::Support::Slugify
5
+
6
+ private
7
+ def slug_from_filename(filename, strip_date: true)
8
+ basename = File.basename(filename, ".*")
9
+
10
+ if strip_date
11
+ extracted = basename.sub(/^\d\d\d\d-\d\d-\d\d-/, "").strip
12
+ else
13
+ extracted = basename
14
+ end
15
+
16
+ if extracted.empty?
17
+ return nil
18
+ else
19
+ return extracted
20
+ end
21
+ end
22
+
23
+ def slug_from_title(title)
24
+ slugify(title)
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,5 @@
1
+ module Hikkoshi
2
+ module Jekyll
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
metadata ADDED
@@ -0,0 +1,99 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: hikkoshi-jekyll
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: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.7'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.7'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ description: Jekyll processor for Hikkoshi the Blog Moving Tool
56
+ email:
57
+ - ducksteven@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - Gemfile
64
+ - LICENSE.txt
65
+ - README.md
66
+ - Rakefile
67
+ - hikkoshi-jekyll.gemspec
68
+ - lib/hikkoshi/jekyll.rb
69
+ - lib/hikkoshi/jekyll/exporter.rb
70
+ - lib/hikkoshi/jekyll/importer.rb
71
+ - lib/hikkoshi/jekyll/post.rb
72
+ - lib/hikkoshi/jekyll/post_processor/date.rb
73
+ - lib/hikkoshi/jekyll/post_processor/slug.rb
74
+ - lib/hikkoshi/jekyll/version.rb
75
+ homepage: ''
76
+ licenses:
77
+ - MIT
78
+ metadata: {}
79
+ post_install_message:
80
+ rdoc_options: []
81
+ require_paths:
82
+ - lib
83
+ required_ruby_version: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - ">="
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ required_rubygems_version: !ruby/object:Gem::Requirement
89
+ requirements:
90
+ - - ">="
91
+ - !ruby/object:Gem::Version
92
+ version: '0'
93
+ requirements: []
94
+ rubyforge_project:
95
+ rubygems_version: 2.2.2
96
+ signing_key:
97
+ specification_version: 4
98
+ summary: Hikkoshi for Jekyll
99
+ test_files: []