-
-
Notifications
You must be signed in to change notification settings - Fork 248
/
Rakefile
72 lines (61 loc) · 1.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
# frozen_string_literal: true
require 'yaml'
require 'cgi'
require 'uri'
require 'jekyll'
begin
require 'rspec/core/rake_task'
RSpec::Core::RakeTask.new(:spec)
rescue LoadError
puts "Can't find RSpec"
end
def test_config
YAML.load_file('_config_test.yml', permitted_classes: [Psych, Symbol, Regexp])
end
def token
path = File.expand_path('~/.token')
File.read(path) if File.exist?(path)
end
def strip_whitespace(string)
string.gsub(/\r?\n/, ' ').strip.squeeze(' ')
end
task :set_env do
ENV['DISABLE_WHITELIST'] = 'true'
ENV['JEKYLL_GITHUB_TOKEN'] = token
end
task :build do
Rake::Task[:set_env].invoke
options = {
# 'config' => %w[_config.yml _config_test.yml]
}
Jekyll::Commands::Build.process(options)
end
task :serve do
Rake::Task[:set_env].invoke
options = {
'serving' => true,
'watch' => true,
'incremental' => true
# 'config' => %w[_config.yml _config_local.yml]
}
Jekyll::Commands::Build.process(options)
Jekyll::Commands::Serve.process(options)
end
task :format_yaml do
Dir['*/**.md'].each do |path|
content = File.read(path)
next unless content.match?(Jekyll::Document::YAML_FRONT_MATTER_REGEXP)
parts = content.split Jekyll::Document::YAML_FRONT_MATTER_REGEXP
yaml = YAML.load_file(parts[1], permitted_classes: [Psych, Symbol])
%w[title description].each { |key| yaml[key] = strip_whitespace(yaml[key]) if yaml[key] }
%w[tags category categories post_format].each { |key| yaml.delete(key) }
File.write(path, "#{yaml.to_yaml(line_width: -1)}---\n\n#{parts[4]}")
end
end
task :test do
Rake::Task[:spec].invoke
Rake::Task[:build].invoke
require 'html-proofer'
require_relative 'spec/amazon_link_check'
HTMLProofer.check_directory('./_site', test_config['proofer']).run
end