Skip to content

Instantly share code, notes, and snippets.

@sheeran
Last active December 11, 2015 10:08
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 sheeran/4584424 to your computer and use it in GitHub Desktop.
Save sheeran/4584424 to your computer and use it in GitHub Desktop.
Read the categories of a directory of Jekyll/Octopress markdown posts and write those categories as OpenMeta tags
#!/usr/bin/ruby
# By Neal Sheeran www.nealsheeran.com
#
# Script to read the categories of all Jekyll/Octopress markdown
# posts in a directory and write those categories to the file
# as OpenMeta tags.
#
# Currently only allows for single-word tags: 'web design'
# will be written as two separate tags - 'web' and 'design'
#
# YAML categories should be in the form:
# categories: [blog, design, typography]
#
# Big Thanks to Brett Terpstra (@tscoff) for his assistance.
#
# Set ARCHIVE to a correct directory (and extension)
require 'yaml'
archive = "#{ENV['HOME']}/Dropbox/Archive/OctopressPosts/*.markdown"
Dir.glob(archive) do |post|
readin = YAML.load_file(post)
title = readin['title']
tags = readin['categories'].join(', ')
%x{/usr/local/bin/openmeta -a #{tags} -p #{post}}
puts "#{title}: #{tags}" # For possible output when used on command line
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment