Skip to content

Instantly share code, notes, and snippets.

@bokuo-okubo
Created April 5, 2017 04:19
Show Gist options
  • Save bokuo-okubo/2cd806fb8de1acdce0a63d2931f12696 to your computer and use it in GitHub Desktop.
Save bokuo-okubo/2cd806fb8de1acdce0a63d2931f12696 to your computer and use it in GitHub Desktop.
require 'date'
require 'pathname'
ARTICLE_PATH = 'source/contents/articles/'
STUB_START_DATE = '2018-01-01'
namespace :stub do
@article_path = Pathname.pwd + Pathname.new(ARTICLE_PATH)
desc 'create stub blog entries'
task :create do
(1...100).each do |n|
date = Date.parse(STUB_START_DATE).+(n).to_s
title = "stub-entry-#{n}"
filename = @article_path.join("#{date}-#{title}.html.md").to_s
open(filename, "w") do |f|
f.write header(title, date, "stub") + body(n)
end
puts "#{filename} created!"
end
end
desc 'remove all stub blog entries'
task :remove do
Dir.glob(@article_path.join("*stub-entry*.html.md").to_s).each { |f| rm f }
end
private
def header(title, date, tags)
header =<<-HEADER
---
title: #{title}
date: #{date}
tags: #{tags}
---
HEADER
end
def body(num)
"これは#{num}番目のサンプルテキストです。"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment