kiln 0.1.0 → 0.1.2
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 +65 -0
- data/LICENSE +1 -1
- data/README.md +127 -102
- data/lib/kiln/assets.rb +73 -24
- data/lib/kiln/build.rb +73 -33
- data/lib/kiln/build_cache.rb +4 -4
- data/lib/kiln/configuration.rb +11 -38
- data/lib/kiln/content/collection.rb +10 -10
- data/lib/kiln/content/entry.rb +36 -10
- data/lib/kiln/content/handlers.rb +8 -3
- data/lib/kiln/content/markdown.rb +52 -9
- data/lib/kiln/content.rb +24 -12
- data/lib/kiln/pages.rb +15 -1
- data/lib/kiln/processors/strip_csrf.rb +1 -1
- data/lib/kiln/redirects.rb +7 -43
- data/lib/kiln/report.rb +1 -1
- data/lib/kiln/router.rb +0 -14
- data/lib/kiln/server.rb +2 -2
- data/lib/kiln/test_helper.rb +14 -18
- data/lib/kiln/verifier.rb +4 -0
- data/lib/kiln/version.rb +1 -1
- data/lib/tasks/kiln/build.rake +0 -14
- data/lib/tasks/kiln/serve.rake +4 -3
- metadata +1 -7
- data/lib/kiln/check.rb +0 -22
- 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/routes.rake +0 -12
- data/lib/tasks/kiln/verify.rake +0 -15
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 2108cdc748f14c10c06ab2edbf346622c13887cac5ec16bc2fe6823dfb3d4b53
|
|
4
|
+
data.tar.gz: f5aabfc64b54bd944d8d2bb3de6a57d980204e4f4070dd23f3340376980b8326
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 6ec17dee2f07143628dbd3892c50ee258bde2aa1a2e0c4e5306b7ecd9d30856e2d0df0d50b78da273f658b7d0607e3ec4a4bd00fc5f8834c4aa7002e7938d814
|
|
7
|
+
data.tar.gz: 9eafdc861711a6f733e9bc376a6c4f0c3519c104451fbaed5140c37642ea0d21edd6649793309ec64fb02e26b8b60ec8892398b5e0bc20f7e2c21a725940a943
|
data/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,70 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.1.2 (2026-11-07)
|
|
4
|
+
|
|
5
|
+
Breaking:
|
|
6
|
+
|
|
7
|
+
- `Kiln.build_cache.fetch` caches only while `Kiln.building?`. Outside a build it runs the block
|
|
8
|
+
every time. `read`, `write` and `delete` are removed.
|
|
9
|
+
- `assert_repeatable_build` is removed. Use `kiln_build(repeatable: true) { |output| ... }`.
|
|
10
|
+
- In collections, `SLUG.LOCALE.md` (such as `2026-08.es.md`) is a translation of `SLUG.md` instead
|
|
11
|
+
of its own entry. Translations stay out of `all`, `find` and `each`, and a translation without
|
|
12
|
+
its entry fails when the collection loads.
|
|
13
|
+
- A collection filename that is only a date, such as `2026-08-01.md`, now sets `published_at`.
|
|
14
|
+
- Removed options: `config.verify` (every build verifies), `config.absolute_urls`,
|
|
15
|
+
`config.external_links`, `config.processors`, `config.before_build`, `config.after_build`,
|
|
16
|
+
`config.strip_source_maps` (source maps are always stripped), `config.sitemap` (written whenever
|
|
17
|
+
`url` is set), `config.host=` (the host comes from `url`, else `localhost`), `config.assets`
|
|
18
|
+
(only referenced assets are exported), `config.redirects` (always `_redirects`; the
|
|
19
|
+
`:meta_refresh`, `:both` and `false` modes are gone) and `config.copy_public` (`public/` is always
|
|
20
|
+
copied).
|
|
21
|
+
- Removed `Kiln::Processors.apply`, `Kiln::Processors::Context`, `Kiln::Build::Context`, and the
|
|
22
|
+
`AbsoluteUrls` and `ExternalLinks` processors.
|
|
23
|
+
- The content layer drops preview tokens: `Collection#find` takes only a slug, and
|
|
24
|
+
`Entry#preview_token` and `Kiln::Content.preview_secret` are removed. Drafts and scheduled
|
|
25
|
+
entries still show in development when Kiln is not building.
|
|
26
|
+
|
|
27
|
+
Added:
|
|
28
|
+
|
|
29
|
+
- `params :page, locale: [ nil, "es", "ja" ]` builds every combination of value lists. `nil`
|
|
30
|
+
leaves the key out, for optional segments. A list may be a lambda, called at build time.
|
|
31
|
+
- `kiln_build(repeatable: true)` builds twice, fails with the diff when the outputs differ, and
|
|
32
|
+
yields the first output.
|
|
33
|
+
- `entry.translation(:es)` and `entry.locale` in the content layer.
|
|
34
|
+
- Collection filenames may start with a `YYYY-MM` date, which means the 1st of that month.
|
|
35
|
+
- `Kiln::Content::Markdown.render_inline(text)` renders a single paragraph without its `<p>`.
|
|
36
|
+
- `config.cname = true` writes `CNAME` with the host from `config.url`.
|
|
37
|
+
|
|
38
|
+
Fixed:
|
|
39
|
+
|
|
40
|
+
- A production build precompiles assets into a temporary directory instead of `public/assets`, so
|
|
41
|
+
a development server that boots during the build no longer loads the production manifest.
|
|
42
|
+
Compiled assets are exported from that directory, and the build no longer needs
|
|
43
|
+
`config.public_file_server.enabled`.
|
|
44
|
+
- When `app/assets/builds` is created after boot (a fresh checkout without
|
|
45
|
+
`app/assets/builds/.keep`), the build stops with one error that says to track the `.keep` file,
|
|
46
|
+
instead of one missing-asset error per page.
|
|
47
|
+
|
|
48
|
+
## 0.1.1 (2026-11-07)
|
|
49
|
+
|
|
50
|
+
- Kiln has two tasks, `kiln:build` and `kiln:serve`. `kiln:verify`, `kiln:routes` and `kiln:check` are removed: every build verifies and reports uncovered routes, and committed output can be checked with `git status --porcelain` after a build.
|
|
51
|
+
- `config.verify_skip`: CSS selectors for sample markup (component demos, previews) whose links the
|
|
52
|
+
verifier ignores.
|
|
53
|
+
- `kiln:serve` takes `BIND` (default localhost), for process managers that expect 127.0.0.1.
|
|
54
|
+
- `config.files` copies files that aren't routes (licenses, verification files) into the output.
|
|
55
|
+
- Development builds run the bundle builds hooked into `assets:precompile` (`tailwindcss:build`,
|
|
56
|
+
`javascript:build`, `css:build`) instead of shipping stale bundles.
|
|
57
|
+
- The build fails when development middleware that injects markup (Hotwire Spark, web-console,
|
|
58
|
+
rack-mini-profiler) is active.
|
|
59
|
+
- The manifest moved from the output to `tmp/kiln-manifest.json`, so it is no longer published.
|
|
60
|
+
- LICENSE names the copyright holder.
|
|
61
|
+
- A production build of an app without `secret_key_base` uses a throwaway secret instead of failing.
|
|
62
|
+
- The build fails when `data-herb-*` or `data-tensaku-*` editor attributes reach the output.
|
|
63
|
+
- The content layer renders Markdown with commonmarker instead of Redcarpet: replace `gem "redcarpet"`
|
|
64
|
+
with `gem "commonmarker"`. The HTML changes, for example lists directly under a paragraph become lists and `^` is no longer superscript. Headings keep a plain `id`.
|
|
65
|
+
- `Kiln::Content.source_positions` marks rendered Markdown blocks with `data-tensaku-md` source
|
|
66
|
+
positions. On by default only in development with Tensaku loaded, never while building.
|
|
67
|
+
|
|
3
68
|
## 0.1.0 (2026-11-07)
|
|
4
69
|
|
|
5
70
|
- First release.
|
data/LICENSE
CHANGED
data/README.md
CHANGED
|
@@ -1,27 +1,26 @@
|
|
|
1
|
-
|
|
1
|
+
<h1 align="center">Kiln</h1>
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
<p align="center">
|
|
4
|
+
<a href="https://rubygems.org/gems/kiln"><img src="https://img.shields.io/gem/v/kiln?color=b45d3c" alt="Gem version"></a>
|
|
5
|
+
<img src="https://img.shields.io/badge/ruby-4.0%2B-cc342d?logo=ruby&logoColor=white" alt="Ruby 4.0+">
|
|
6
|
+
<img src="https://img.shields.io/badge/rails-8.1%2B-d30001?logo=rubyonrails&logoColor=white" alt="Rails 8.1+">
|
|
7
|
+
<a href="https://github.com/davafons/kiln/actions/workflows/ci.yml"><img src="https://github.com/davafons/kiln/actions/workflows/ci.yml/badge.svg" alt="CI"></a>
|
|
8
|
+
</p>
|
|
5
9
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
Kiln renders every GET route through Rack, the same way a browser request goes through your app,
|
|
11
|
-
and writes plain files to `dist/` that any static host can serve.
|
|
10
|
+
<p align="center">
|
|
11
|
+
Fire a Rails app into a static site.
|
|
12
|
+
</p>
|
|
12
13
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
- **Kiln knows nothing about your data.** Models and repositories stay ordinary app code.
|
|
14
|
+
<p align="center">
|
|
15
|
+
<a href="#configuration">Configuration</a> ·
|
|
16
|
+
<a href="CHANGELOG.md">Changelog</a>
|
|
17
|
+
</p>
|
|
18
18
|
|
|
19
|
-
|
|
19
|
+
Kiln renders every GET route of a Rails app through Rack and writes plain files that any static host can serve. You build pages with normal Rails: routes, controllers, views, helpers, Turbo and Stimulus. Development stays `bin/rails server`.
|
|
20
20
|
|
|
21
|
-
|
|
22
|
-
to RubyGems through trusted publishing.
|
|
21
|
+
Routes are the page list. A route that needs params and has no param source fails the build, and every render error, missing asset and broken link is reported at once. Kiln knows nothing about your data: models and repositories stay ordinary app code.
|
|
23
22
|
|
|
24
|
-
##
|
|
23
|
+
## Build a site
|
|
25
24
|
|
|
26
25
|
```ruby
|
|
27
26
|
# Gemfile
|
|
@@ -31,134 +30,160 @@ gem "kiln"
|
|
|
31
30
|
```ruby
|
|
32
31
|
# config/kiln.rb
|
|
33
32
|
Kiln.configure do |config|
|
|
34
|
-
config.url = "https://example.com"
|
|
35
|
-
config.not_found = "/404"
|
|
33
|
+
config.url = "https://example.com"
|
|
34
|
+
config.not_found = "/404"
|
|
36
35
|
end
|
|
37
36
|
|
|
38
37
|
Kiln.pages do
|
|
39
38
|
params :post, -> { Post.published.map { { slug: it.slug } } }
|
|
40
|
-
params :page, -> { %w[en es ja].map { { locale: it } } + [ {} ] } # scope "(:locale)"
|
|
41
|
-
paginate :blog_page, per: 10, total: -> { Post.count }, start: 2 # /blog/page/2 ...
|
|
42
39
|
skip :search, reason: "dynamic"
|
|
43
40
|
end
|
|
44
41
|
```
|
|
45
42
|
|
|
46
|
-
|
|
43
|
+
```sh
|
|
44
|
+
RAILS_ENV=production bin/rails kiln:build
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
The site lands in `dist/`. Kiln precompiles assets in-process, renders each page, exports the assets the pages reference, copies `public/`, and writes `_redirects`, `sitemap.xml` and `404.html`. Then it checks every internal link, anchor and importmap module, and exits non-zero on any problem.
|
|
47
48
|
|
|
48
|
-
|
|
49
|
-
routes are skipped by default. Redirect routes become redirects, and mounted Rack apps are built
|
|
50
|
-
like any other route.
|
|
49
|
+
## Declare the pages
|
|
51
50
|
|
|
52
|
-
|
|
51
|
+
A GET route with no required params is built automatically. A route with params needs a param source:
|
|
52
|
+
|
|
53
|
+
```ruby
|
|
54
|
+
Kiln.pages do
|
|
55
|
+
params :post, -> { Post.published.map { { slug: it.slug } } }
|
|
56
|
+
params :page, locale: [ nil, "es", "ja" ] # scope "(:locale)"
|
|
57
|
+
params :archive, year: -> { Post.years }, locale: [ nil, "es" ] # every combination
|
|
58
|
+
paginate :blog_page, per: 10, total: -> { Post.count }, start: 2 # /blog/page/2, /blog/page/3, ...
|
|
59
|
+
skip :search, reason: "dynamic"
|
|
60
|
+
end
|
|
61
|
+
```
|
|
53
62
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
63
|
+
A hash of value lists builds every combination of the values. A `nil` value leaves the key out, which fills an optional segment such as `(:locale)` with nothing. A list may be a lambda, called at build time.
|
|
64
|
+
|
|
65
|
+
A route that needs params and has neither a param source nor a skip fails the build, and the error names the line to add. Rails internals, the health check, mounted engines and turbo-rails' native navigation routes are skipped by default. Redirect routes become redirects, and mounted Rack apps are built like any other route.
|
|
66
|
+
|
|
67
|
+
Feeds, `robots.txt`, `llms.txt` and JSON files are ordinary routes with views. The content type picks the extension, so `get "api"` rendering JSON is written as `api.json`.
|
|
68
|
+
|
|
69
|
+
## Develop and ship
|
|
70
|
+
|
|
71
|
+
Develop with `bin/rails server` and whatever reloading the app already has, such as Hotwire Spark. Kiln adds no dev server. It has two commands:
|
|
72
|
+
|
|
73
|
+
```sh
|
|
74
|
+
RAILS_ENV=production bin/rails kiln:build # write the site; CI and deploys run this
|
|
75
|
+
bin/rails kiln:serve # look at the output as a static host serves it
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
`kiln:build` verifies every internal link, anchor and importmap module, and lists the pages that changed since the previous build. Set `VERBOSE=1` to see request logs. A repository that commits its output can check it in CI: run `kiln:build`, then fail if `git status --porcelain docs` prints anything.
|
|
79
|
+
|
|
80
|
+
`kiln:serve` uses Cloudflare Pages and GitHub Pages path resolution and applies `_redirects`. It reads `PORT` (default 4000) and `BIND` (default localhost).
|
|
61
81
|
|
|
62
82
|
## Configuration
|
|
63
83
|
|
|
64
84
|
| Option | Default | |
|
|
65
85
|
|---|---|---|
|
|
66
86
|
| `output` | `"dist"` | Relative to `Rails.root`, or absolute. Wiped at the start of every build. |
|
|
67
|
-
| `url` | `nil` | Public base URL.
|
|
68
|
-
| `
|
|
69
|
-
| `
|
|
70
|
-
| `assets` | `:referenced` | Only assets the output references (HTML, importmap, CSS `url()`). `:all` exports everything. |
|
|
71
|
-
| `cname` | `nil` | Writes a `CNAME` file. |
|
|
87
|
+
| `url` | `nil` | Public base URL. Its host is sent with every request (`localhost` without it), and `sitemap.xml` is written only when it is set. |
|
|
88
|
+
| `paths` | `:directory` | `/now` becomes `now/index.html`. `:file` writes `now.html`. |
|
|
89
|
+
| `cname` | `nil` | Writes a `CNAME` file with this host. `true` takes the host from `url`. |
|
|
72
90
|
| `not_found` | `nil` | Path rendered to `404.html`. It may respond with 200 or 404. |
|
|
73
|
-
| `
|
|
74
|
-
| `
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
91
|
+
| `files` | `{}` | Files that aren't routes: `{ "octicons-license.txt" => "vendor/octicons/LICENSE" }`. |
|
|
92
|
+
| `verify_skip` | `[]` | CSS selectors for sample markup whose links aren't checked, such as `"[data-example-preview]"`. |
|
|
93
|
+
|
|
94
|
+
Every build exports the assets the output references (HTML, importmap, CSS `url()`), removes `sourceMappingURL` comments from JS and CSS, copies `public/` (minus `public/assets`), writes `_redirects` when a route redirects, and runs the verifier. The sitemap leaves out pages marked `noindex`.
|
|
95
|
+
|
|
96
|
+
CSRF tokens and meta tags are always stripped. The rest of the HTML stays byte for byte as the app rendered it.
|
|
97
|
+
|
|
98
|
+
## Write views for a build
|
|
99
|
+
|
|
100
|
+
- `Kiln.building?` is true while a build renders pages. Use it to hide development-only markup.
|
|
101
|
+
- `Kiln.build_cache.fetch(key) { ... }` memoizes for one build and is cleared before and after it. Outside a build it runs the block every time, so a development server never serves stale data.
|
|
102
|
+
- A production build precompiles assets into a temporary directory and exports them from there. `public/assets` is left alone, so a development server of the same app can run at the same time.
|
|
103
|
+
- Propshaft only serves asset folders that exist when the app boots. Track `app/assets/builds/.keep`, as a new Rails app does, or the build stops with an error on a fresh checkout.
|
|
104
|
+
- A build in development skips the precompile but still runs the steps hooked into `assets:precompile`, such as `tailwindcss:build`.
|
|
105
|
+
- Development middleware that injects markup (Hotwire Spark, web-console, rack-mini-profiler) fails the build. Load it only under `bin/rails server`.
|
|
106
|
+
- Root-absolute asset paths keep every page's `<head>` identical, so Turbo visits never force a full reload.
|
|
107
|
+
|
|
108
|
+
## Write in Markdown
|
|
81
109
|
|
|
82
|
-
|
|
110
|
+
The content layer is optional and works in server-rendered apps too. It needs commonmarker and Rouge:
|
|
83
111
|
|
|
84
112
|
```ruby
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
113
|
+
# Gemfile
|
|
114
|
+
gem "commonmarker"
|
|
115
|
+
gem "rouge"
|
|
116
|
+
|
|
117
|
+
# config/application.rb, after Bundler.require
|
|
118
|
+
require "kiln/content"
|
|
89
119
|
```
|
|
90
120
|
|
|
91
|
-
|
|
92
|
-
the app rendered it.
|
|
121
|
+
`app/views/pages/about.html.md` renders through the layout like any view, and `.md.erb` runs ERB first. commonmarker renders GitHub Flavored Markdown with tables, strikethrough, autolinks and heading ids; raw HTML passes through. Code blocks get Rouge CSS classes.
|
|
93
122
|
|
|
94
|
-
|
|
123
|
+
`Kiln::Content::Markdown.render(text)` returns HTML. `Kiln::Content::Markdown.render_inline(text)` drops the `<p>` around text that is a single paragraph, for titles and captions; other text renders as with `render`.
|
|
95
124
|
|
|
96
|
-
|
|
97
|
-
- `Kiln.build_cache.fetch(key) { ... }` memoizes for one build and is cleared before and after.
|
|
98
|
-
- Builds run in production. Kiln runs `assets:precompile` in-process when needed and removes
|
|
99
|
-
`public/assets` afterwards. Assets are fetched through the app, so keep
|
|
100
|
-
`config.public_file_server.enabled = true` for builds.
|
|
101
|
-
- Use root-absolute asset paths so every page's `<head>` stays identical and Turbo visits never
|
|
102
|
-
force a full reload.
|
|
103
|
-
- Feeds, `robots.txt`, `llms.txt` or JSON files are ordinary routes with views
|
|
104
|
-
(`get "feed.xml"`). The file is written under the route's path.
|
|
125
|
+
With `Kiln::Content.source_positions` on, each rendered block of a `.md` view or collection entry carries `data-tensaku-md="path:startLine:startCol-endLine:endCol"` for the Tensaku editor. The format is a draft. `.md.erb` views get none, because ERB shifts the line numbers. The setting defaults to on in development when Tensaku is loaded, and is always off while Kiln is building.
|
|
105
126
|
|
|
106
|
-
|
|
127
|
+
Collections read Markdown files with YAML frontmatter, such as `content/blog/2024-05-01-hello.md`:
|
|
107
128
|
|
|
108
129
|
```ruby
|
|
109
|
-
|
|
130
|
+
posts = Kiln::Content.collection("blog")
|
|
131
|
+
posts.all # visible entries, newest first
|
|
132
|
+
posts.find("hello") # raises Kiln::Content::NotFound, which Rails maps to a 404
|
|
133
|
+
post.title, post.published_at, post.html, post[:tags]
|
|
134
|
+
```
|
|
110
135
|
|
|
111
|
-
|
|
112
|
-
include Kiln::TestHelper
|
|
136
|
+
A filename date may be `YYYY-MM-DD` or `YYYY-MM`. A month-only date sets `published_at` to the 1st of that month, and a filename that is only a date, such as `2026-08.md`, keeps the date as its slug.
|
|
113
137
|
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
138
|
+
`SLUG.LOCALE.md` is a translation of the entry with that slug, such as `2026-08.es.md` for `2026-08.md`. A locale is two lowercase letters, optionally followed by a dash and two uppercase letters (`es`, `pt-BR`). Translations stay out of `all`, `find` and `each`:
|
|
139
|
+
|
|
140
|
+
```ruby
|
|
141
|
+
post.locale # nil for SLUG.md, "es" for SLUG.es.md
|
|
142
|
+
post.translation(:es) # the visible SLUG.es.md entry, or nil
|
|
117
143
|
```
|
|
118
144
|
|
|
119
|
-
|
|
120
|
-
yields the output path.
|
|
145
|
+
A translation whose entry does not exist fails when the collection loads.
|
|
121
146
|
|
|
122
|
-
|
|
147
|
+
Entries with `draft: true` or a future `published_at` are hidden, except in development when Kiln is not building.
|
|
123
148
|
|
|
124
|
-
|
|
149
|
+
## Test the build
|
|
125
150
|
|
|
126
151
|
```ruby
|
|
127
|
-
|
|
128
|
-
gem "redcarpet"
|
|
129
|
-
gem "rouge"
|
|
152
|
+
require "kiln/test_helper"
|
|
130
153
|
|
|
131
|
-
|
|
132
|
-
|
|
154
|
+
class StaticSiteTest < ActiveSupport::TestCase
|
|
155
|
+
include Kiln::TestHelper
|
|
156
|
+
|
|
157
|
+
test "the site builds repeatably" do
|
|
158
|
+
kiln_build(repeatable: true) { |output| assert output.join("index.html").file? }
|
|
159
|
+
end
|
|
160
|
+
|
|
161
|
+
test("home page") { assert_page "/", selector: "h1", text: "Welcome" }
|
|
162
|
+
end
|
|
133
163
|
```
|
|
134
164
|
|
|
135
|
-
|
|
136
|
-
`.md.erb` runs ERB first. Code blocks get Rouge CSS classes (`rougify style github`).
|
|
137
|
-
- **Collections:** `content/blog/2024-05-01-hello.md` with YAML frontmatter.
|
|
165
|
+
`kiln_build { |output| ... }` builds into a temp dir, fails with the report on any error, and yields the output path. With `repeatable: true` it builds twice, fails with the list of differing files when the outputs differ, and yields the first output.
|
|
138
166
|
|
|
139
|
-
|
|
140
|
-
posts = Kiln::Content.collection("blog")
|
|
141
|
-
posts.all # visible entries, newest first
|
|
142
|
-
posts.find("hello") # raises Kiln::Content::NotFound (a 404)
|
|
143
|
-
post.title, post.published_at, post.html, post[:tags]
|
|
167
|
+
## Known limits
|
|
144
168
|
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
169
|
+
- Pages render one at a time.
|
|
170
|
+
- Redirects are written only as `_redirects`, which Cloudflare Pages and Netlify read. GitHub Pages ignores the file, so redirect routes do not redirect there.
|
|
171
|
+
- Wildcard rules in your own `public/_redirects` are written out, but the verifier and `kiln:serve` only follow exact rules.
|
|
172
|
+
- JS modules are found through the importmap. Relative `import "./x.js"` between files is not followed.
|
|
173
|
+
- Collections read `*.md` files. `.md.erb` works for views only.
|
|
148
174
|
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
175
|
+
## Develop Kiln
|
|
176
|
+
|
|
177
|
+
```sh
|
|
178
|
+
bundle install
|
|
179
|
+
bin/test
|
|
180
|
+
bin/lint # RuboCop and bin/house-rules
|
|
181
|
+
```
|
|
152
182
|
|
|
153
|
-
|
|
183
|
+
`test/dummy` is the Rails app the tests build. `bin/house-rules` rejects em dashes, AI attribution, leftover tool-call markup, filler phrases and dead links in Markdown. [AGENTS.md](AGENTS.md) holds the rules a script cannot check.
|
|
154
184
|
|
|
155
|
-
|
|
156
|
-
- Only exact `_redirects` rules count for the verifier and `kiln:serve`. Splat and placeholder
|
|
157
|
-
rules in your own `public/_redirects` are written out but not followed.
|
|
158
|
-
- JS modules are found through the importmap. Relative `import "./x.js"` between files is not
|
|
159
|
-
followed.
|
|
160
|
-
- Collections read `*.md` files only (`.md.erb` works for views).
|
|
185
|
+
Releases publish from a `vX.Y.Z` tag that matches `Kiln::VERSION`. CI runs first, then the release workflow publishes to RubyGems through trusted publishing.
|
|
161
186
|
|
|
162
187
|
## License
|
|
163
188
|
|
|
164
|
-
|
|
189
|
+
Copyright © 2026 David Afonso. Kiln is licensed under the [MIT License](LICENSE).
|
data/lib/kiln/assets.rb
CHANGED
|
@@ -4,23 +4,37 @@ require "nokogiri"
|
|
|
4
4
|
require "set"
|
|
5
5
|
|
|
6
6
|
module Kiln
|
|
7
|
-
# Finds the /assets/* files the output uses and
|
|
8
|
-
#
|
|
7
|
+
# Finds the /assets/* files the output uses and exports them. Compiled assets are read from the
|
|
8
|
+
# compile directory; dynamic Propshaft (development, test) serves them through the app.
|
|
9
9
|
class Assets
|
|
10
10
|
CSS_REFERENCE = /url\(\s*["']?([^"')]+?)["']?\s*\)|@import\s+["']([^"']+)["']/
|
|
11
11
|
EXTERNAL = %r{\A(?:[a-z][a-z0-9+.-]*:|//|#)}i
|
|
12
12
|
|
|
13
13
|
class << self
|
|
14
|
-
# Compiles assets in-process when the app does not serve them dynamically.
|
|
15
|
-
#
|
|
14
|
+
# Compiles assets in-process when the app does not serve them dynamically. The compile goes to a
|
|
15
|
+
# temporary directory, never public/assets, so a development server of the same app that boots
|
|
16
|
+
# meanwhile never sees a production manifest. Returns a callable that restores the asset config
|
|
17
|
+
# and removes the directory, or nil when nothing was compiled. When assets are served
|
|
18
|
+
# dynamically, still runs the build steps hooked into assets:precompile (tailwindcss:build,
|
|
19
|
+
# javascript:build, css:build), so a development build never ships stale bundles.
|
|
16
20
|
def precompile(app)
|
|
17
|
-
return unless precompile?(app)
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
21
|
+
return build_bundles(app) unless precompile?(app)
|
|
22
|
+
|
|
23
|
+
assets = app.config.assets
|
|
24
|
+
original = assets.slice(:output_path, :manifest_path)
|
|
25
|
+
dir = Pathname(Dir.mktmpdir("kiln-assets"))
|
|
26
|
+
cleanup = -> do
|
|
27
|
+
assets.merge!(original)
|
|
28
|
+
FileUtils.rm_rf(dir)
|
|
29
|
+
end
|
|
30
|
+
assets.merge!(output_path: dir, manifest_path: dir.join(".manifest.json"))
|
|
31
|
+
begin
|
|
32
|
+
run_precompile(app)
|
|
33
|
+
rescue Kiln::Error
|
|
34
|
+
cleanup.call
|
|
35
|
+
raise
|
|
36
|
+
end
|
|
37
|
+
cleanup
|
|
24
38
|
end
|
|
25
39
|
|
|
26
40
|
def precompile?(app)
|
|
@@ -30,6 +44,17 @@ module Kiln
|
|
|
30
44
|
!assets.server && !Pathname(assets.manifest_path).exist?
|
|
31
45
|
end
|
|
32
46
|
|
|
47
|
+
# Propshaft only adds load paths that exist at boot. On a fresh checkout, a bundler such as
|
|
48
|
+
# tailwindcss:build creates app/assets/builds during the build, too late to be served.
|
|
49
|
+
def check_builds!(app)
|
|
50
|
+
builds = app.root.join("app/assets/builds")
|
|
51
|
+
paths = app.config.respond_to?(:assets) && app.config.assets.respond_to?(:paths) && app.config.assets.paths
|
|
52
|
+
return unless paths && builds.directory? && paths.none? { Pathname(it) == builds }
|
|
53
|
+
|
|
54
|
+
raise Kiln::Error, "app/assets/builds did not exist when the app booted, so its assets are not served. " \
|
|
55
|
+
"Track app/assets/builds/.keep in version control, as a new Rails app does, and build again."
|
|
56
|
+
end
|
|
57
|
+
|
|
33
58
|
# Copies public/ into the output, minus public/assets. Files already in the output win, with a
|
|
34
59
|
# warning unless they are listed in `generated` (files Kiln writes on purpose, like 404.html).
|
|
35
60
|
def copy_public(from:, to:, report:, generated: [])
|
|
@@ -54,10 +79,26 @@ module Kiln
|
|
|
54
79
|
end
|
|
55
80
|
|
|
56
81
|
private
|
|
57
|
-
def
|
|
82
|
+
def build_bundles(app)
|
|
83
|
+
precompile_task(app)&.prerequisite_tasks&.each do |task|
|
|
84
|
+
next if task.name.end_with?("environment")
|
|
85
|
+
|
|
86
|
+
task.reenable
|
|
87
|
+
task.invoke
|
|
88
|
+
rescue StandardError => error
|
|
89
|
+
raise Kiln::Error, "#{task.name} failed: #{error.class}: #{error.message}"
|
|
90
|
+
end
|
|
91
|
+
nil
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
def precompile_task(app)
|
|
58
95
|
require "rake"
|
|
59
96
|
app.load_tasks unless Rake::Task.task_defined?("assets:precompile")
|
|
60
|
-
|
|
97
|
+
Rake::Task["assets:precompile"] if Rake::Task.task_defined?("assets:precompile")
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
def run_precompile(app)
|
|
101
|
+
task = precompile_task(app)
|
|
61
102
|
task.reenable
|
|
62
103
|
task.invoke
|
|
63
104
|
rescue StandardError => error
|
|
@@ -75,7 +116,6 @@ module Kiln
|
|
|
75
116
|
|
|
76
117
|
def export
|
|
77
118
|
queue = referenced_paths
|
|
78
|
-
queue.concat(all_paths) if @config.assets == :all
|
|
79
119
|
seen = Set.new
|
|
80
120
|
|
|
81
121
|
while (path = queue.shift)
|
|
@@ -87,15 +127,18 @@ module Kiln
|
|
|
87
127
|
private
|
|
88
128
|
# Writes one asset and returns the asset paths it references (CSS url() and @import).
|
|
89
129
|
def fetch(path)
|
|
90
|
-
|
|
91
|
-
unless
|
|
92
|
-
@
|
|
93
|
-
|
|
130
|
+
body = compiled(path)
|
|
131
|
+
unless body
|
|
132
|
+
response = @renderer.get(path)
|
|
133
|
+
unless response.success?
|
|
134
|
+
@report.error(:asset, "responded with #{response.status}", path:)
|
|
135
|
+
return []
|
|
136
|
+
end
|
|
137
|
+
body = response.body
|
|
94
138
|
end
|
|
95
139
|
|
|
96
140
|
extension = File.extname(path)
|
|
97
|
-
body =
|
|
98
|
-
body = Processors::StripSourceMaps.call(body) if @config.strip_source_maps && %w[.js .css].include?(extension)
|
|
141
|
+
body = Processors::StripSourceMaps.call(body) if %w[.js .css].include?(extension)
|
|
99
142
|
write(path, body)
|
|
100
143
|
extension == ".css" ? css_references(path, body) : []
|
|
101
144
|
rescue StandardError => error
|
|
@@ -103,6 +146,16 @@ module Kiln
|
|
|
103
146
|
[]
|
|
104
147
|
end
|
|
105
148
|
|
|
149
|
+
# The file from the compile directory when assets are precompiled, or nil.
|
|
150
|
+
def compiled(path)
|
|
151
|
+
assets = @app.config.assets
|
|
152
|
+
return if assets.server
|
|
153
|
+
|
|
154
|
+
dir = Pathname(assets.manifest_path).dirname.expand_path
|
|
155
|
+
file = dir.join(path.delete_prefix("#{prefix}/")).expand_path
|
|
156
|
+
file.binread if file.to_s.start_with?("#{dir}/") && file.file?
|
|
157
|
+
end
|
|
158
|
+
|
|
106
159
|
def write(path, body)
|
|
107
160
|
relative = path.delete_prefix("/")
|
|
108
161
|
file = @output.join(relative)
|
|
@@ -141,10 +194,6 @@ module Kiln
|
|
|
141
194
|
end
|
|
142
195
|
end
|
|
143
196
|
|
|
144
|
-
def all_paths
|
|
145
|
-
@app.assets.load_path.assets.map { "#{prefix}/#{it.digested_path}" }
|
|
146
|
-
end
|
|
147
|
-
|
|
148
197
|
# Normalizes a URL to an asset path ("/assets/app-abc.css"), or nil when it isn't one of ours.
|
|
149
198
|
def asset_path(url)
|
|
150
199
|
uri = URI.parse(url.to_s.strip)
|