-
Notifications
You must be signed in to change notification settings - Fork 673
Expand file tree
/
Copy pathRakefile
More file actions
158 lines (131 loc) · 3.69 KB
/
Copy pathRakefile
File metadata and controls
158 lines (131 loc) · 3.69 KB
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
152
153
154
155
156
157
158
# frozen_string_literal: true
begin
require "bundler/setup"
rescue LoadError => e
warn e.message
warn "Run `gem install bundler` to install Bundler"
exit(-1)
end
LANGUAGES = %w[bg de en es fr id it ja ko pl pt ru tr ua vi zh_cn zh_tw].freeze
CONFIG = "_config.yml"
task default: [:build]
desc "Build CSS with Tailwind"
task :"build-css" do
sh "npm run build-css"
end
desc "Run every test suite, the markdown linter and a full build"
task test: %i[test-news-plugin test-html-lang-plugin test-linter test-search-index lint build]
desc "Build the Jekyll site"
task build: :"build-css" do
require "jekyll"
Jekyll::Commands::Build.process({})
end
desc "Serve the Jekyll site locally"
task serve: :"build-css" do
require "jekyll"
# Same pair `jekyll serve` runs. Serving on its own only hands out whatever
# _site already holds, which leaves a fresh clone with nothing to serve and
# never picks up an edit.
options = { "serving" => true, "watch" => true }
Jekyll::Commands::Build.process(options)
Jekyll::Commands::Serve.process(options)
end
namespace :new_post do
def create_template(lang)
url_title = "short-title"
title = "Post Title"
now = Time.now.utc
datetime = now.strftime("%Y-%m-%d %H:%M:%S %z")
date = now.strftime("%Y-%m-%d")
filename = "#{date}-#{url_title}.md"
path = File.join(lang, "news", "_posts", filename)
content = <<-TEMPLATE.gsub(/^ */, "")
---
layout: news_post
title: "#{title}"
author: "Unknown Author"
translator:
date: #{datetime}
lang: #{lang}
---
Content.
TEMPLATE
$stderr.print "Creating template `#{path}'... "
begin
if File.exist?(path)
warn "Could not create template, `#{path}' already exists."
else
File.open(path, "w") {|f| f.write content }
warn "done."
end
rescue => e
warn e.message
end
end
desc "Create a news post template for language `lang'"
task :lang do
puts "Please specify one of the valid language codes:"
puts LANGUAGES.join(", ") << "."
end
LANGUAGES.each do |lang|
task lang.to_sym do
create_template(lang)
end
end
end
desc "Run linter on markdown files"
task :lint do
require_relative "lib/linter"
Linter.new.run
end
namespace :check do
desc "Check for broken internal links"
task :links do
require "html-proofer"
options = {
checks: [
'Links',
'Images',
'Scripts',
],
ignore_empty_alt: true,
ignore_missing_alt: true,
check_external_hash: false,
check_internal_hash: false,
}
HTMLProofer.check_directory('_site', options).run
end
desc "Validate _site markup with validate-website"
task :markup do
require_relative "lib/markup_checker"
MarkupChecker.new.check
end
end
require "rake/testtask"
Rake::TestTask.new(:"test-linter") do |t|
t.description = "Run tests for the Linter library"
t.libs = ["test", "lib"]
t.test_files = FileList['test/test_linter_*.rb']
t.verbose = true
end
require "rake/testtask"
Rake::TestTask.new(:"test-news-plugin") do |t|
t.description = "Run tests for the news archive plugin"
t.libs = ["test"]
t.test_files = FileList['test/test_plugin_news.rb']
t.verbose = true
end
require "rake/testtask"
Rake::TestTask.new(:"test-html-lang-plugin") do |t|
t.description = "Run tests for the HTML language plugin"
t.libs = ["test"]
t.test_files = FileList['test/test_plugin_html_lang.rb']
t.verbose = true
end
require "rake/testtask"
Rake::TestTask.new(:"test-search-index") do |t|
t.description = "Run tests for the search index library"
t.libs = ["test", "lib"]
t.test_files = FileList['test/test_search_index.rb']
t.verbose = true
end