kiln 0.1.1 → 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +84 -0
- data/README.md +9 -127
- data/lib/kiln/assets.rb +51 -20
- data/lib/kiln/build.rb +35 -42
- data/lib/kiln/build_cache.rb +4 -4
- data/lib/kiln/configuration.rb +4 -38
- data/lib/kiln/content/collection.rb +10 -10
- data/lib/kiln/content/entry.rb +29 -10
- data/lib/kiln/content/markdown.rb +22 -8
- data/lib/kiln/content.rb +26 -52
- data/lib/kiln/pages.rb +20 -14
- data/lib/kiln/processors/strip_csrf.rb +1 -1
- data/lib/kiln/railtie.rb +9 -0
- data/lib/kiln/redirects.rb +7 -43
- data/lib/kiln/report.rb +1 -1
- data/lib/kiln/sitemap.rb +6 -1
- data/lib/kiln/test_helper.rb +14 -18
- data/lib/kiln/version.rb +1 -1
- data/lib/kiln.rb +38 -3
- data/lib/tasks/kiln/build.rake +12 -2
- metadata +1 -4
- data/lib/kiln/processors/absolute_urls.rb +0 -26
- data/lib/kiln/processors/external_links.rb +0 -26
- data/lib/kiln/processors.rb +0 -22
data/lib/tasks/kiln/build.rake
CHANGED
|
@@ -1,6 +1,15 @@
|
|
|
1
1
|
namespace :kiln do
|
|
2
|
+
# Rails and gems such as turbo-rails read secret_key_base while the app boots. A build ships nothing
|
|
3
|
+
# signed, so an app without a secret of its own boots with Rails' dummy secret.
|
|
4
|
+
task :secret_key_base do
|
|
5
|
+
next unless ENV["SECRET_KEY_BASE"].to_s.empty? && ENV["RAILS_MASTER_KEY"].to_s.empty?
|
|
6
|
+
next if Dir[File.join(Dir.pwd, "config/{master.key,credentials/*.key}")].any?
|
|
7
|
+
|
|
8
|
+
ENV["SECRET_KEY_BASE_DUMMY"] ||= "1"
|
|
9
|
+
end
|
|
10
|
+
|
|
2
11
|
desc "Render every page into the output directory"
|
|
3
|
-
task build: :environment do
|
|
12
|
+
task build: [ :secret_key_base, :environment ] do
|
|
4
13
|
started = Process.clock_gettime(Process::CLOCK_MONOTONIC)
|
|
5
14
|
build = Kiln::Build.new
|
|
6
15
|
# One log line per request buries the report. Warnings and errors still show; VERBOSE=1 shows all.
|
|
@@ -13,7 +22,8 @@ namespace :kiln do
|
|
|
13
22
|
puts "Pages since last build: #{summary}"
|
|
14
23
|
changes.each { |kind, paths| paths.each { puts " #{kind}: #{it}" } }
|
|
15
24
|
end
|
|
16
|
-
|
|
25
|
+
status = report.success? ? "Output" : "Output left unchanged"
|
|
26
|
+
puts format("%s: %s (%s, %.1fs)", status, build.output, Rails.env, elapsed)
|
|
17
27
|
exit 1 if report.failure?
|
|
18
28
|
end
|
|
19
29
|
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: kiln
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.1.
|
|
4
|
+
version: 0.1.3
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- David Afonso
|
|
@@ -91,9 +91,6 @@ files:
|
|
|
91
91
|
- lib/kiln/manifest.rb
|
|
92
92
|
- lib/kiln/page.rb
|
|
93
93
|
- lib/kiln/pages.rb
|
|
94
|
-
- lib/kiln/processors.rb
|
|
95
|
-
- lib/kiln/processors/absolute_urls.rb
|
|
96
|
-
- lib/kiln/processors/external_links.rb
|
|
97
94
|
- lib/kiln/processors/strip_csrf.rb
|
|
98
95
|
- lib/kiln/processors/strip_source_maps.rb
|
|
99
96
|
- lib/kiln/railtie.rb
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
module Kiln
|
|
2
|
-
module Processors
|
|
3
|
-
# Prefixes root-relative image URLs with config.url: img src/srcset and og:/twitter: image meta tags.
|
|
4
|
-
# Feed readers and social previews need absolute URLs.
|
|
5
|
-
module AbsoluteUrls
|
|
6
|
-
IMG_TAG = /<img\b[^>]*>/
|
|
7
|
-
IMAGE_META = /<meta\b(?=[^>]*\s(?:property|name)="(?:og|twitter):image[^"]*")[^>]*>/
|
|
8
|
-
ROOT_RELATIVE = %r{\A/(?!/)}
|
|
9
|
-
|
|
10
|
-
def self.call(html, context)
|
|
11
|
-
base = context.config.url.to_s.chomp("/")
|
|
12
|
-
raise Kiln::Error, "config.url is required when absolute_urls is on" if base.empty?
|
|
13
|
-
|
|
14
|
-
html
|
|
15
|
-
.gsub(IMG_TAG) { |tag| tag.gsub(/(?<=\s)(src|srcset)="([^"]*)"/) { %(#{$1}="#{$1 == "src" ? absolute($2, base) : srcset($2, base)}") } }
|
|
16
|
-
.gsub(IMAGE_META) { |tag| tag.sub(/(?<=\s)content="([^"]*)"/) { %(content="#{absolute($1, base)}") } }
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
def self.absolute(url, base) = url.match?(ROOT_RELATIVE) ? "#{base}#{url}" : url
|
|
20
|
-
|
|
21
|
-
def self.srcset(value, base)
|
|
22
|
-
value.gsub(/(\A|,)(\s*)([^\s,]+)/) { "#{$1}#{$2}#{absolute($3, base)}" }
|
|
23
|
-
end
|
|
24
|
-
end
|
|
25
|
-
end
|
|
26
|
-
end
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
module Kiln
|
|
2
|
-
module Processors
|
|
3
|
-
# Adds target="_blank" rel="noopener" to http(s) links that point to another host.
|
|
4
|
-
module ExternalLinks
|
|
5
|
-
LINK_TAG = /<a\b[^>]*\shref="https?:[^"]*"[^>]*>/
|
|
6
|
-
|
|
7
|
-
def self.call(html, context)
|
|
8
|
-
host = context.config.host
|
|
9
|
-
html.gsub(LINK_TAG) { |tag| external?(tag, host) ? mark(tag) : tag }
|
|
10
|
-
end
|
|
11
|
-
|
|
12
|
-
def self.external?(tag, host)
|
|
13
|
-
link_host = URI(tag[/(?<=\s)href="([^"]*)"/, 1]).host
|
|
14
|
-
link_host.present? && !link_host.casecmp?(host)
|
|
15
|
-
rescue URI::InvalidURIError
|
|
16
|
-
false
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
def self.mark(tag)
|
|
20
|
-
tag = tag.sub(/(?<=\s)rel="([^"]*)"/) { $1.split.include?("noopener") ? $& : %(rel="#{$1} noopener") }
|
|
21
|
-
additions = [ (' target="_blank"' unless tag.match?(/\starget=/)), (' rel="noopener"' unless tag.match?(/\srel=/)) ]
|
|
22
|
-
tag.delete_suffix(">") + additions.join + ">"
|
|
23
|
-
end
|
|
24
|
-
end
|
|
25
|
-
end
|
|
26
|
-
end
|
data/lib/kiln/processors.rb
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
module Kiln
|
|
2
|
-
# HTML transforms applied to every rendered HTML response, in order: built-ins, then config.processors.
|
|
3
|
-
# Processors edit the HTML as a string and leave everything they don't match byte-for-byte intact.
|
|
4
|
-
module Processors
|
|
5
|
-
Context = Data.define(:path, :config, :response)
|
|
6
|
-
|
|
7
|
-
def self.apply(html, context)
|
|
8
|
-
config = context.config
|
|
9
|
-
html = StripCSRF.call(html, context)
|
|
10
|
-
html = AbsoluteUrls.call(html, context) if config.absolute_urls
|
|
11
|
-
html = ExternalLinks.call(html, context) if config.external_links
|
|
12
|
-
|
|
13
|
-
config.processors.reduce(html) do |current, processor|
|
|
14
|
-
result = processor.call(current, context)
|
|
15
|
-
unless result.is_a?(String)
|
|
16
|
-
raise Kiln::Error, "Processor #{processor.inspect} returned #{result.class} for #{context.path}, expected a String"
|
|
17
|
-
end
|
|
18
|
-
result
|
|
19
|
-
end
|
|
20
|
-
end
|
|
21
|
-
end
|
|
22
|
-
end
|