jekyll-reposter 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.
- data/.gitignore +4 -0
- data/Gemfile +4 -0
- data/README.md +82 -0
- data/Rakefile +1 -0
- data/jekyll-reposter.gemspec +27 -0
- data/lib/jekyll-reposter.rb +100 -0
- metadata +96 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,82 @@
|
|
1
|
+
# Repost lib for Jekyll blog
|
2
|
+
|
3
|
+
|
4
|
+
I needed a convenient way to repost stuff in a jekyll blog, which i posted in another blog (corporate blog etc).
|
5
|
+
So i mungled together this gem, which uses Feedzirra as interface, so can handle both RSS and Atom Feeds.
|
6
|
+
|
7
|
+
## Install
|
8
|
+
|
9
|
+
add to Gemfile or install with gem install:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem "jekyll-reposter"
|
13
|
+
```
|
14
|
+
|
15
|
+
## Usage
|
16
|
+
|
17
|
+
create a ruby file in the jekyll root folder or subfolder like "tools"/"import"
|
18
|
+
etc. and fill in:
|
19
|
+
|
20
|
+
```ruby tools/notes.rb
|
21
|
+
require "jekyll-reposter"
|
22
|
+
|
23
|
+
reposter = Jekyll::Reposter.new "http://notes.it-jobs-und-stellen.de/notes.atom",
|
24
|
+
:tags => "[notes, external]", :pretend => true
|
25
|
+
|
26
|
+
reposter.create_if do |entry|
|
27
|
+
true
|
28
|
+
end
|
29
|
+
```
|
30
|
+
|
31
|
+
This will create all blog posts, if not exists yet inside my
|
32
|
+
```source/_posts/notes.it-jobs-und-stellen.de`` folder.
|
33
|
+
|
34
|
+
The ```create_if``` directive decideds if a blog posts is created. So if you
|
35
|
+
want to filter the passed feed, like to only show specific authors posts, then
|
36
|
+
here you can add any logic. In our case, we post all new items.
|
37
|
+
|
38
|
+
|
39
|
+
After finshed, you can run that script like
|
40
|
+
```bash
|
41
|
+
ruby tools/notes.rb
|
42
|
+
```
|
43
|
+
any time in your workflow, to add all new posts. Afterwards, check formatting and
|
44
|
+
add categories if necessary.
|
45
|
+
|
46
|
+
## Config
|
47
|
+
|
48
|
+
There are some options, you can pass to the Reposter:
|
49
|
+
|
50
|
+
```ruby
|
51
|
+
:tags => "[notes, external]", #categories
|
52
|
+
:dir => "source/_posts",
|
53
|
+
:allowed_tags => %w[h2 ul li ol h3 h4 h5 code pre quote blockquote cite hr],
|
54
|
+
:meta => { #default markdown meta tags
|
55
|
+
"comments" => true,
|
56
|
+
"layout" => "post"
|
57
|
+
},
|
58
|
+
:pretend => false # do not create posts, but show the generated output
|
59
|
+
```
|
60
|
+
|
61
|
+
Additionally, there are some replacings to make a better output, you can
|
62
|
+
customize that with the attribute "reposter.replacings", default are:
|
63
|
+
|
64
|
+
```ruby
|
65
|
+
reposter.replacings = {
|
66
|
+
"“" => '"',
|
67
|
+
"”" => '"',
|
68
|
+
"<" => "<",
|
69
|
+
">" => ">",
|
70
|
+
"</li>" => "",
|
71
|
+
"</ul>" => "",
|
72
|
+
"<ul>" => "",
|
73
|
+
"<pre>" => "\n\n```ruby\n",
|
74
|
+
"</pre>" => "```\n",
|
75
|
+
/\s+<li>/ => "* "
|
76
|
+
}
|
77
|
+
```
|
78
|
+
|
79
|
+
Also, for SEO reasons, a link to the original post will be added at the end of
|
80
|
+
each entry with a rel=canonical.
|
81
|
+
|
82
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "jekyll-reposter"
|
7
|
+
s.version = "0.1"
|
8
|
+
s.authors = ["Stefan Wienert"]
|
9
|
+
s.email = ["stefan.wienert@pludoni.de"]
|
10
|
+
s.homepage = ""
|
11
|
+
s.summary = %q{Reposting external feeds with jekyll}
|
12
|
+
s.description = %q{Provides a interface for generating posts as a repost from external feeds. Tested with octopress.}
|
13
|
+
|
14
|
+
s.rubyforge_project = "jekyll-reposter"
|
15
|
+
|
16
|
+
s.files = `git ls-files`.split("\n")
|
17
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
18
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
19
|
+
s.require_paths = ["lib"]
|
20
|
+
|
21
|
+
# specify any dependencies here; for example:
|
22
|
+
# s.add_development_dependency "rspec"
|
23
|
+
s.add_runtime_dependency "feedzirra"
|
24
|
+
s.add_runtime_dependency "curb", "~> 0.8"
|
25
|
+
s.add_runtime_dependency "stringex"
|
26
|
+
s.add_runtime_dependency "sanitize"
|
27
|
+
end
|
@@ -0,0 +1,100 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require "active_support"
|
4
|
+
require 'feedzirra'
|
5
|
+
require "fileutils"
|
6
|
+
require "uri"
|
7
|
+
require "stringex"
|
8
|
+
require "sanitize"
|
9
|
+
require "yaml"
|
10
|
+
|
11
|
+
module Jekyll
|
12
|
+
class Reposter
|
13
|
+
VERSION = "0.0.1"
|
14
|
+
|
15
|
+
attr_accessor :replacings
|
16
|
+
|
17
|
+
# fetching a single feed
|
18
|
+
def initialize(feed, options={})
|
19
|
+
@options = {
|
20
|
+
:tags => "[notes, external]",
|
21
|
+
:dir => "source/_posts",
|
22
|
+
:allowed_tags => %w[h2 ul li ol h3 h4 h5 code pre quote blockquote cite hr],
|
23
|
+
:meta => {
|
24
|
+
"comments" => true,
|
25
|
+
"layout" => "post"
|
26
|
+
},
|
27
|
+
:pretend => false
|
28
|
+
}.merge options
|
29
|
+
|
30
|
+
@replacings = {
|
31
|
+
"“" => '"',
|
32
|
+
"”" => '"',
|
33
|
+
"<" => "<",
|
34
|
+
">" => ">",
|
35
|
+
"</li>" => "",
|
36
|
+
"</ul>" => "",
|
37
|
+
"<ul>" => "",
|
38
|
+
"<pre>" => "\n\n```ruby\n",
|
39
|
+
"</pre>" => "```\n",
|
40
|
+
/\s+<li>/ => "* "
|
41
|
+
}
|
42
|
+
|
43
|
+
@feed = Feedzirra::Feed.fetch_and_parse(feed)
|
44
|
+
@uri = URI.parse(feed)
|
45
|
+
@dir = File.join @options[:dir], @uri.host
|
46
|
+
FileUtils.mkdir_p(@dir)
|
47
|
+
puts "Working dir: #{@dir}"
|
48
|
+
end
|
49
|
+
|
50
|
+
# creates the blog entry file, if passed block
|
51
|
+
# returns true. block is a entry object from
|
52
|
+
# feedzirra, like filtering
|
53
|
+
def create_if(&block)
|
54
|
+
@feed.entries.each do |entry|
|
55
|
+
if block.call(entry)
|
56
|
+
create_entry(entry)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
def create_entry(entry)
|
62
|
+
date = entry.published.strftime("%Y-%m-%d")
|
63
|
+
filename = File.join @dir, date + "-" + entry.title.to_url + ".markdown"
|
64
|
+
unless File.exists? filename
|
65
|
+
content = Sanitize.clean entry.content, :elements => @options[:allowed_tags]
|
66
|
+
|
67
|
+
end
|
68
|
+
@replacings.each do |from,to|
|
69
|
+
content.gsub! from, to
|
70
|
+
end
|
71
|
+
|
72
|
+
meta = {
|
73
|
+
"title" => entry.title,
|
74
|
+
"date" => entry.published.strftime("%Y-%m-%d %H:%M"),
|
75
|
+
}.merge(@options[:meta])
|
76
|
+
|
77
|
+
tags = @options[:tags]
|
78
|
+
file = <<DOC
|
79
|
+
#{meta.to_yaml}
|
80
|
+
categories: #{tags}
|
81
|
+
---
|
82
|
+
#{content}
|
83
|
+
|
84
|
+
---
|
85
|
+
<i>Reposted from <a href='#{entry.url}' rel='canonical'>#{@uri.host}</a></i>
|
86
|
+
DOC
|
87
|
+
|
88
|
+
if !@options[:pretend]
|
89
|
+
File.open filename, "w+" do |f|
|
90
|
+
puts "Writing #{filename}"
|
91
|
+
f.write file
|
92
|
+
end
|
93
|
+
else
|
94
|
+
breakwater = (["="] * 20).join + "\n"
|
95
|
+
puts "#{breakwater}Would create #{filename} with content:\n#{breakwater}#{file}"
|
96
|
+
end
|
97
|
+
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
metadata
ADDED
@@ -0,0 +1,96 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: jekyll-reposter
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: '0.1'
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Stefan Wienert
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-02-19 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: feedzirra
|
16
|
+
requirement: &74477300 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *74477300
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: curb
|
27
|
+
requirement: &74477000 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ~>
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0.8'
|
33
|
+
type: :runtime
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *74477000
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: stringex
|
38
|
+
requirement: &74476730 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ! '>='
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '0'
|
44
|
+
type: :runtime
|
45
|
+
prerelease: false
|
46
|
+
version_requirements: *74476730
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: sanitize
|
49
|
+
requirement: &74476480 !ruby/object:Gem::Requirement
|
50
|
+
none: false
|
51
|
+
requirements:
|
52
|
+
- - ! '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
type: :runtime
|
56
|
+
prerelease: false
|
57
|
+
version_requirements: *74476480
|
58
|
+
description: Provides a interface for generating posts as a repost from external feeds.
|
59
|
+
Tested with octopress.
|
60
|
+
email:
|
61
|
+
- stefan.wienert@pludoni.de
|
62
|
+
executables: []
|
63
|
+
extensions: []
|
64
|
+
extra_rdoc_files: []
|
65
|
+
files:
|
66
|
+
- .gitignore
|
67
|
+
- Gemfile
|
68
|
+
- README.md
|
69
|
+
- Rakefile
|
70
|
+
- jekyll-reposter.gemspec
|
71
|
+
- lib/jekyll-reposter.rb
|
72
|
+
homepage: ''
|
73
|
+
licenses: []
|
74
|
+
post_install_message:
|
75
|
+
rdoc_options: []
|
76
|
+
require_paths:
|
77
|
+
- lib
|
78
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
79
|
+
none: false
|
80
|
+
requirements:
|
81
|
+
- - ! '>='
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: '0'
|
84
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
85
|
+
none: false
|
86
|
+
requirements:
|
87
|
+
- - ! '>='
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
requirements: []
|
91
|
+
rubyforge_project: jekyll-reposter
|
92
|
+
rubygems_version: 1.8.15
|
93
|
+
signing_key:
|
94
|
+
specification_version: 3
|
95
|
+
summary: Reposting external feeds with jekyll
|
96
|
+
test_files: []
|