-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathRakefile
151 lines (134 loc) · 4.75 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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
require 'rubygems'
require 'rake'
require 'yaml'
require 'time'
SOURCE = "."
CONFIG = {
'layouts' => File.join(SOURCE, "_layouts"),
'posts' => File.join(SOURCE, "_posts"),
'post_ext' => "md",
}
desc "Set up environment"
task :setup do
system("bundle install --path vendor/bundle") or raise
end # task :setup
desc "Build site"
task :build do
system("bundle exec jekyll build") or raise
end # task :serve
desc "Launch preview environment"
task :serve do
system("bundle exec jekyll serve -H 0.0.0.0")
end # task :serve
desc "Launch preview environment"
task :preview do
system("bundle exec jekyll serve")
end # task :preview
desc "Run check"
task :check do
system("bundle exec jekyll build") or raise
system("bundle exec htmlproofer \
--checks-to-ignore LinkCheck \
--log-level debug ./_site") or raise
system("bundle exec htmlproofer \
--checks-to-ignore ScriptCheck,ImageCheck \
--allow-hash-href \
--url-ignore '/localhost/' \
--assume_extension \
--typhoeus_config '{ \"ssl_verifyhost\": 0, \"ssl_verifypeer\": false }' \
--log-level debug ./_site")
end # task :check
desc "Create a new tutorial"
task :tutorial do
abort("Error: tutorial title not given, or too many arguments.") if ARGV.length != 2
ARGV.each {|a| task a.to_sym do; end}
title = ARGV[1]
tutorial = ARGV[1].downcase.strip.gsub(' ', '-').gsub(/[^\w-]/, '')
abort("Error: directory already exists: '_#{tutorial}'") if File.exist?("_#{tutorial}")
puts "Creating new tutorial: #{tutorial}"
puts " ==> creating tutorial directory: _#{tutorial}"
Dir.mkdir "_#{tutorial}"
tutorial_images = "assets/images/#{tutorial}"
puts " ==> creating new tutorial images directory: #{tutorial_images}"
Dir.mkdir tutorial_images
# index
open("_#{tutorial}/index.html", 'w') do |f|
f.puts '---'
f.puts 'layout: none'
f.puts '---'
f.puts '{%- include collection.html -%}'
f.puts '{%- assign first_page = site[collection.label] | where_exp: "item", "item.order != null" | sort: "order" | first -%}'
f.puts '<!DOCTYPE html>'
f.puts '<html lang="en-US">'
f.puts ' <meta charset="utf-8">'
f.puts ' <title>Redirecting…</title>'
f.puts ' <link rel="canonical" href="{{ first_page.url | prepend: site.baseurl }}">'
f.puts ' <script>location="{{ first_page.url | prepend: site.baseurl }}"</script>'
f.puts ' <meta http-equiv="refresh" content="0; url="{{ first_page.url | prepend: site.baseurl }}">'
f.puts ' <meta name="robots" content="noindex">'
f.puts ' <h1>Redirecting…</h1>'
f.puts ' <a href="{{ first_page.url | prepend: site.baseurl }}">Click here if you are not redirected.</a>'
f.puts '</html>'
end
puts " ==> creating first page: _#{tutorial}/01-overview.md"
open("_#{tutorial}/01-overview.md", 'w') do |f|
f.puts '---'
f.puts 'title: Overview'
f.puts 'order: 1'
f.puts 'duration: 1'
f.puts '---'
f.puts ''
f.puts 'This tutorial... (replace this) '
f.puts ''
f.puts '### What you\'ll learn'
f.puts ''
f.puts '- '
f.puts '- '
f.puts '- '
f.puts ''
f.puts '### What you\'ll need'
f.puts ''
f.puts '- '
f.puts '- '
f.puts '- '
end
puts ' ==> updating site configuration: _config.yml'
open("_config.yml", 'a') do |f|
f.puts " #{tutorial}:"
f.puts ' output: true'
f.puts ' permalink: /:collection/:name'
f.puts " title: #{title}"
f.puts " summary: A tutorial for #{title}"
f.puts ' category: Beginner # Beginner|Intermediate|Advanced|Series|Non-technical'
f.puts ' tags:'
f.puts ' - tutorial'
f.puts ' difficulty: 1 # number from 1 to 5'
f.puts ' duration: 10 # number of minutes'
f.puts ' status: draft # draft or published'
f.puts " published: #{Time.now.strftime('%Y-%m-%d')}"
f.puts ' author: Your Name <your.name@email.domain>'
f.puts ''
end
puts ''
puts "----------------------------------------------------------------------"
puts "A new skeleton tutorial has been created at _#{tutorial}, an"
puts "images directory created at #{tutorial_images} and the"
puts "the initial configuration added to the end of _config.yml."
puts "Please edit _config.yml and update the metadata for the new tutorial."
puts "----------------------------------------------------------------------"
puts ''
end # task :test
def ask(message, valid_options)
if valid_options
answer = get_stdin("#{message} #{valid_options.to_s.gsub(/"/, '').gsub(/, /,'/')} ") while !valid_options.include?(answer)
else
answer = get_stdin(message)
end
answer
end
def get_stdin(message)
print message
STDIN.gets.chomp
end
#Load custom rake scripts
Dir['_rake/*.rake'].each { |r| load r }