jekyll-oldcomments 0.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 3bdb81d103ad3560b7e791adb890fd7033a86bba
4
+ data.tar.gz: a2049d7792711089a695eb5725fd7efa7c859243
5
+ SHA512:
6
+ metadata.gz: 566fed1ad578b5c1db32a1542a1098183c5e5422591a58d74899545fc1ad1d2b71288f0a7a6e65109a4f274c3db41db6c7785352bf4085f969edaed53e241545
7
+ data.tar.gz: cbd359cf64fc27345046a712771ceedfbb398aee4c6b77f88a4f3c5560f8f5458dd9161f9e9ff45730c18d9c46c1ba7250344d094703215f3ab0de74048b11f5
@@ -0,0 +1,45 @@
1
+ #!/usr/bin/env ruby
2
+ require 'rexml/document'
3
+ include REXML
4
+ require 'uri'
5
+
6
+ if not ARGV[0] or not File.exists?(ARGV[0])
7
+ puts('Usage: wp_comments2jekyll <wordpress-export.xml>')
8
+ exit(1)
9
+ end
10
+
11
+ xml = Document.new(File.new(ARGV[0]))
12
+ comment_dir = '_comments'
13
+ Dir.mkdir(comment_dir)
14
+
15
+ XPath.each(xml,'//item') do |item|
16
+ c_map = Hash.new
17
+ c_map['title'] = item.elements['title'].text.tr(':','')
18
+ c_map['link'] = item.elements['link'].text
19
+ c_map['path'] = URI.parse(c_map['link']).path
20
+
21
+ item.elements.each('wp:comment') do |comment|
22
+ #print_field(comment, 'wp:comment_author_email')
23
+ for f in ['wp:comment_author_email','wp:comment_author','wp:comment_id','wp:comment_author_url','wp:comment_author_IP','wp:comment_date','wp:comment_date_gmt','wp:comment_content','wp:comment_approved']
24
+ ele = comment.elements[f]
25
+ if ele
26
+ c_map[f.split(':')[1]] = ele.text
27
+ end
28
+ end
29
+
30
+ if c_map['comment_approved'] == '1'
31
+ filename = "%d-%s-%s" % [c_map['comment_id'], c_map['comment_date'].split(' ')[0], c_map['path'].gsub(/^\/|\/?$/,'').tr('/','_')]
32
+ fd = File.open(File.join(comment_dir, '%s.md' % filename),'w')
33
+ fd.write("---\n")
34
+ c_map.each do |key, value|
35
+ if key != 'comment_content'
36
+ fd.write("%s: %s\n" % [key.gsub(/comment_/,''), value])
37
+ end
38
+ end
39
+ fd.write("---\n")
40
+ fd.write(c_map['comment_content'])
41
+ fd.close()
42
+ end
43
+
44
+ end
45
+ end
@@ -0,0 +1,30 @@
1
+ require 'yaml'
2
+
3
+ class Jekyll::OldComments < Liquid::Tag
4
+
5
+ def render(context)
6
+ comment_dir = File.join(context.registers[:site].source, '_comments','*.md')
7
+ @comment_map = Hash.new
8
+ Dir[comment_dir].each do |comment|
9
+ yaml = YAML.load_file(comment)
10
+ fd = File.open(comment,'r')
11
+ text = fd.read().split('---')[2]
12
+ fd.close
13
+ path = yaml['path'].strip
14
+ if not @comment_map.has_key?(path)
15
+ @comment_map[path] = Array.new
16
+ end
17
+ @comment_map[path] << { 'meta' => yaml, 'text' => text.gsub(/^(.*)$/, '<p>\1</p>') }
18
+ end
19
+
20
+ @comment_map.each do |key, value|
21
+ @comment_map[key].sort!{ |a,b| a['meta']['date']<=>b['meta']['date'] }
22
+ end
23
+
24
+ tmpl = File.read File.join Dir.pwd, "_includes", 'comments.html'
25
+ (Liquid::Template.parse tmpl).render('comments' => @comment_map[context.registers[:page]['permalink']])
26
+ end
27
+
28
+ end
29
+
30
+ Liquid::Template.register_tag('old_comments', Jekyll::OldComments)
metadata ADDED
@@ -0,0 +1,46 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: jekyll-oldcomments
3
+ version: !ruby/object:Gem::Version
4
+ version: '0.5'
5
+ platform: ruby
6
+ authors:
7
+ - Sumit Khanna
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-10-28 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: A Jekyll plugin for extracting and displaying Wordpress comments
14
+ email: sumit@penguindreams.org
15
+ executables:
16
+ - wp_comments2jekyll
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - bin/wp_comments2jekyll
21
+ - lib/oldcomments.rb
22
+ homepage: http://penguindreams.org
23
+ licenses:
24
+ - Apache-2.0
25
+ metadata: {}
26
+ post_install_message:
27
+ rdoc_options: []
28
+ require_paths:
29
+ - lib
30
+ required_ruby_version: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - ">="
33
+ - !ruby/object:Gem::Version
34
+ version: '0'
35
+ required_rubygems_version: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: '0'
40
+ requirements: []
41
+ rubyforge_project:
42
+ rubygems_version: 2.2.5
43
+ signing_key:
44
+ specification_version: 4
45
+ summary: jekyll-oldcomments
46
+ test_files: []