-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfig.rb
More file actions
97 lines (70 loc) · 2.24 KB
/
config.rb
File metadata and controls
97 lines (70 loc) · 2.24 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
# frozen_string_literal: true
Bundler.require(:default)
require 'dotenv/load'
require 'pry'
require 'slim'
Slim::Engine.disable_option_validator!
set :markdown_engine, :redcarpet
set :markdown, fenced_code_blocks: true
set :images_dir, 'assets/images'
require_relative 'lib/webpack/webpack_assets'
autoload :WebpackAssets, 'lib/webpack/webpack_assets'
helpers WebpackAssets
page '/*.xml', layout: false
page '/*.json', layout: false
page '/*.txt', layout: false
page '/sitemap.xml', layout: false
ignore 'assets/stylesheets/*'
ignore 'assets/javascripts/*'
ignore 'partials/*'
ignore 'rev-manifest.json'
activate :directory_indexes
# 404 page must be at root level for GitHub Pages
page '/404.html', directory_index: false
activate :deploy do |deploy|
deploy.build_before = true
deploy.deploy_method = :git
deploy.branch = 'gh-pages'
end
# rubocop:disable Metrics/BlockLength, Style/SuperArguments
helpers do
def image_url(source)
return image_path(source) unless external_site_configured?
config[:protocol] + host_with_port + image_path(source)
end
def link_to(*args, &)
return super(*args, &) unless external_site_configured?
return super(*args, &) if args.select { |arg| arg.is_a?(Hash) && arg.include?(:target) }.present?
if block_given?
args[0] = external_destination(args[0])
else
args[1] = external_destination(args[1])
end
super(*args, &)
end
def stylesheet_link_tag(destination)
return super(destination) unless external_site_configured?
super(external_destination(prep_external_destination(destination)))
end
def javascript_include_tag(destination)
return super(destination) unless external_site_configured?
super(external_destination(prep_external_destination(destination)))
end
private
def external_destination(destination)
config[:protocol] + host_with_port + destination
end
def prep_external_destination(destination)
"/#{destination}"
end
def external_site_configured?
config[:host] && config[:port] && config[:protocol]
end
def host_with_port
[config[:host], optional_port].compact.join(':')
end
def optional_port
config[:port] unless config[:port].to_i == 80
end
end
# rubocop:enable Metrics/BlockLength, Style/SuperArguments