summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordavidtsadler <davidtsadler@googlemail.com>2012-02-08 23:15:46 +0000
committerdavidtsadler <davidtsadler@googlemail.com>2012-02-08 23:15:46 +0000
commit3c2ac474f20da6baf804e5c51f62c2c8cb19c6eb (patch)
tree743001d97c34d2f963ad20b01c60c2c3adb09895
parent1dcb61ea904e901548deba046016661e23a1f12f (diff)
Update rake task for better creation of test posts.
-rw-r--r--Rakefile22
-rw-r--r--_config.yml.example12
-rw-r--r--lib/random.rb31
-rw-r--r--lib/templates/post.markdown (renamed from templates/post.markdown)6
4 files changed, 58 insertions, 13 deletions
diff --git a/Rakefile b/Rakefile
index 21d2861..44d0628 100644
--- a/Rakefile
+++ b/Rakefile
@@ -1,4 +1,6 @@
+$:.unshift(File.dirname(__FILE__))
require 'yaml'
+require 'lib/random'
task :default => [:'site:deploy:development']
@@ -41,12 +43,12 @@ namespace :site do
end
end
-namespace :posts do
+namespace :test_posts do
desc 'Creates several test posts.'
task :create => [:clean, :create_directory] do
- year = Time.now.year
- (1..20).each do |day|
- save_post(Time.new(year, 1, day), "Dummy post #{day}")
+ (1..@config['num_test_posts']).each do |day|
+ date, title, category = TestPosts::Random.generate
+ save_post(date, title, "Testing", "A test post", category, true)
end
end
@@ -57,15 +59,21 @@ namespace :posts do
desc 'Creates the required posts directory if one does not exist.'
task :create_directory => [:load_config] do
- Dir.mkdir(@config['posts']) unless File.directory?(@config['posts'])
+ dir = @config['posts'] + '/test'
+ FileUtils.mkdir_p(dir) unless File.directory?(dir)
end
private
- def save_post(date, title)
+ def save_post(date, title, author, description, categories, test = false)
template = File.read("templates/post.markdown")
template.gsub!(/:title/, title)
+ template.gsub!(/:author/, author)
+ template.gsub!(/:description/, description)
+ template.gsub!(/:categories/, categories)
- filename = "#{@config['source']}/_posts/#{date.strftime('%Y-%m-%d')}-#{parameterize(title)}.markdown"
+ filename = "#{@config['source']}/_posts"
+ filename << '/test' if test
+ filename << "/#{date.strftime('%Y-%m-%d')}-#{parameterize(title)}.markdown"
File.open(filename, 'w') { |f| f.write(template) }
end
diff --git a/_config.yml.example b/_config.yml.example
index 54f8732..aaf1025 100644
--- a/_config.yml.example
+++ b/_config.yml.example
@@ -1,5 +1,5 @@
# ***************************
-# SITE CONFIG
+# SITE
# ***************************
# Set to true when building the site for production.
@@ -51,7 +51,7 @@ copyright_year:
#feedburner:
# ***************************
-# JEKYLL CONFIG
+# JEKYLL
# ***************************
# Markdown engine that will be used.
@@ -67,7 +67,7 @@ destination: public
permalink: /archives/:year/:month/:day/:title/
# ***************************
-# PLUGINS CONFIG
+# PLUGINS
# ***************************
# Directory where plugins are located.
@@ -84,3 +84,9 @@ plugins: _site_build/_plugins
# String prefixed to the meta description of the category page. Defaults to Category:
#category_meta_description_prefix:
+
+# ***************************
+# RAKE TASKS
+# ***************************
+# The number of test posts that will be generated by the task test_posts:create
+num_test_posts: 50
diff --git a/lib/random.rb b/lib/random.rb
new file mode 100644
index 0000000..9204138
--- /dev/null
+++ b/lib/random.rb
@@ -0,0 +1,31 @@
+module TestPosts
+ module Random
+ APPLICATIONS = ['Apache 2', 'MySQL', 'Sqlite', 'Magento']
+
+ DISTROS = ['Ubuntu', 'Fedora', 'Kubuntu', 'Mythbuntu', 'SUSE Linux', 'Debian']
+
+ FRAMEWORKS = ['Ruby on Rails', 'CakePHP', 'Wordpress', 'Sinatra', 'Drupal']
+
+ LANGUAGES = ['Actionscript', 'Ada', 'Assembly', 'C', 'C#', 'C++', 'Cobol', 'ColdFusion', 'D', 'Delphi', 'Erlang', 'Forth', 'Fortran', 'Haskell', 'Java', 'JavaScript', 'Lisp', 'Lua', 'OCaml', 'Objective C', 'PHP', 'Pascal', 'Perl', 'Python', 'Rexx', 'Ruby', 'SQL', 'Scala', 'Scheme', 'Shell', 'Smalltalk', 'Tcl', 'Visual Basic']
+
+ TITLES = [
+ [['Getting started with', 'A tutorial on', 'Why I like', "Why I don't like", 'Developing applications with'], LANGUAGES + FRAMEWORKS],
+ [['Getting started with', 'How to install', 'How to upgrade'], DISTROS + APPLICATIONS + FRAMEWORKS],
+ [['Developing a plugin for'], FRAMEWORKS]
+ ]
+
+ def self.generate
+ topics, subjects = TITLES[rand(TITLES.size)]
+ topic = topics[rand(topics.size)]
+ subject = subjects[rand(subjects.size)]
+ [date, topic + ' ' + subject, subject]
+ end
+
+ private
+ def self.date
+ jdFrom = Date.today.prev_year.jd
+ jdTo = Date.today.jd
+ Date.jd(rand((jdTo + 1) - jdFrom) + jdFrom)
+ end
+ end
+end
diff --git a/templates/post.markdown b/lib/templates/post.markdown
index 0c14cbd..5bd0de9 100644
--- a/templates/post.markdown
+++ b/lib/templates/post.markdown
@@ -1,9 +1,9 @@
---
layout: post
title: :title
-author:
-description:
-categories:
+author: :author
+description: :description
+categories: :categories
---
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Fusce et tellus ac sem vestibulum tristique ac at magna. Proin eros ipsum, egestas sit amet rutrum non, fringilla ut tellus. Sed facilisis rhoncus libero ornare interdum. Morbi a dui id quam dignissim mollis at sit amet purus. Ut pretium malesuada dolor, eu luctus lorem bibendum id. Mauris cursus cursus est sit amet lobortis. Quisque sit amet dui quis sapien fringilla tempus et convallis lectus. Integer pretium tristique sollicitudin. Fusce at ante et tellus vulputate congue. Aliquam nec ligula est. Vestibulum aliquet scelerisque neque, ut elementum neque mattis id. Sed non mauris quam. Vivamus id augue felis. Etiam eleifend, erat sit amet tempor tempor, nibh neque tristique lorem, pretium adipiscing nulla lorem sit amet lacus. Vestibulum odio mauris, hendrerit non dictum sit amet, consequat in mi. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Nulla est nulla, pulvinar eget volutpat quis, placerat nec metus. Vivamus tristique elit ac lectus vestibulum bibendum. Phasellus ac diam purus, cursus imperdiet lorem. Sed a nulla nec velit placerat tempus.