Created
August 26, 2010 16:20
-
-
Save lukeredpath/551705 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace :tag do | |
desc "Tag last post" | |
task :last do | |
system("./_scripts/tagposts last") | |
end | |
desc "Re-tag all posts" | |
task :all do | |
system("./_scripts/tagposts all") | |
end | |
end | |
desc "Deploy to production" | |
task :deploy => [:generate, 'tag:last'] do | |
system("rsync -avz --delete _site/ lukeredpath.co.uk:#{SITE_ROOT}") | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'jekyll' | |
module Site | |
def self.load | |
config = Jekyll.configuration('source' => File.join(File.dirname(__FILE__), *%w[..])) | |
Jekyll::Site.new(config).tap { |site| site.read } | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require File.join(File.dirname(__FILE__), *%w[site]) | |
require 'rubygems' | |
require 'www/delicious' | |
class Tagger | |
def initialize(api, site) | |
@api, @site = api, site | |
end | |
def tag_all | |
tag(@site.posts) | |
end | |
def tag_last | |
tag([@site.posts.last]) | |
end | |
def tag(posts) | |
posts.each do |post| | |
next if post.tags.empty? | |
if @api.posts_get(:url => url_for_post(post), :tag => default_tag).any? | |
@api.posts_delete(url_for_post(post)) | |
end | |
@api.posts_add( | |
:url => url_for_post(post), | |
:title => post.data['title'], | |
:tags => [post.tags, default_tag].flatten | |
) | |
puts "➜ Tagged post '#{post.data['title']}'." | |
end | |
end | |
def self.connect(username, password, site = Site.load) | |
api = WWW::Delicious.new(username, password) | |
new(api, site) | |
end | |
private | |
def url_for_post(post) | |
return @site.config['base_url'] + post.url | |
end | |
def default_tag | |
"@#{URI.parse(@site.config['base_url']).host}" | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require File.join(File.dirname(__FILE__), *%w[.. _lib tagger]) | |
require 'yaml' | |
delicious_config = YAML.load(File.open('_delicious.yml'))['delicious'] | |
tagger = Tagger.connect(delicious_config['username'], delicious_config['password']) | |
if ARGV[0] == 'all' | |
tagger.tag_all | |
elsif ARGV[0] == 'last' | |
tagger.tag_last | |
else | |
puts "Usage: tagger (all|last)" | |
exit 1 | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The series of scripts that I use to tag my blog posts automatically in Delicious. See here for more information.
My Delicious credentials are stored outside of the scripts, in the root of my site in a file called delicious.yml.
If you have a newer Delicious account, you'll need to modify this to work with OAuth.
As to where this files go, I structure the root of my Jekyll site like this (underscore prefixed dirs are not added to the generated output):