-
Notifications
You must be signed in to change notification settings - Fork 1
/
config.rb
116 lines (88 loc) · 3.3 KB
/
config.rb
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
set :url_root, 'https://mywarp.github.com'
config[:js_dir] = 'assets/javascripts'
config[:css_dir] = 'assets/stylesheets'
# Do not include files in the final build.
# Instead, we link to the files inside the GitHub Repo (see file_url below)
ignore 'files/*'
# Activate and configure extensions
# https://middlemanapp.com/advanced/configuration/#configuring-extensions
activate :aria_current
activate :inline_svg
activate :external_pipeline,
name: :esbuild,
command: build? ? 'npm run build:esbuild' : 'npm run watch:esbuild',
source: ".tmp/javascripts"
activate :external_pipeline,
name: :sass,
command: build? ? 'npm run build:sass' : 'npm run watch:sass',
source: ".tmp/stylesheets"
activate :pagination do
# See https://github.com/suresh44t/middleman-pagination#usage
pageable_set :development_builds do
# After 3.1.1-SNAPSHOT+Travis-b1930.git-10b9684e31, MyWarp switched its CI from Travis to Github actions. Build numbers started over from 0.
# Here, we sort the list by (a) CI (alphabetically, i.e. Github Actions comes first) and (b) by build number (higher ones come first).
data.builds.sort_by { |file_name, content| [content.build.by, -content.build.number.to_i]}
end
end
# With alternative layout
# page '/path/to/file.html', layout: 'other_layout'
# Proxy pages
# https://middlemanapp.com/advanced/dynamic-pages
@app.data.builds.each do |id, info|
# see https://github.com/middleman/middleman/issues/1246#issuecomment-163596912
proxy "/builds/#{info.build.number}.html",
"single_build_information",
:locals => {:info => info, :title => "Build No. #{info.build.number}" },
:ignore => true
end
activate :autoprefixer
# Build-specific configuration
# https://middlemanapp.com/advanced/configuration/#environment-specific-settings
configure :development do
set :debug_assets, true
activate :livereload
end
configure :build do
activate :minify_html
activate :imageoptim do |options|
#do not use pngout and svgo, both are not part of image_optim_pack
options.pngout = false
options.svgo = false
end
activate :robots,
:rules => [
{:user_agent => '*', :allow => %w(/)}
],
:sitemap => config.url_root + "/sitemap.xml"
end
# after_build hook
# https://middlemanapp.com/advanced/custom-extensions/#after_build
after_build do |builder|
builder.thor.run 'npm run purgecss'
end
# Helpers
# Methods defined in the helpers block are available in templates
# https://middlemanapp.com/basics/helper-methods
helpers do
def link_to_commit(commitHash)
truncatedHash = commitHash[0...7]
return link_to truncatedHash, "https://github.com/MyWarp/MyWarp/commit/" + commitHash
end
def artifact_files(buildInfo, includePattern="*", excludePattern="")
path = 'source/files/' + buildInfo.build.number.to_s + '_' + buildInfo.commit.short_hash.to_s + '/';
files = Dir.glob( path + includePattern )
unless excludePattern.empty?
files -= Dir.glob(path + excludePattern)
end
return files
end
def file_url(binary)
base_url = 'https://github.com/MyWarp/mywarp.github.io/raw/src/'
absolute_path = Pathname.new(binary)
project_root = Pathname.new(".")
return base_url + absolute_path.relative_path_from(project_root).to_s
end
def file_size(binary, format="%.2f")
return format % (File.size(binary).to_f / 2**20)
end
end