Skip to content

Commit

Permalink
Merge pull request #32 from nilenso/whitelist
Browse files Browse the repository at this point in the history
Adding ability to import posts only with whitelisted tags
  • Loading branch information
pote committed Sep 16, 2013
2 parents 1d5d10f + 54a1d1c commit 86b130b
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 2 deletions.
3 changes: 2 additions & 1 deletion README.md
Expand Up @@ -89,7 +89,8 @@ The planet.yml file contains the basic config options for planet. It consists of
```yaml
planet:
posts_directory: source/_posts/ # => Posts text files will be written into this directory
templates_directory: source/_layouts/ # => Planet specific layouts will be saved here, I suggest that it matches your Octopress/Jekyll layout directory.
templates_directory: source/_layouts/ # => Planet specific layouts will be saved here, I suggest that it matches your Octopress/Jekyll layout directory.
whitelisted_tags: [] # => Only posts that are tagged with any of these tags will be imported

blogs:
- author: "Cubox" # => Name that we will use as the author of this post (soon you wont have to specify this :)
Expand Down
1 change: 1 addition & 0 deletions bin/planet
Expand Up @@ -151,6 +151,7 @@ layout: post
planet:
posts_directory: source/_posts/
templates_directory: source/_layouts/
whitelisted_tags: []

blogs:
# Bare minimum to get it working
Expand Down
3 changes: 2 additions & 1 deletion lib/planet.rb
Expand Up @@ -5,12 +5,13 @@

class Planet

attr_accessor :config, :blogs
attr_accessor :config, :blogs, :whitelisted_tags

def initialize(config_file_path)
config_file = read_config_file(config_file_path)
self.config = config_file[:planet]
self.blogs = config_file[:blogs]
self.whitelisted_tags = self.config['whitelisted_tags']
end

def posts
Expand Down
8 changes: 8 additions & 0 deletions lib/planet/blog.rb
Expand Up @@ -40,6 +40,7 @@ def on_fetch_success(feed)
end

feed.entries.each do |entry|
next unless whitelisted?(entry)
content = if entry.content
self.sanitize_images(entry.content.strip)
elsif entry.summary
Expand Down Expand Up @@ -73,5 +74,12 @@ def sanitize_images(html)

html
end

def whitelisted?(entry)
return true if self.planet.whitelisted_tags.empty?
result = !(entry.categories & self.planet.whitelisted_tags).empty?
puts "\t=> Ignored post titled: #{entry.title} with categories: [#{entry.categories.join(', ')}]" unless result
result
end
end
end

0 comments on commit 86b130b

Please sign in to comment.