hexo_disqus_migrator 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +55 -0
- data/Rakefile +1 -0
- data/bin/disqus_migrator +64 -0
- data/hexo_disqus_migrator.gemspec +26 -0
- data/lib/hexo_disqus_migrator.rb +10 -0
- data/lib/migrator/mapping.rb +57 -0
- data/lib/migrator/migrator/class_methods.rb +65 -0
- data/lib/migrator/migrator/outputs.rb +59 -0
- data/lib/migrator/migrator/reports.rb +37 -0
- data/lib/migrator/migrator/rules.rb +140 -0
- data/lib/migrator/migrator.rb +34 -0
- data/lib/migrator/rule.rb +33 -0
- data/lib/migrator/version.rb +3 -0
- metadata +119 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 190cc06190b2b89529f49d72291d72f7da02f96f
|
4
|
+
data.tar.gz: 5f392ca5ab4899290099964df764294af11cb7f0
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: dcd58da42cfa460fd0de234d1189954395495cb22fb91448b698a8d1afd6365ed83f4698960edf89b931ead562a5110b8f59e042c440a278976f982139224714
|
7
|
+
data.tar.gz: 18ee909d29eb20932e62ee39317dbf01ecab7c13e495f8144a9fbdf3d7bae36117cc942d31da9cdd79d17bb49d674f2574929bf0294a4ed0f65b61ab248554a4
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 TimNew
|
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,55 @@
|
|
1
|
+
hexo_disqus_migrator [![Gem version][gem-image]][gem-url] [![Dependency Status][depstat-image]][depstat-url]
|
2
|
+
===============
|
3
|
+
|
4
|
+
> [hexo_disqus_migrator] is a tool that help blogger to generate [Disqus Url Mapper] for your [Hexo] or [Octopress] blog
|
5
|
+
|
6
|
+
## Installation
|
7
|
+
|
8
|
+
Add this line to your application's Gemfile:
|
9
|
+
|
10
|
+
gem 'hexo_disqus_migrator'
|
11
|
+
|
12
|
+
And then execute:
|
13
|
+
|
14
|
+
$ bundle
|
15
|
+
|
16
|
+
Or install it yourself as:
|
17
|
+
|
18
|
+
$ gem install hexo_disqus_migrator
|
19
|
+
|
20
|
+
## Usage
|
21
|
+
|
22
|
+
$ disqus_migrator post_links.csv
|
23
|
+
|
24
|
+
For more detail about Disqus comments migartion, read [Disqus Url Mapper] document.
|
25
|
+
|
26
|
+
For more detail about the tool, check out built-in help
|
27
|
+
|
28
|
+
$ disqus_migrator help
|
29
|
+
|
30
|
+
## Contributing
|
31
|
+
|
32
|
+
1. Fork it
|
33
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
34
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
35
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
36
|
+
5. Create new Pull Request
|
37
|
+
|
38
|
+
## License
|
39
|
+
MIT
|
40
|
+
|
41
|
+
[![Gem downloads][gem-downloads]][gem-url]
|
42
|
+
|
43
|
+
[gem-image]: http://img.shields.io/gem/v/hexo_disqus_migrator.svg?style=flat
|
44
|
+
[gem-url]: http://rubygems.org/gems/hexo_disqus_migrator
|
45
|
+
[gem-downloads]: http://img.shields.io/gem/dtv/hexo_disqus_migrator.svg?style=flat
|
46
|
+
|
47
|
+
[depstat-url]: https://gemnasium.com/timnew/hexo_disqus_migrator
|
48
|
+
[depstat-image]: http://img.shields.io/gemnasium/timnew/hexo_disqus_migrator.svg?style=flat
|
49
|
+
|
50
|
+
[hexo_disqus_migrator]: https://github.com/timnew/hexo_disqus_migrator
|
51
|
+
[Disqus Url Mapper]: https://help.disqus.com/customer/portal/articles/912757-url-mapper
|
52
|
+
[Hexo]: http://hexo.io/
|
53
|
+
[Octopress]: http://octopress.org/
|
54
|
+
|
55
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'bundler/gem_tasks'
|
data/bin/disqus_migrator
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'hexo_disqus_migrator'
|
4
|
+
|
5
|
+
require 'commander/import'
|
6
|
+
|
7
|
+
program :version, '0.0.1'
|
8
|
+
program :description, 'Disqus comments migrator for Hexo'
|
9
|
+
|
10
|
+
command :migrate do |c|
|
11
|
+
c.syntax = 'migrator migrate [options]'
|
12
|
+
c.summary = 'Generate Disqus URL mapping CSV'
|
13
|
+
c.description = ''
|
14
|
+
c.example 'description', 'command example'
|
15
|
+
c.option '-i', '--input FILE', 'The csv generated by Disqus'
|
16
|
+
c.option '-o', '--output FILE', 'Name pattern for generated CSV'
|
17
|
+
c.option '-r', '--reports overview, unconfident, excluded, invalid', Array, 'Reports to be displayed'
|
18
|
+
c.option '-R', '--report FILE', 'Write report to file'
|
19
|
+
c.option '-u', '--[no-]unconfidient', 'Do/Don\' generate unconfident migrations'
|
20
|
+
c.option '-c', '--[no-]confirm', 'Do/Don\'t confirm unconfident link one by one'
|
21
|
+
c.option '-b', '--[no-]invalid', 'Do/Don\' generate invalid migrations'
|
22
|
+
c.action do |args, options|
|
23
|
+
options.default input: 'links.csv',
|
24
|
+
output: 'migration',
|
25
|
+
overview: true,
|
26
|
+
reports: %w(overview unconfident excluded invalid),
|
27
|
+
report: nil,
|
28
|
+
unconfidient: true,
|
29
|
+
verify: true,
|
30
|
+
invalid: false
|
31
|
+
|
32
|
+
migrator = Migrator.new(options.input)
|
33
|
+
|
34
|
+
migrator.migrate
|
35
|
+
|
36
|
+
report = ''
|
37
|
+
options.reports.each do |r|
|
38
|
+
case r.downcase[0].to_sym
|
39
|
+
when :o
|
40
|
+
report += migrator.overview_report.render
|
41
|
+
when :u
|
42
|
+
report += migrator.unconfident_report.render
|
43
|
+
when :e
|
44
|
+
report += migrator.excluded_report.render
|
45
|
+
when :i
|
46
|
+
report += migrator.invalid_report.render
|
47
|
+
else
|
48
|
+
log 'error', "Invalid report #{r}"
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
File.write options.report, report if options.report
|
53
|
+
|
54
|
+
if options.verify
|
55
|
+
migrator.confirm_unconfidents
|
56
|
+
end
|
57
|
+
|
58
|
+
migrator.write_confident options.output + '.csv'
|
59
|
+
migrator.write_unconfident options.output + '.unconfident.csv' if options.unconfidient
|
60
|
+
migrator.write_invalid options.output + '.invalid.csv' if options.invalid
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
default_command :migrate
|
@@ -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 'migrator/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'hexo_disqus_migrator'
|
8
|
+
spec.version = Migrator::VERSION
|
9
|
+
spec.authors = ['TimNew']
|
10
|
+
spec.email = ['timnew.wti@gmail.com']
|
11
|
+
spec.description = %q{hexo_disqus_migrator is a tool that help blogger to generate Disqus Url Mapper for your Hexo or Octopress blog}
|
12
|
+
spec.summary = spec.description
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = 'MIT'
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
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 'commander', '~> 4.2.0'
|
22
|
+
spec.add_dependency 'terminal-table', '~> 1.4.5'
|
23
|
+
|
24
|
+
spec.add_development_dependency 'bundler', '~> 1.3'
|
25
|
+
spec.add_development_dependency 'rake'
|
26
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
class Mapping
|
2
|
+
attr_reader :migrator, :url, :host, :path, :local_path, :basename
|
3
|
+
|
4
|
+
attr_accessor :new_url, :tags
|
5
|
+
|
6
|
+
attr_accessor :output, :confident
|
7
|
+
alias_method :output?, :output
|
8
|
+
alias_method :confident?, :confident
|
9
|
+
|
10
|
+
def new_path
|
11
|
+
new_url.path
|
12
|
+
end
|
13
|
+
|
14
|
+
def new_path=(path)
|
15
|
+
@new_url = URI(url.to_s)
|
16
|
+
@new_url.path = URI.escape(path)
|
17
|
+
@new_url
|
18
|
+
end
|
19
|
+
|
20
|
+
def new_local_path
|
21
|
+
Migrator.local_path new_path
|
22
|
+
end
|
23
|
+
|
24
|
+
def new_basename
|
25
|
+
File.basename new_path
|
26
|
+
end
|
27
|
+
|
28
|
+
def initialize(migrator, url_text)
|
29
|
+
@migrator = migrator
|
30
|
+
|
31
|
+
@url = URI(url_text)
|
32
|
+
@host = url.host
|
33
|
+
@path = url.path
|
34
|
+
@local_path = Migrator.local_path path
|
35
|
+
@basename = File.basename path
|
36
|
+
|
37
|
+
@tags = []
|
38
|
+
@new_url = @url
|
39
|
+
@confident = true
|
40
|
+
@output = false
|
41
|
+
end
|
42
|
+
|
43
|
+
def isnt?(tag)
|
44
|
+
!tags.include?(tag)
|
45
|
+
end
|
46
|
+
alias_method :isnt, :isnt?
|
47
|
+
|
48
|
+
def is?(tag)
|
49
|
+
tags.include?(tag)
|
50
|
+
end
|
51
|
+
alias_method :is, :is?
|
52
|
+
|
53
|
+
def execute
|
54
|
+
migrator.migrate_mapping self
|
55
|
+
self
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
class Migrator
|
2
|
+
module ClassMethods
|
3
|
+
|
4
|
+
ROOT_PATH = File.join(Dir.pwd, 'public')
|
5
|
+
ROOT = Pathname.new ROOT_PATH
|
6
|
+
POSTS_FOLDER = Pathname.new File.join(Dir.pwd, 'source/_posts')
|
7
|
+
|
8
|
+
VERIFIER = Rule.new(:valid_checker, false) do
|
9
|
+
setup_match { |m| m.isnt?(:ignored) }
|
10
|
+
setup_action do |m|
|
11
|
+
local_file = Migrator.local_path m.new_path
|
12
|
+
|
13
|
+
if local_file.exist?
|
14
|
+
m.tags << :valid
|
15
|
+
else
|
16
|
+
m.tags << :invalid
|
17
|
+
m.output = false
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
FIX_CHECKER = Rule.new(:fix_checker, false) do
|
23
|
+
setup_match { |m| m.is?(:broken) }
|
24
|
+
setup_match { |m| m.isnt?(:fixed) }
|
25
|
+
setup_match { |m| Migrator.local_path(m.new_path).exist? }
|
26
|
+
setup_action do |m|
|
27
|
+
m.tags << :fixed
|
28
|
+
true
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def root
|
33
|
+
ROOT
|
34
|
+
end
|
35
|
+
|
36
|
+
def posts
|
37
|
+
POSTS_FOLDER.each_child(false)
|
38
|
+
end
|
39
|
+
|
40
|
+
def local_path(path)
|
41
|
+
Pathname.new File.join(ROOT_PATH, path)
|
42
|
+
end
|
43
|
+
|
44
|
+
def to_url(path)
|
45
|
+
path[ROOT_PATH.length..-1]
|
46
|
+
end
|
47
|
+
|
48
|
+
def name_components(path)
|
49
|
+
base_name = File.basename(path)
|
50
|
+
base_name.split('-')
|
51
|
+
end
|
52
|
+
|
53
|
+
def verifier
|
54
|
+
VERIFIER
|
55
|
+
end
|
56
|
+
|
57
|
+
def delegate_to_class(*names)
|
58
|
+
names.each do |name|
|
59
|
+
define_method name do |*args|
|
60
|
+
self.class.send name, *args
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
class Migrator
|
2
|
+
module Outputs
|
3
|
+
include Commander::Methods
|
4
|
+
|
5
|
+
def write(type, filename, &filter)
|
6
|
+
puts "Write #{type} to file #{filename}"
|
7
|
+
CSV.open(filename, 'wb') do |csv|
|
8
|
+
data = mappings.select(&filter)
|
9
|
+
table_print data, "#{type} Entries", :basename, :tags
|
10
|
+
progress data do |mapping|
|
11
|
+
csv << [mapping.url.to_s, mapping.new_url.to_s]
|
12
|
+
end
|
13
|
+
end
|
14
|
+
puts
|
15
|
+
end
|
16
|
+
|
17
|
+
def write_confident(filename)
|
18
|
+
write('Confident', filename) do |m|
|
19
|
+
m.output? && m.confident?
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def write_unconfident(filename)
|
24
|
+
write('Unconfident', filename) do |m|
|
25
|
+
m.output? && !m.confident?
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def write_invalid(filename)
|
30
|
+
write('Invalid', filename) do |m|
|
31
|
+
m.is(:invalid)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def confirm_unconfidents
|
36
|
+
mappings.select { |m| m.output? and !m.confident? }.each do |m|
|
37
|
+
agreed = false
|
38
|
+
until agreed do
|
39
|
+
puts "Old: #{m.url}"
|
40
|
+
puts "New: #{m.new_url}"
|
41
|
+
agreed = agree('Okay to output?')
|
42
|
+
|
43
|
+
unless agreed
|
44
|
+
case choose("What to do?", :manual, :invalid, :cancel)
|
45
|
+
when :manual
|
46
|
+
m.new_url = ask('New Url:')
|
47
|
+
when :invalid
|
48
|
+
m.tags << :invalid
|
49
|
+
m.output = false
|
50
|
+
agreed = true
|
51
|
+
when :cancel
|
52
|
+
# do nothing
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
class Migrator
|
2
|
+
module Reports
|
3
|
+
def table_print(data, title, *columns)
|
4
|
+
table = Terminal::Table.new do |t|
|
5
|
+
t.headings = columns
|
6
|
+
t.title = title
|
7
|
+
data.each do |mapping|
|
8
|
+
t.add_row columns.map { |c| mapping.send(c) }
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
puts table
|
13
|
+
puts
|
14
|
+
|
15
|
+
table
|
16
|
+
end
|
17
|
+
|
18
|
+
def overview_report
|
19
|
+
table_print mappings, 'Overview', :basename, :host, :tags, :output?, :confident?
|
20
|
+
end
|
21
|
+
|
22
|
+
def unconfident_report
|
23
|
+
data = mappings.select { |m| !m.confident? }
|
24
|
+
table_print data, 'Unconfident', :url, :new_url
|
25
|
+
end
|
26
|
+
|
27
|
+
def excluded_report
|
28
|
+
data = mappings.select { |m| !m.output? }
|
29
|
+
table_print data, 'Excluded', :basename, :host, :tags
|
30
|
+
end
|
31
|
+
|
32
|
+
def invalid_report
|
33
|
+
data = mappings.select { |m| m.is?(:invalid) }
|
34
|
+
table_print data, 'Invalid', :url, :tags, :new_path
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,140 @@
|
|
1
|
+
class Migrator
|
2
|
+
module Rules
|
3
|
+
RULES = []
|
4
|
+
|
5
|
+
def rules
|
6
|
+
RULES
|
7
|
+
end
|
8
|
+
|
9
|
+
def self.rule(*args, &block)
|
10
|
+
RULES << Rule.new(*args, &block)
|
11
|
+
end
|
12
|
+
|
13
|
+
rule(:ignored) do
|
14
|
+
setup_match { |m| m.host == 'localhost' }
|
15
|
+
setup_action do |m|
|
16
|
+
m.output = false
|
17
|
+
true
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
rule(:update_host) do
|
22
|
+
setup_match { |m| m.host != 'timnew.me' }
|
23
|
+
setup_action do |m|
|
24
|
+
m.output = true
|
25
|
+
false
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
rule(:normalize_url) do
|
30
|
+
regex = /\/\//
|
31
|
+
setup_match { |m| m.path =~ regex }
|
32
|
+
setup_action do |m|
|
33
|
+
m.output = true
|
34
|
+
m.new_path = m.new_path.gsub regex, '/'
|
35
|
+
false
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
rule(:broken) do
|
40
|
+
setup_match { |m| !m.new_local_path.exist? }
|
41
|
+
setup_action do |m|
|
42
|
+
m.output = false
|
43
|
+
false
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
rule(:fix_root) do
|
48
|
+
setup_match { |m| m.is?(:broken) }
|
49
|
+
setup_match do |m|
|
50
|
+
!m.new_path.start_with?('/blog/')
|
51
|
+
end
|
52
|
+
|
53
|
+
setup_action do |m|
|
54
|
+
m.new_path = m.new_path.gsub(/^\/[^\/]+\//, '/blog/')
|
55
|
+
m.output = true
|
56
|
+
FIX_CHECKER.apply(m)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
rule(:time_stamp_url) do
|
61
|
+
setup_match { |m| m.is?(:broken) }
|
62
|
+
setup_match { |m| m.isnt?(:fixed) }
|
63
|
+
|
64
|
+
setup_match { |m| m.new_basename.match(/^\d\d\d\d-\d\d-\d\d-/) }
|
65
|
+
|
66
|
+
setup_action do |m|
|
67
|
+
m.new_path = m.new_path.sub(/\/\d\d\d\d-\d\d-\d\d-/, '/')
|
68
|
+
m.output = true
|
69
|
+
FIX_CHECKER.apply(m)
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
rule(:time_stamp_path, false) do
|
74
|
+
setup_match { |m| m.is?(:broken) }
|
75
|
+
setup_match { |m| m.isnt?(:fixed) }
|
76
|
+
setup_action do |m|
|
77
|
+
pattern = "*-#{m.basename}.md"
|
78
|
+
local_file = Migrator.posts.find { |f| f.fnmatch? pattern }
|
79
|
+
|
80
|
+
if local_file.nil?
|
81
|
+
false
|
82
|
+
else
|
83
|
+
m.tags << name
|
84
|
+
timestamp_path= local_file.basename.to_s.match(/^(\d\d\d\d-\d\d-\d\d)/).to_s.gsub(/-/, '/')
|
85
|
+
|
86
|
+
m.output = true
|
87
|
+
m.new_path = File.join('/', 'public', 'timestamp_path', m.basename.to_s)
|
88
|
+
FIX_CHECKER.apply(m)
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
rule(:auto_rename) do
|
94
|
+
setup_match { |m| m.is?(:broken) }
|
95
|
+
setup_match { |m| m.isnt?(:fixed) }
|
96
|
+
|
97
|
+
setup_match do |m|
|
98
|
+
parent = m.local_path.parent
|
99
|
+
parent.exist? and parent.children.length == 1
|
100
|
+
end
|
101
|
+
|
102
|
+
setup_action do |m|
|
103
|
+
m.new_path = Migrator.to_url m.local_path.parent.children.first.to_s
|
104
|
+
m.confident = false
|
105
|
+
m.output = true
|
106
|
+
FIX_CHECKER.apply(m)
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
rule(:fuzzy_rename) do
|
111
|
+
setup_match { |m| m.tags.include?(:broken) }
|
112
|
+
|
113
|
+
setup_match do |m|
|
114
|
+
parent = m.local_path.parent
|
115
|
+
parent.exist?
|
116
|
+
end
|
117
|
+
|
118
|
+
setup_action do |m|
|
119
|
+
components = Migrator.name_components(m.new_path)
|
120
|
+
|
121
|
+
fuzzy_matched = m.local_path.parent
|
122
|
+
.each_child
|
123
|
+
.sort_by do |candidate|
|
124
|
+
candidate_components = Migrator.name_components(candidate.to_s)
|
125
|
+
result = components & candidate_components
|
126
|
+
result.length
|
127
|
+
end
|
128
|
+
.reverse
|
129
|
+
.first
|
130
|
+
|
131
|
+
m.new_path = Migrator.to_url fuzzy_matched.to_s
|
132
|
+
|
133
|
+
m.confident = false
|
134
|
+
m.output = true
|
135
|
+
FIX_CHECKER.apply(m)
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
139
|
+
end
|
140
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'migrator/rules'
|
2
|
+
require 'migrator/class_methods'
|
3
|
+
require 'migrator/reports'
|
4
|
+
require 'migrator/outputs'
|
5
|
+
|
6
|
+
class Migrator
|
7
|
+
extend Rules
|
8
|
+
extend ClassMethods
|
9
|
+
|
10
|
+
include Reports
|
11
|
+
include Outputs
|
12
|
+
|
13
|
+
delegate_to_class :root, :local_path, :to_url, :rules, :verifier
|
14
|
+
|
15
|
+
attr_reader :mappings
|
16
|
+
|
17
|
+
def initialize(csv_file)
|
18
|
+
@mappings = CSV.open(csv_file)
|
19
|
+
.map { |row| Mapping.new(self, row[0]) }
|
20
|
+
end
|
21
|
+
|
22
|
+
def migrate_mapping(mapping)
|
23
|
+
rules.find do |rule|
|
24
|
+
rule.apply(mapping)
|
25
|
+
end
|
26
|
+
verifier.apply(mapping)
|
27
|
+
end
|
28
|
+
|
29
|
+
def migrate
|
30
|
+
mappings.map do |mapping|
|
31
|
+
mapping.execute
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
|
2
|
+
class Rule
|
3
|
+
attr_reader :name, :auto_tag
|
4
|
+
|
5
|
+
def initialize(name, auto_tag = true, &block)
|
6
|
+
@name = name
|
7
|
+
@auto_tag = auto_tag
|
8
|
+
@match_blocks = []
|
9
|
+
instance_eval &block
|
10
|
+
end
|
11
|
+
|
12
|
+
def apply(mapping)
|
13
|
+
return false unless match?(mapping)
|
14
|
+
act(mapping)
|
15
|
+
end
|
16
|
+
|
17
|
+
def setup_match(&block)
|
18
|
+
@match_blocks << block
|
19
|
+
end
|
20
|
+
|
21
|
+
def match?(mapping)
|
22
|
+
@match_blocks.all? {|b| b.call(mapping) }
|
23
|
+
end
|
24
|
+
|
25
|
+
def setup_action(&block)
|
26
|
+
@action_block = block
|
27
|
+
end
|
28
|
+
|
29
|
+
def act(mapping)
|
30
|
+
mapping.tags << name if auto_tag
|
31
|
+
@action_block.call(mapping)
|
32
|
+
end
|
33
|
+
end
|
metadata
ADDED
@@ -0,0 +1,119 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: hexo_disqus_migrator
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- TimNew
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-08-20 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: commander
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 4.2.0
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 4.2.0
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: terminal-table
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 1.4.5
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 1.4.5
|
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.3'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.3'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
description: hexo_disqus_migrator is a tool that help blogger to generate Disqus Url
|
70
|
+
Mapper for your Hexo or Octopress blog
|
71
|
+
email:
|
72
|
+
- timnew.wti@gmail.com
|
73
|
+
executables:
|
74
|
+
- disqus_migrator
|
75
|
+
extensions: []
|
76
|
+
extra_rdoc_files: []
|
77
|
+
files:
|
78
|
+
- .gitignore
|
79
|
+
- Gemfile
|
80
|
+
- LICENSE.txt
|
81
|
+
- README.md
|
82
|
+
- Rakefile
|
83
|
+
- bin/disqus_migrator
|
84
|
+
- hexo_disqus_migrator.gemspec
|
85
|
+
- lib/hexo_disqus_migrator.rb
|
86
|
+
- lib/migrator/mapping.rb
|
87
|
+
- lib/migrator/migrator.rb
|
88
|
+
- lib/migrator/migrator/class_methods.rb
|
89
|
+
- lib/migrator/migrator/outputs.rb
|
90
|
+
- lib/migrator/migrator/reports.rb
|
91
|
+
- lib/migrator/migrator/rules.rb
|
92
|
+
- lib/migrator/rule.rb
|
93
|
+
- lib/migrator/version.rb
|
94
|
+
homepage: ''
|
95
|
+
licenses:
|
96
|
+
- MIT
|
97
|
+
metadata: {}
|
98
|
+
post_install_message:
|
99
|
+
rdoc_options: []
|
100
|
+
require_paths:
|
101
|
+
- lib
|
102
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
103
|
+
requirements:
|
104
|
+
- - '>='
|
105
|
+
- !ruby/object:Gem::Version
|
106
|
+
version: '0'
|
107
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
108
|
+
requirements:
|
109
|
+
- - '>='
|
110
|
+
- !ruby/object:Gem::Version
|
111
|
+
version: '0'
|
112
|
+
requirements: []
|
113
|
+
rubyforge_project:
|
114
|
+
rubygems_version: 2.0.6
|
115
|
+
signing_key:
|
116
|
+
specification_version: 4
|
117
|
+
summary: hexo_disqus_migrator is a tool that help blogger to generate Disqus Url Mapper
|
118
|
+
for your Hexo or Octopress blog
|
119
|
+
test_files: []
|