- Notifications
You must be signed in to change notification settings - Fork 631
/
Copy pathRakefile
131 lines (108 loc) · 2.78 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
# frozen_string_literal: true
begin
require"bundler/setup"
rescueLoadError=>e
warne.message
warn"Run `gem install bundler` to install Bundler"
exit(-1)
end
LANGUAGES=%w[bgdeenesfriditjakoplptrutrvizh_cnzh_tw].freeze
CONFIG="_config.yml"
taskdefault: [:build]
desc"Run tests (test-linter, lint, build)"
tasktest: %i[test-news-plugintest-linterlintbuild]
desc"Build the Jekyll site"
task:builddo
require"jekyll"
Jekyll::Commands::Build.process({})
end
desc"Serve the Jekyll site locally"
task:servedo
require"jekyll"
Jekyll::Commands::Serve.process({})
end
namespace:new_postdo
defcreate_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
ifFile.exist?(path)
warn"Could not create template, `#{path}' already exists."
else
File.open(path,"w"){|f| f.writecontent}
warn"done."
end
rescue=>e
warne.message
end
end
desc"Create a news post template for language `lang'"
task:langdo
puts"Please specify one of the valid language codes:"
putsLANGUAGES.join(", ") << "."
end
LANGUAGES.eachdo |lang|
tasklang.to_symdo
create_template(lang)
end
end
end
desc"Run linter on markdown files"
task:lintdo
require_relative"lib/linter"
Linter.new.run
end
namespace:checkdo
desc"Check for broken internal links"
task:linksdo
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:markupdo
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