forked from theforeman/theforeman.org
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rakefile
53 lines (45 loc) · 1.15 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
task :default => :build
desc 'Clean up generated site'
task :clean do
sh 'rm -rf _site'
end
desc 'Build site with Jekyll'
task :build do
sh "jekyll build"
end
desc 'Start server'
task :server do
sh "jekyll serve --watch --incremental"
end
desc 'Starts up browser window (requires running server)'
task :browser do
sh "xdg-open http://localhost:4000/index.html"
end
desc "Given a title as an argument, create a new post file"
task :new_post, [:title] do |t, args|
title = args.title || ENV["title"] || "new-post"
title_clean = title.downcase.strip.gsub(/\s/, '-').gsub(/[^\w-]/, '')
filename = "#{Time.now.strftime('%Y-%m-%d')}-#{title_clean}.md"
path = File.join("_posts", filename)
if File.exist? path; raise RuntimeError.new("#{path} exists! Refusing to overwrite"); end
File.open(path, 'w') do |file|
file.write <<-EOS
---
layout: post
title: #{args.title}
date: #{Time.now.utc.strftime('%Y-%m-%d %k:%M:%S')}
author: Foreman
tags:
- foreman
---
My abstract goes here
<!--more-->
The rest of the post goes here.
EOS
end
if editor = ENV["EDITOR"]
system("#{editor} #{path}")
else
puts "#{path} is ready for editing."
end
end