kiln 0.1.5 → 0.2.0
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 +27 -0
- data/lib/kiln/build.rb +1 -1
- data/lib/kiln/configuration.rb +0 -3
- data/lib/kiln/content/markdown.rb +3 -1
- data/lib/kiln/railtie.rb +0 -9
- data/lib/kiln/server.rb +6 -2
- data/lib/kiln/sitemap.rb +1 -6
- data/lib/kiln/static_resolver.rb +49 -12
- data/lib/kiln/verifier.rb +8 -3
- data/lib/kiln/version.rb +1 -1
- data/lib/kiln/writer.rb +9 -12
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 16e0dc4e5feadd3bf854b8bfec84c9973a97a899995aa4f28894e416672d845e
|
|
4
|
+
data.tar.gz: b1931b450833b2ca947b67aac41d9254c1ec45fe9e90d2b7b3658d3818e9f5a9
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: fe15eafda9dd8baa902fc6060326328d620dd2c2bd12fbcba337e34ba6e98e10e0454e58ddb7b7151e93e175288e4c9ba17372ae846e9b7d8d0b02f603c55369
|
|
7
|
+
data.tar.gz: 96b38b16497f0d43ca07ddd23d3fcd207d6eee5de3d90e274e31cbf1f6d7e1fa98754f621a06ebd34c857adc25e8e3108003322058cbec92006f804e911eb3ed
|
data/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,32 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.2.0 (2026-11-15)
|
|
4
|
+
|
|
5
|
+
Breaking:
|
|
6
|
+
|
|
7
|
+
- The `paths` option is removed, and every page URL has no trailing slash. `/about` is written to
|
|
8
|
+
`about.html` instead of `about/index.html`, route helpers return `/about`, and the sitemap lists
|
|
9
|
+
`/about`. Kiln no longer sets `trailing_slash` in `default_url_options`. Relative links between
|
|
10
|
+
pages resolve against the new URLs: from `/posts`, `hello` is `/hello`.
|
|
11
|
+
- An HTML response always gets `.html`, also when the last segment has a dot: `/posts/v1.2` is
|
|
12
|
+
written to `posts/v1.2.html` instead of `posts/v1.2`.
|
|
13
|
+
- `Kiln::Writer.new` no longer takes `mode:`.
|
|
14
|
+
|
|
15
|
+
Added:
|
|
16
|
+
|
|
17
|
+
- A link to a URL the host redirects, such as `/about/` or `/about.html` for `about.html`, fails the
|
|
18
|
+
build as a redirected link.
|
|
19
|
+
- `kiln:serve` redirects `/about/` and `/about.html` to `/about`, and `/docs` to `/docs/` when only
|
|
20
|
+
`docs/index.html` exists, with a 307, as Cloudflare does by default.
|
|
21
|
+
|
|
22
|
+
## 0.1.6 (2026-11-14)
|
|
23
|
+
|
|
24
|
+
Fixed:
|
|
25
|
+
|
|
26
|
+
- Markdown renders a line break inside a paragraph as a space, as CommonMark does, instead of
|
|
27
|
+
`<br>`. Commonmarker turns hardbreaks on by default, so files wrapped at a column rendered a
|
|
28
|
+
break at every wrap. Two trailing spaces or a backslash still break the line.
|
|
29
|
+
|
|
3
30
|
## 0.1.5 (2026-11-13)
|
|
4
31
|
|
|
5
32
|
Breaking:
|
data/lib/kiln/build.rb
CHANGED
data/lib/kiln/configuration.rb
CHANGED
|
@@ -4,8 +4,6 @@ module Kiln
|
|
|
4
4
|
attr_accessor :output
|
|
5
5
|
# Public base URL ("https://davafons.com"). Sets the request host and enables sitemap.xml.
|
|
6
6
|
attr_accessor :url
|
|
7
|
-
# :directory ("/now" -> now/index.html) or :file ("/now" -> now.html).
|
|
8
|
-
attr_accessor :paths
|
|
9
7
|
# Writes a CNAME file with this domain when set. true takes the host from `url`.
|
|
10
8
|
attr_accessor :cname
|
|
11
9
|
# Path rendered to 404.html (expected to respond with 404 or 200), nil to skip.
|
|
@@ -19,7 +17,6 @@ module Kiln
|
|
|
19
17
|
def initialize
|
|
20
18
|
@output = "dist"
|
|
21
19
|
@url = nil
|
|
22
|
-
@paths = :directory
|
|
23
20
|
@cname = nil
|
|
24
21
|
@not_found = nil
|
|
25
22
|
@verify_skip = []
|
|
@@ -2,7 +2,9 @@ module Kiln
|
|
|
2
2
|
module Content
|
|
3
3
|
module Markdown
|
|
4
4
|
OPTIONS = {
|
|
5
|
-
|
|
5
|
+
# Commonmarker turns hardbreaks on by default. Off, a line break inside a paragraph is a
|
|
6
|
+
# space, as CommonMark says, so files wrapped at a column read as whole paragraphs.
|
|
7
|
+
render: { unsafe: true, hardbreaks: false },
|
|
6
8
|
extension: { table: true, strikethrough: true, autolink: true, header_ids: "" }
|
|
7
9
|
}.freeze
|
|
8
10
|
PLUGINS = { syntax_highlighter: nil }.freeze
|
data/lib/kiln/railtie.rb
CHANGED
|
@@ -15,15 +15,6 @@ module Kiln
|
|
|
15
15
|
hosts << Kiln.config.host if hosts.any? && !hosts.include?(Kiln.config.host)
|
|
16
16
|
end
|
|
17
17
|
|
|
18
|
-
# In :directory mode "/now" is written as now/index.html, which static hosts serve at "/now/" and
|
|
19
|
-
# reach from "/now" with a redirect. Route helpers add the trailing slash so links point at the
|
|
20
|
-
# served URL. Paths with a dot (feed.xml) are left alone, and an app that sets trailing_slash in
|
|
21
|
-
# default_url_options keeps its own value.
|
|
22
|
-
config.after_initialize do |app|
|
|
23
|
-
options = app.routes.default_url_options
|
|
24
|
-
options[:trailing_slash] = true if Kiln.config.paths == :directory && !options.key?(:trailing_slash)
|
|
25
|
-
end
|
|
26
|
-
|
|
27
18
|
rake_tasks do
|
|
28
19
|
Dir[File.expand_path("../tasks/kiln/*.rake", __dir__)].sort.each { load it }
|
|
29
20
|
end
|
data/lib/kiln/server.rb
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
require "rack/mime"
|
|
2
2
|
|
|
3
3
|
module Kiln
|
|
4
|
-
# Rack app that serves the built output the way
|
|
4
|
+
# Rack app that serves the built output the way Cloudflare does: _redirects rules, then files, then
|
|
5
|
+
# 307 redirects to the URL a page is served at, then 404.html.
|
|
5
6
|
class Server
|
|
6
7
|
def self.start(root, port:, host: "localhost")
|
|
7
8
|
require "rackup"
|
|
@@ -21,7 +22,10 @@ module Kiln
|
|
|
21
22
|
[ redirect.status, { "location" => redirect.to }, [] ]
|
|
22
23
|
elsif (file = @resolver.resolve(path))
|
|
23
24
|
serve(200, file)
|
|
24
|
-
elsif (
|
|
25
|
+
elsif (location = @resolver.redirect(path))
|
|
26
|
+
query = env["QUERY_STRING"].presence
|
|
27
|
+
[ 307, { "location" => query ? "#{location}?#{query}" : location }, [] ]
|
|
28
|
+
elsif (not_found = @resolver.resolve("/404"))
|
|
25
29
|
serve(404, not_found)
|
|
26
30
|
else
|
|
27
31
|
[ 404, { "content-type" => "text/plain" }, [ "Not found\n" ] ]
|
data/lib/kiln/sitemap.rb
CHANGED
|
@@ -25,7 +25,7 @@ module Kiln
|
|
|
25
25
|
urls = @manifest.entries.filter_map do |path, entry|
|
|
26
26
|
next if entry[:noindex] || entry[:content_type] != "text/html"
|
|
27
27
|
|
|
28
|
-
" <url><loc>#{ERB::Util.html_escape(@url +
|
|
28
|
+
" <url><loc>#{ERB::Util.html_escape(@url + path)}</loc></url>\n"
|
|
29
29
|
end
|
|
30
30
|
|
|
31
31
|
writer.write_file(FILENAME, <<~XML)
|
|
@@ -34,10 +34,5 @@ module Kiln
|
|
|
34
34
|
#{urls.join}</urlset>
|
|
35
35
|
XML
|
|
36
36
|
end
|
|
37
|
-
|
|
38
|
-
private
|
|
39
|
-
def served_path(path, file)
|
|
40
|
-
File.basename(file.to_s) == "index.html" ? "/#{file.to_s.delete_suffix("index.html")}" : path
|
|
41
|
-
end
|
|
42
37
|
end
|
|
43
38
|
end
|
data/lib/kiln/static_resolver.rb
CHANGED
|
@@ -1,28 +1,65 @@
|
|
|
1
1
|
module Kiln
|
|
2
|
-
# Maps a URL path to a file the way Cloudflare
|
|
3
|
-
#
|
|
2
|
+
# Maps a URL path to a file the way Cloudflare static assets do by default (auto-trailing-slash).
|
|
3
|
+
# "/x" serves the file x or x.html, and "/x/" serves x/index.html. The other spellings of a page
|
|
4
|
+
# redirect to the URL it is served at: "/x/" and "/x.html" to "/x", "/x/index.html" and "/x" to
|
|
5
|
+
# "/x/" when only x/index.html exists. Never returns a file outside root.
|
|
4
6
|
class StaticResolver
|
|
5
7
|
def initialize(root)
|
|
6
8
|
@root = Pathname(root).expand_path
|
|
7
9
|
end
|
|
8
10
|
|
|
11
|
+
# The file served at the path, or nil.
|
|
9
12
|
def resolve(url_path)
|
|
10
|
-
|
|
11
|
-
return
|
|
13
|
+
segments, slash = parse(url_path)
|
|
14
|
+
return unless segments
|
|
12
15
|
|
|
13
|
-
|
|
14
|
-
|
|
16
|
+
base = @root.join(*segments)
|
|
17
|
+
|
|
18
|
+
candidates =
|
|
19
|
+
if segments.empty? || slash then [ base.join("index.html") ]
|
|
20
|
+
elsif segments.last.end_with?(".html") then []
|
|
21
|
+
else [ base, Pathname("#{base}.html") ]
|
|
22
|
+
end
|
|
23
|
+
candidates.find { servable?(it) }
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
# The URL the path redirects to, or nil. Only meaningful when resolve returns nil.
|
|
27
|
+
def redirect(url_path)
|
|
28
|
+
segments, slash = parse(url_path)
|
|
29
|
+
return if segments.nil? || segments.empty?
|
|
15
30
|
|
|
16
31
|
base = @root.join(*segments)
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
32
|
+
*parents, name = segments
|
|
33
|
+
target =
|
|
34
|
+
if slash
|
|
35
|
+
segments if servable?(Pathname("#{base}.html"))
|
|
36
|
+
elsif name == "index.html"
|
|
37
|
+
[ *parents, "" ] if servable?(base)
|
|
38
|
+
elsif name.end_with?(".html") && name != ".html"
|
|
39
|
+
[ *parents, name.delete_suffix(".html") ] if servable?(base)
|
|
40
|
+
else
|
|
41
|
+
[ *segments, "" ] if servable?(base.join("index.html"))
|
|
42
|
+
end
|
|
43
|
+
"/#{target.map { Rack::Utils.escape_path(it) }.join("/")}" if target
|
|
21
44
|
end
|
|
22
45
|
|
|
23
46
|
private
|
|
24
|
-
|
|
25
|
-
|
|
47
|
+
# The decoded segments and whether the path ends in a slash, or nil for a path that can't name
|
|
48
|
+
# a file under root.
|
|
49
|
+
def parse(url_path)
|
|
50
|
+
path = Rack::Utils.unescape_path(url_path.to_s.split(/[?#]/, 2).first.to_s)
|
|
51
|
+
return if path.include?("\0")
|
|
52
|
+
|
|
53
|
+
segments = path.split("/").reject { it.empty? || it == "." }
|
|
54
|
+
[ segments, path.end_with?("/") ] unless segments.include?("..")
|
|
55
|
+
rescue ArgumentError, Encoding::CompatibilityError
|
|
56
|
+
nil
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
def servable?(file)
|
|
60
|
+
file.file? && file.realpath.to_s.start_with?("#{@root.realpath}/")
|
|
61
|
+
rescue ArgumentError, Encoding::CompatibilityError
|
|
62
|
+
false
|
|
26
63
|
end
|
|
27
64
|
end
|
|
28
65
|
end
|
data/lib/kiln/verifier.rb
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
module Kiln
|
|
2
|
-
# Checks the built output: internal links, anchors and importmap modules.
|
|
2
|
+
# Checks the built output: internal links, anchors and importmap modules. A link to a URL the host
|
|
3
|
+
# answers with a redirect, such as "/about/" for about.html, is an error: links use the served URL.
|
|
3
4
|
class Verifier
|
|
4
5
|
def initialize(output, config:)
|
|
5
6
|
@output = Pathname(output)
|
|
@@ -34,7 +35,11 @@ module Kiln
|
|
|
34
35
|
target = @resolver.resolve(uri.path)
|
|
35
36
|
|
|
36
37
|
if target.nil?
|
|
37
|
-
|
|
38
|
+
if (location = @resolver.redirect(uri.path))
|
|
39
|
+
error(:redirected_link, "#{url} (served at #{location})", page)
|
|
40
|
+
elsif !@redirect_sources.include?(uri.path)
|
|
41
|
+
error(:broken_link, url, page)
|
|
42
|
+
end
|
|
38
43
|
elsif uri.fragment.present? && uri.fragment != "top" && target.extname == ".html"
|
|
39
44
|
fragment = Rack::Utils.unescape_path(uri.fragment)
|
|
40
45
|
error(:missing_anchor, url, page) unless anchors(target).include?(fragment)
|
|
@@ -71,7 +76,7 @@ module Kiln
|
|
|
71
76
|
Nokogiri::HTML5(file.read)
|
|
72
77
|
end
|
|
73
78
|
|
|
74
|
-
# The URL a file is served at: index.html -> /,
|
|
79
|
+
# The URL a file is served at: index.html -> /, docs/index.html -> /docs/, now.html -> /now.
|
|
75
80
|
def page_path(file)
|
|
76
81
|
path = "/#{file}"
|
|
77
82
|
return path.delete_suffix("index.html") if File.basename(file) == "index.html"
|
data/lib/kiln/version.rb
CHANGED
data/lib/kiln/writer.rb
CHANGED
|
@@ -6,29 +6,26 @@ module Kiln
|
|
|
6
6
|
class Writer
|
|
7
7
|
attr_reader :output
|
|
8
8
|
|
|
9
|
-
def initialize(output,
|
|
10
|
-
raise Kiln::Error, "Unknown paths mode #{mode.inspect} (expected :directory or :file)" unless %i[directory file].include?(mode)
|
|
11
|
-
|
|
9
|
+
def initialize(output, report:)
|
|
12
10
|
@output = Pathname(output).expand_path
|
|
13
|
-
@mode = mode
|
|
14
11
|
@report = report
|
|
15
12
|
end
|
|
16
13
|
|
|
17
|
-
# Relative file for a request path
|
|
14
|
+
# Relative file for a request path. "/" is index.html. An HTML response is written with .html
|
|
15
|
+
# unless its path already ends in .html: "/now" -> "now.html", "/posts/v1.2" -> "posts/v1.2.html".
|
|
16
|
+
# Other responses keep their extension, or get one from the MIME type: "/api/status" -> "api/status.json".
|
|
18
17
|
def file_for(path, content_type)
|
|
19
18
|
segments = segments_for(path)
|
|
20
19
|
content_type = content_type.to_s.split(";").first.to_s.strip.downcase
|
|
21
20
|
return "index.html" if segments.empty?
|
|
22
21
|
|
|
23
22
|
name = segments.last
|
|
24
|
-
if
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
segments = [ *segments[...-1], "#{name}.#{extension}" ]
|
|
29
|
-
end
|
|
23
|
+
if content_type == "text/html"
|
|
24
|
+
name = "#{name}.html" unless name.end_with?(".html")
|
|
25
|
+
elsif File.extname(name).empty? && (extension = extension_for(content_type))
|
|
26
|
+
name = "#{name}.#{extension}"
|
|
30
27
|
end
|
|
31
|
-
segments.join("/")
|
|
28
|
+
[ *segments[...-1], name ].join("/")
|
|
32
29
|
end
|
|
33
30
|
|
|
34
31
|
def write(path, content_type, body)
|