Skip to content

Instantly share code, notes, and snippets.

@lukeredpath
Created August 26, 2010 16:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lukeredpath/551705 to your computer and use it in GitHub Desktop.
Save lukeredpath/551705 to your computer and use it in GitHub Desktop.
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
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
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
#!/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
@lukeredpath
Copy link
Author

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):

_lib/ # support scripts like site.rb and tagger.rb
_scripts/ # scripts like tagposts

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment