Skip to content

Instantly share code, notes, and snippets.

@delputnam
Forked from iamamused/publisher.rb
Created June 20, 2014 10:14
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 delputnam/34b4b0e287cff8239f2b to your computer and use it in GitHub Desktop.
Save delputnam/34b4b0e287cff8239f2b to your computer and use it in GitHub Desktop.
module Jekyll
class PostPublisher < Generator
safe false
def replace(filepath, regexp, *args, &block)
content = File.read(filepath).gsub(regexp, *args, &block)
File.open(filepath, 'wb') { |file| file.write(content) }
end
def generate(site)
@files = Dir["_publish/*"]
@files.each_with_index { |f,i|
now = DateTime.now.strftime("%Y-%m-%d %H:%M:%S")
replace(f, /^date: unpublished/mi) { |match| "date: \"" + now + "\"" }
now = Date.today.strftime("%Y-%m-%d")
File.rename(f, "_posts/#{now}-#{File.basename(f)}")
}
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment