-
-
Save pocketWashburn/8328872 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
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["#{site.source}/_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, "#{site.source}/_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