forked from BenWard/benward-web
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRakefile
98 lines (80 loc) · 2.49 KB
/
Rakefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
require 'date'
def jekyll(opts="", path="")
sh "cd jekyll"
sh "jekyll " + opts
end
desc "Build site using Jekyll"
task :build do
jekyll
end
desc "Remove existing _sites directory"
task :clean do
sh "rm -r _site"
end
task :rebuild => [:clean, :build]
desc "Rebuild the Jekyll site"
task :default => :build do
jekyll
end
namespace :blog do
desc "Create a new entry"
task :new, [:slug] do |t, args|
raise ArgumentError, "Must specify a slug name" unless args.slug
date = DateTime.now
slug = "#{DateTime.now.strftime("%Y-%m-%d")}-#{args.slug}"
dir_name = "jekyll/_posts/blog/#{date.year}"
file_name = "#{dir_name}/#{slug}.md"
Dir::mkdir dir_name unless FileTest::directory? dir_name
File.open file_name, 'w' do |f|
# Start YML Front Matter
f.puts '---'
f.puts 'layout: blog'
f.puts 'category: blog'
f.puts 'title: "New Post"'
f.puts "date: \"#{date.iso8601}\""
f.puts "summary: "
f.puts "tags: []"
f.puts "geo:"
f.puts ' name: "San Francisco"'
f.puts ' xy: "37.77493,122.41942"'
f.puts '---'
f.puts "\n\n"
end
sh "open #{file_name}"
end
desc "Touch a post and set its publication date to now"
task :touch, [:post] do |t, args|
base = "jekyll/_posts/blog/"
raise ArgumentError, "Must specify a post file" unless args.post
/^([0-9]{4})\-/.match(args.post)
year = $1
file_name = "#{base}#{year}/#{args.post}"
raise "Post not found" unless FileTest::file? file_name
content = File.read file_name
content.sub!(/^date: .*$/, "date: \"#{DateTime.now.iso8601}\"")
File.open file_name, 'w' do |f| f.puts content end
end
desc "Mark a post as being updated"
task :update, [:post] do |t, args|
base = "jekyll/_posts/blog/"
raise ArgumentError, "Must specify a post file" unless args.post
/^([0-9]{4})\-/.match(args.post)
year = $1
file_name = "#{base}#{year}/#{args.post}"
raise "Post not found" unless FileTest::file? file_name
content = File.read file_name
if /^updated:/.match(content)
content.sub!(/^updated: .*$/, "updated: \"#{DateTime.now.iso8601}\"")
else
content.sub!(/^(date: .*)$/, "\\1\nupdated: \"#{DateTime.now.iso8601}\"")
end
File.open file_name, 'w' do |f| f.puts content end
end
end
namespace :server do
desc "Update apache configuration for the site"
task :reconfigure do
sh "cp conf/apache/me.benward.conf /etc/apache/sites-available/me.benward.conf"
sh "apache2ctl reload"
end
end