Skip to content

Commit

Permalink
Add tags and categories to blogs
Browse files Browse the repository at this point in the history
  • Loading branch information
mparuszewski committed Jun 6, 2014
1 parent 1a69fbd commit c7b8efe
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 22 deletions.
14 changes: 9 additions & 5 deletions README.md
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -97,11 +97,13 @@ blogs:
feed: "http://blog.cuboxlabs.com/atom.xml" # => RSS/Atom feed feed: "http://blog.cuboxlabs.com/atom.xml" # => RSS/Atom feed
image: "http://cubox-website.s3.amazonaws.com/i-work-at-cubox/i-work-at-cubox-badge-small.png" # => Image to use when doing credits image: "http://cubox-website.s3.amazonaws.com/i-work-at-cubox/i-work-at-cubox-badge-small.png" # => Image to use when doing credits


- author: "Pablo Astigarraga" - author: "Pablo Astigarraga"
feed: "http://blog.poteland.com/atom.xml" feed: "http://blog.poteland.com/atom.xml"
image: "http://poteland.com/images/avatars/red_mage.png" image: "http://poteland.com/images/avatars/red_mage.png"
twitter: "poteland" # => Do you want a link to the user's twitter account next to the credits? You got it. categories: "programming" # => If you want to group your posts by categories or
url: "http://blog.poteland.com" # => This is not needed in most cases, because it's picked up from the feed, but if it's not on the feed tags: "go ruby jekyll git" # => tag them, you can do that.
twitter: "poteland" # => Do you want a link to the user's twitter account next to the credits? You got it.
url: "http://blog.poteland.com" # => This is not needed in most cases, because it's picked up from the feed, but if it's not on the feed
# then planet will ask you to specify it. :) # then planet will ask you to specify it. :)


``` ```
Expand All @@ -118,6 +120,8 @@ So this is pretty sweet: planet.rb doesn't really want to inject html and random
{{ blog_name }} # => "This is where I tell you stuff" {{ blog_name }} # => "This is where I tell you stuff"
{{ blog_slug }} # => "this-is-where-i-tell-you-stuff" {{ blog_slug }} # => "this-is-where-i-tell-you-stuff"
{{ blog_url }} # => "http://blog.poteland.com" {{ blog_url }} # => "http://blog.poteland.com"
{{ blog_categories }} # => "programming planet"
{{ blog_tags }} # => "go ruby jekyll"
{{ image_url }} # => "http://poteland.com/images/avatars/red_mage.png" {{ image_url }} # => "http://poteland.com/images/avatars/red_mage.png"
{{ author }} # => "Pablo Astigarraga" {{ author }} # => "Pablo Astigarraga"
{{ twitter }} # => "poteland" {{ twitter }} # => "poteland"
Expand Down
4 changes: 4 additions & 0 deletions bin/planet
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -154,6 +154,8 @@ title: "{{ post_title }}"
kind: article kind: article
created_at: {{ post_date }} created_at: {{ post_date }}
author: {{ author }} author: {{ author }}
categories: {{ blog_categories }}
tags: {{ blog_tags }}
layout: post layout: post
--- ---


Expand All @@ -176,4 +178,6 @@ blogs:
image: "http://poteland.com/images/avatars/red_mage.png" image: "http://poteland.com/images/avatars/red_mage.png"
# Other fields: # Other fields:
twitter: "poteland" twitter: "poteland"
categories: "programming"
tags: "go ruby jekyll git"
url: "http://blog.poteland.com" # => only required for people that don\'t have a \'url\' field on their RSS/Atom field' url: "http://blog.poteland.com" # => only required for people that don\'t have a \'url\' field on their RSS/Atom field'
16 changes: 9 additions & 7 deletions lib/planet.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -36,13 +36,15 @@ def read_config_file(config_file_path)
planet = config.fetch('planet', {}) planet = config.fetch('planet', {})
blogs = config.fetch('blogs', []).map do |blog| blogs = config.fetch('blogs', []).map do |blog|
Blog.new( Blog.new(
feed: blog['feed'], feed: blog['feed'],
url: blog['url'], url: blog['url'],
author: blog['author'], author: blog['author'],
image: blog['image'], image: blog['image'],
posts: [], posts: [],
planet: self, planet: self,
twitter: blog['twitter'] twitter: blog['twitter'],
categories: blog['categories'],
tags: blog['tags']
) )
end end


Expand Down
22 changes: 13 additions & 9 deletions lib/planet/blog.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -12,19 +12,23 @@ class Blog
:image, :image,
:twitter, :twitter,
:posts, :posts,
:categories,
:tags,
:planet, :planet,
:rss_data :rss_data


def initialize(attributes = {}) def initialize(attributes = {})
self.url = attributes[:url] self.url = attributes[:url]
self.feed = attributes[:feed] self.feed = attributes[:feed]
self.type = attributes[:type] self.type = attributes[:type]
self.name = attributes[:name] self.name = attributes[:name]
self.author = attributes[:author] self.author = attributes[:author]
self.image = attributes[:image] self.image = attributes[:image]
self.twitter = attributes[:twitter] self.twitter = attributes[:twitter]
self.posts = attributes.fetch(:posts, []) self.posts = attributes.fetch(:posts, [])
self.planet = attributes[:planet] self.planet = attributes[:planet]
self.categories = attributes.fetch(:categories, '')
self.tags = attributes.fetch(:tags, '')


# Feedzirra parsed data is made available for when the information # Feedzirra parsed data is made available for when the information
# provides is not enough. Transparency should help use cases we're # provides is not enough. Transparency should help use cases we're
Expand Down
3 changes: 2 additions & 1 deletion lib/planet/post.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ def to_h
blog_url: self.blog.url, blog_url: self.blog.url,
blog_name: self.blog.name, blog_name: self.blog.name,
blog_slug: self.blog.name.to_url(:limit => 50, :truncate_words => true), blog_slug: self.blog.name.to_url(:limit => 50, :truncate_words => true),
blog_categories: self.blog.categories,
blog_tags: self.blog.tags,
post_url: self.url, post_url: self.url,
twitter: self.blog.twitter, twitter: self.blog.twitter,
twitter_url: "http://twitter.com/#{ self.blog.twitter }", twitter_url: "http://twitter.com/#{ self.blog.twitter }",
Expand All @@ -39,7 +41,6 @@ def to_h
alias_method :to_hash, :to_h alias_method :to_hash, :to_h


def header def header
## TODO: We need categories/tags
file = self.blog.planet.config.fetch('templates_directory', '_layouts/') + 'header.md' file = self.blog.planet.config.fetch('templates_directory', '_layouts/') + 'header.md'
file_contents = File.read(file) file_contents = File.read(file)


Expand Down

0 comments on commit c7b8efe

Please sign in to comment.