Last active
December 19, 2015 02:09
-
-
Save ChrisMissal/5881424 to your computer and use it in GitHub Desktop.
Rake task to convert gists from one format to another
This file contains hidden or 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
| desc "Convert old gist tags into new format" | |
| task :convert_gists, :dir do |t, args| | |
| puts ">>> !! Please provide a directory, eg. rake convert_gists[source/_new_posts]" unless args.dir | |
| if args.dir | |
| if args.dir == "/" | |
| dir = "" | |
| else | |
| dir = args.dir.sub(/(\/*)(.+)/, "\\2").sub(/\/$/, ''); | |
| end | |
| Dir.open dir do |d| | |
| d.each do |file| | |
| next if file == '.' or file == '..' | |
| file_location = File.join(dir, file) | |
| text = File.read(file_location) | |
| new_text = text.gsub(/\[gist id\=(\"?)(\d*)(\"?)\]/, '{% gist \2 %}') # [gist id=1234567] => {% gist 1234567 %} | |
| File.open(file_location, "w") { |f| f.puts new_text } | |
| end | |
| end | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment