-
Notifications
You must be signed in to change notification settings - Fork 4
/
Rakefile
55 lines (45 loc) · 1.47 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
# frozen_string_literal: true
# Rake tasks for Jekyll
require 'rake/clean'
require 'stringex'
# <\!--more--\> is excerpt_separator
DEFAULT_TEXT = "Add first paragraph here \n\n\<\!--more--\>\n\nAdd more content here".freeze
POSTS_DIR = '_posts'.freeze
BUILD_DIR = '_site'.freeze
CLEAN.include BUILD_DIR
desc 'Build the site'
task :build do
sh 'jekyll', 'build', '--trace'
end
desc 'Start web server to preview site'
task :preview do
sh 'jekyll', 'serve', '--watch', '--drafts', '--trace', '--port', ENV.fetch('PORT', '4000')
end
# Hacking Rake for pretty args
# exit at the end of task so rake can not execute our args as task
# https://stackoverflow.com/a/36929059
desc 'Create a new post, usage: rake post "Title of post" "Link to the incident details page"'
task :post do
_, title, link = ARGV
title ||= 'Title of new Post'
link ||= 'Link to Incident details page'
timestamp = Time.now.strftime('%Y-%m-%d')
filepath = File.join(POSTS_DIR, "#{timestamp}-#{title.to_url}.md")
build_file(filepath, title, link, timestamp)
exit
end
task default: :preview
# create jekyll post file
def build_file(filepath, title, link, timestamp)
File.open(filepath, 'w') do |f|
f << "---\n"
f << "layout: post\n"
f << "title: \"#{title}\"\n"
f << "date: #{timestamp || Time.now.strftime('%Y-%m-%d')}\n"
f << "tags: ['New-Post', 'Tag']\n"
f << "---\n"
f << "\n"
f << "[see more details](#{link})\n\n#{DEFAULT_TEXT}\n"
end
puts "Created: #{filepath}"
end