andromeda_cms 0.11.0 → 0.12.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 +31 -0
- data/README.md +9 -3
- data/ext/andromeda_cms/src/lib.rs +7 -7
- data/lib/andromeda/assets.rb +11 -0
- data/lib/andromeda/build_context.rb +10 -0
- data/lib/andromeda/components.rb +32 -17
- data/lib/andromeda/entry.rb +9 -7
- data/lib/andromeda/file_stamp.rb +18 -0
- data/lib/andromeda/fix.rb +3 -5
- data/lib/andromeda/helpers.rb +1 -1
- data/lib/andromeda/loader.rb +2 -1
- data/lib/andromeda/pipeline.rb +22 -16
- data/lib/andromeda/renderer.rb +2 -2
- data/lib/andromeda/script/module_graph.rb +3 -5
- data/lib/andromeda/store.rb +6 -2
- data/lib/andromeda/version.rb +1 -1
- data/lib/andromeda_cms.rb +1 -0
- data/lib/generators/andromeda/import_astro/mdx_import_rewriter.rb +2 -4
- metadata +2 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 47685aedf2002621e1646d457ef0fddde3d7b0020a0e8be91c5c713445a81d45
|
|
4
|
+
data.tar.gz: 66ed2f768450a9e42701a1a474c443d5f57ac154e4dc7256c9dfd2bd324b9197
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: ad6f2d0fd7f6eab6969ebe973b54981e97b61c7b63feb8424fce1115b88c16825ebdaf319f631c6903bd524ee29005ce69b0c20237461e2e026530d5fcbd392a
|
|
7
|
+
data.tar.gz: 62b84241d3002120b2f3e19f30105a607c722f15ccc75c7cf29563dc1afb836840ade03b3749e4e59959b1895a826c8e1c1d4b9341188c61be45cdcbbdb97884
|
data/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,36 @@ All notable changes to this project are documented in this file.
|
|
|
5
5
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
|
|
6
6
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
7
|
|
|
8
|
+
## [0.12.0] - 2026-12-04
|
|
9
|
+
|
|
10
|
+
### Added
|
|
11
|
+
|
|
12
|
+
- `Entry#raw_frontmatter` holds the frontmatter as written, before the
|
|
13
|
+
schema coerced it, for an entry the Loader built. MDX's `frontmatter`
|
|
14
|
+
comes from it instead of reading the source file a second time.
|
|
15
|
+
|
|
16
|
+
### Changed
|
|
17
|
+
|
|
18
|
+
- `andromeda:build` writes a collection's `_index.json` once, after its
|
|
19
|
+
last entry, instead of rewriting it for every entry. The time a build
|
|
20
|
+
takes now grows with the number of entries rather than with its square:
|
|
21
|
+
on 1,110 files it went from 8.9s to 4.3s without a JavaScript runtime and
|
|
22
|
+
from 11.6s to 6.4s with mini_racer. A partial that reads the collection
|
|
23
|
+
being built through `index` sees the previous build's index until the
|
|
24
|
+
collection finishes.
|
|
25
|
+
- The component partials are scanned once per build for the render key,
|
|
26
|
+
not once per entry.
|
|
27
|
+
- The release workflow uses `actions/upload-artifact@v6`,
|
|
28
|
+
`actions/download-artifact@v7` and
|
|
29
|
+
`rubygems/configure-rubygems-credentials@v2.2.0`, which run on Node 24.
|
|
30
|
+
|
|
31
|
+
### Fixed
|
|
32
|
+
|
|
33
|
+
- A JSON or image import in MDX rendered without a collection's base
|
|
34
|
+
directory is checked against the entry's own directory. It used to be
|
|
35
|
+
checked against the imported file's directory, so a `../` chain out of
|
|
36
|
+
the project was reported as missing instead of refused.
|
|
37
|
+
|
|
8
38
|
## [0.11.0] - 2026-12-03
|
|
9
39
|
|
|
10
40
|
### Added
|
|
@@ -464,6 +494,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
464
494
|
- Generators: `andromeda:install`, `andromeda:collection`,
|
|
465
495
|
`andromeda:component` and `andromeda:import_astro`.
|
|
466
496
|
|
|
497
|
+
[0.12.0]: https://github.com/AndromedaCMS/andromeda_cms/releases/tag/v0.12.0
|
|
467
498
|
[0.11.0]: https://github.com/AndromedaCMS/andromeda_cms/releases/tag/v0.11.0
|
|
468
499
|
[0.10.0]: https://github.com/AndromedaCMS/andromeda_cms/releases/tag/v0.10.0
|
|
469
500
|
[0.9.0]: https://github.com/AndromedaCMS/andromeda_cms/releases/tag/v0.9.0
|
data/README.md
CHANGED
|
@@ -150,6 +150,9 @@ Frontmatter is validated against the entry class: a missing `title` or an
|
|
|
150
150
|
unparseable date fails the build with the file name and line number, rather
|
|
151
151
|
than surfacing as `nil` in a view.
|
|
152
152
|
|
|
153
|
+
HTML written in Markdown or MDX is output as written, without sanitizing, as
|
|
154
|
+
in Astro: content is trusted as much as the application's own templates.
|
|
155
|
+
|
|
153
156
|
### MDX components
|
|
154
157
|
|
|
155
158
|
MDX components map to Rails partials — no ViewComponent dependency:
|
|
@@ -251,14 +254,17 @@ end
|
|
|
251
254
|
|
|
252
255
|
Values render as Astro renders them (`false`, `null` and `undefined` render
|
|
253
256
|
nothing, arrays are joined, strings are escaped, `class:list` and style
|
|
254
|
-
objects work
|
|
257
|
+
objects work, and `$...$` stays text, as in Astro without a math plugin).
|
|
258
|
+
Components are still Rails partials: their props are the
|
|
255
259
|
evaluated values, a JSX prop arrives as HTML, an imported image as an
|
|
256
260
|
`Andromeda::Image`, and functions are dropped. Packages are not installed for
|
|
257
261
|
Rails, so a package import may only bring in components (Starlight's
|
|
258
262
|
`Card`); anything else from one is an error.
|
|
259
263
|
|
|
260
|
-
Each file runs in a fresh JavaScript context with a 10-second limit,
|
|
261
|
-
|
|
264
|
+
Each file runs in a fresh JavaScript context with a 10-second limit, when the
|
|
265
|
+
entry is converted: during `andromeda:build`, and in development inside the
|
|
266
|
+
request that first reads an entry after it changed. That request waits for
|
|
267
|
+
it, and with Node it is the web server's process that starts `node`. The code in MDX runs with the runtime's reach: imports can read
|
|
262
268
|
files in the project, and with Node the code can reach the file system
|
|
263
269
|
and the network too, since Node's `vm` is not a sandbox. Build only content
|
|
264
270
|
whose authors you would trust with code.
|
|
@@ -4,11 +4,10 @@
|
|
|
4
4
|
//! mdast tree as JSON. See `Cargo.toml` for why Sätteri.
|
|
5
5
|
//!
|
|
6
6
|
//! Parsing happens fully in Rust; the mdast tree crosses the FFI boundary as
|
|
7
|
-
//! a single JSON string rather than as nested Ruby objects
|
|
8
|
-
//!
|
|
9
|
-
//!
|
|
10
|
-
//!
|
|
11
|
-
//! having to hold the GVL while walking the arena).
|
|
7
|
+
//! a single JSON string rather than as nested Ruby objects: building Ruby
|
|
8
|
+
//! `Hash`/`Array` objects node by node through the Ruby C API would have to
|
|
9
|
+
//! hold the GVL for the whole walk of the arena. `serde_json::to_string`
|
|
10
|
+
//! walks it without Ruby, and Ruby then needs one `JSON.parse`.
|
|
12
11
|
|
|
13
12
|
mod errors;
|
|
14
13
|
mod esm;
|
|
@@ -87,8 +86,9 @@ fn script_options() -> Options {
|
|
|
87
86
|
/// are both recursive over nesting depth. A few thousand nested `>` or
|
|
88
87
|
/// `<div>` overflow the native stack, and on a Ruby thread other than the
|
|
89
88
|
/// main one -- which is where Puma serves development requests -- the stack
|
|
90
|
-
/// is small enough that 5,000 levels already fail. Real content nests a
|
|
91
|
-
///
|
|
89
|
+
/// is small enough that 5,000 levels already fail. Real content nests a
|
|
90
|
+
/// handful of levels; 256 leaves ample room for it while keeping every
|
|
91
|
+
/// recursive step far from any stack limit.
|
|
92
92
|
const MAX_DEPTH: usize = 256;
|
|
93
93
|
|
|
94
94
|
/// Longest run of a single `*` or `_` accepted.
|
data/lib/andromeda/assets.rb
CHANGED
|
@@ -62,6 +62,17 @@ module Andromeda
|
|
|
62
62
|
"#{MARKER}#{logical_path}"
|
|
63
63
|
end
|
|
64
64
|
|
|
65
|
+
# An image an MDX file imports (`import photo from './photo.png'`),
|
|
66
|
+
# published like an `image()` attribute. The caller checks `refusal` and
|
|
67
|
+
# existence first, to report them in its own error.
|
|
68
|
+
#
|
|
69
|
+
# @param specifier [String] the import's path, as written.
|
|
70
|
+
# @return [Andromeda::Image]
|
|
71
|
+
def imported_image(source, specifier, content_root:)
|
|
72
|
+
logical = publish(source, content_root: content_root)
|
|
73
|
+
Andromeda::Image.new(path: source, relative_path: specifier, asset: marker_for(logical))
|
|
74
|
+
end
|
|
75
|
+
|
|
65
76
|
# @param html [String] stored HTML, possibly containing markers.
|
|
66
77
|
# @return [String] the same HTML with every marker replaced by a real URL.
|
|
67
78
|
def resolve(html)
|
|
@@ -48,6 +48,16 @@ module Andromeda
|
|
|
48
48
|
cache[entry_class] ||= yield
|
|
49
49
|
end
|
|
50
50
|
|
|
51
|
+
# @param key [Symbol]
|
|
52
|
+
# @return [Object] the block's result, computed once per build and once
|
|
53
|
+
# per call outside one.
|
|
54
|
+
def per_build(key)
|
|
55
|
+
cache = Thread.current[BUILD_KEY]
|
|
56
|
+
return yield if cache.nil?
|
|
57
|
+
|
|
58
|
+
cache.fetch([:per_build, key]) { cache[[:per_build, key]] = yield }
|
|
59
|
+
end
|
|
60
|
+
|
|
51
61
|
# Marks the block as rendering an entry's body into stored HTML. Anything
|
|
52
62
|
# that would bake a final asset URL into it must emit a marker instead:
|
|
53
63
|
# the digest is only known once `assets:precompile` runs, after the build.
|
data/lib/andromeda/components.rb
CHANGED
|
@@ -167,6 +167,14 @@ module Andromeda
|
|
|
167
167
|
#
|
|
168
168
|
# @param name [String, Symbol]
|
|
169
169
|
# @return [String]
|
|
170
|
+
# The partial path a component lives under, as ActionView names it:
|
|
171
|
+
# `config.components_path` without the `app/views/` it is relative to.
|
|
172
|
+
#
|
|
173
|
+
# @return [String] e.g. "content_components".
|
|
174
|
+
def partial_prefix
|
|
175
|
+
Andromeda.config.components_path.sub(%r{\Aapp/views/}, "")
|
|
176
|
+
end
|
|
177
|
+
|
|
170
178
|
def underscore(name)
|
|
171
179
|
name.to_s
|
|
172
180
|
.gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2')
|
|
@@ -204,14 +212,12 @@ module Andromeda
|
|
|
204
212
|
# admin one). Imports resolve only inside the components directory, and
|
|
205
213
|
# anything else falls back to convention like an unresolvable import.
|
|
206
214
|
def within_components_path?(partial)
|
|
207
|
-
base = Andromeda.config.components_path.sub(%r{\Aapp/views/}, "")
|
|
208
215
|
normalized = Pathname.new(partial).cleanpath.to_s
|
|
209
|
-
normalized.start_with?("#{
|
|
216
|
+
normalized.start_with?("#{self.class.partial_prefix}/")
|
|
210
217
|
end
|
|
211
218
|
|
|
212
219
|
def convention_partial(name)
|
|
213
|
-
|
|
214
|
-
"#{base}/#{self.class.underscore(name)}"
|
|
220
|
+
"#{self.class.partial_prefix}/#{self.class.underscore(name)}"
|
|
215
221
|
end
|
|
216
222
|
|
|
217
223
|
# @return [Hash{Symbol => Object}] props, camelCase -> snake_case,
|
|
@@ -288,13 +294,7 @@ module Andromeda
|
|
|
288
294
|
@json_imports.fetch(name) do
|
|
289
295
|
specifier = @default_imports[name]
|
|
290
296
|
invalid = ->(reason) { InvalidDataImportError.new(name, specifier, reason, path: @path, line: line) }
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
source = File.expand_path(specifier, File.dirname(File.expand_path(@path)))
|
|
294
|
-
content_root = @content_root || File.dirname(source)
|
|
295
|
-
refusal = Andromeda::Assets.refusal(source, content_root: content_root)
|
|
296
|
-
raise invalid.call(refusal) if refusal
|
|
297
|
-
raise invalid.call("does not exist") unless File.file?(source)
|
|
297
|
+
source = imported_file(specifier, invalid)
|
|
298
298
|
|
|
299
299
|
@json_imports[name] = begin
|
|
300
300
|
JSON.parse(File.read(source))
|
|
@@ -304,7 +304,6 @@ module Andromeda
|
|
|
304
304
|
end
|
|
305
305
|
end
|
|
306
306
|
|
|
307
|
-
IMAGE_EXTENSIONS = %w[.png .jpg .jpeg .gif .webp .avif .svg].freeze
|
|
308
307
|
IDENTIFIER_RE = /\A[A-Za-z_$][\w$]*\z/.freeze
|
|
309
308
|
|
|
310
309
|
# `{photo}` where `photo` was bound by `import photo from './photo.png'`
|
|
@@ -313,7 +312,7 @@ module Andromeda
|
|
|
313
312
|
return false unless IDENTIFIER_RE.match?(name)
|
|
314
313
|
|
|
315
314
|
specifier = @imports[name]
|
|
316
|
-
!specifier.nil? &&
|
|
315
|
+
!specifier.nil? && Andromeda::Assets.image?(specifier)
|
|
317
316
|
end
|
|
318
317
|
|
|
319
318
|
# Publishes the imported file the same way an `image` attribute is, so
|
|
@@ -326,16 +325,32 @@ module Andromeda
|
|
|
326
325
|
def imported_image(name, node)
|
|
327
326
|
specifier = @imports[name]
|
|
328
327
|
invalid = ->(reason) { InvalidImageImportError.new(name, specifier, reason, path: @path, line: node_position(node)[:line]) }
|
|
328
|
+
source = imported_file(specifier, invalid)
|
|
329
|
+
|
|
330
|
+
Andromeda::Assets.imported_image(source, specifier, content_root: import_root)
|
|
331
|
+
end
|
|
332
|
+
|
|
333
|
+
# The file a JSON or image import names, checked the same way for both:
|
|
334
|
+
# a relative path, inside the project and not private (before existence,
|
|
335
|
+
# so a crafted path never learns whether something outside exists), and
|
|
336
|
+
# present.
|
|
337
|
+
#
|
|
338
|
+
# @param invalid [Proc] builds the caller's error from a reason.
|
|
339
|
+
# @return [String] the absolute path.
|
|
340
|
+
def imported_file(specifier, invalid)
|
|
329
341
|
raise invalid.call("must be a relative path (./ or ../)") unless specifier.start_with?("./", "../") && @path
|
|
330
342
|
|
|
331
343
|
source = File.expand_path(specifier, File.dirname(File.expand_path(@path)))
|
|
332
|
-
|
|
333
|
-
refusal = Andromeda::Assets.refusal(source, content_root: content_root)
|
|
344
|
+
refusal = Andromeda::Assets.refusal(source, content_root: import_root)
|
|
334
345
|
raise invalid.call(refusal) if refusal
|
|
335
346
|
raise invalid.call("does not exist") unless File.file?(source)
|
|
336
347
|
|
|
337
|
-
|
|
338
|
-
|
|
348
|
+
source
|
|
349
|
+
end
|
|
350
|
+
|
|
351
|
+
# The collection's directory, or the entry's own without one.
|
|
352
|
+
def import_root
|
|
353
|
+
@content_root || File.dirname(File.expand_path(@path))
|
|
339
354
|
end
|
|
340
355
|
|
|
341
356
|
# @return [Hash{Symbol => String}] `{content: ...}` plus one entry per
|
data/lib/andromeda/entry.rb
CHANGED
|
@@ -226,14 +226,11 @@ module Andromeda
|
|
|
226
226
|
@entries
|
|
227
227
|
end
|
|
228
228
|
|
|
229
|
-
#
|
|
230
|
-
#
|
|
231
|
-
# scheme as Andromeda::Pipeline#render_key uses for component partials.
|
|
229
|
+
# The collection's source files, stamped (Andromeda::FileStamp) the
|
|
230
|
+
# same way Andromeda::Pipeline#render_key stamps component partials.
|
|
232
231
|
def source_signature
|
|
233
232
|
root = File.expand_path(base_dir)
|
|
234
|
-
files = Andromeda::Loader.glob(root, pattern).map
|
|
235
|
-
[file.delete_prefix("#{root}#{File::SEPARATOR}"), File.mtime(file).to_r, File.size(file)].join(":")
|
|
236
|
-
end
|
|
233
|
+
files = Andromeda::Loader.glob(root, pattern).map { |file| Andromeda::FileStamp.of(file, root: root) }
|
|
237
234
|
Digest::SHA256.hexdigest(files.join("\n"))
|
|
238
235
|
end
|
|
239
236
|
|
|
@@ -287,14 +284,19 @@ module Andromeda
|
|
|
287
284
|
attr_reader :file_path
|
|
288
285
|
# @return [String] SHA-256 of the whole source file, for cache keys.
|
|
289
286
|
attr_reader :digest
|
|
287
|
+
# @return [Hash, nil] the frontmatter as written, before the schema
|
|
288
|
+
# coerced it, when the Loader built this entry. MDX sees it as
|
|
289
|
+
# `frontmatter`.
|
|
290
|
+
attr_reader :raw_frontmatter
|
|
290
291
|
|
|
291
|
-
def initialize(id:, collection:, data:, body:, file_path:, digest:)
|
|
292
|
+
def initialize(id:, collection:, data:, body:, file_path:, digest:, raw_frontmatter: nil)
|
|
292
293
|
@id = id
|
|
293
294
|
@collection = collection
|
|
294
295
|
@data = data
|
|
295
296
|
@body = body
|
|
296
297
|
@file_path = file_path
|
|
297
298
|
@digest = digest
|
|
299
|
+
@raw_frontmatter = raw_frontmatter
|
|
298
300
|
end
|
|
299
301
|
|
|
300
302
|
# The rendered HTML for `body` (MDX components expanded),
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Andromeda
|
|
4
|
+
# What a cache key needs to notice a file changing without reading it:
|
|
5
|
+
# its path, modification time and size. An added or removed file changes
|
|
6
|
+
# the list of paths, an edit changes the time or the size.
|
|
7
|
+
module FileStamp
|
|
8
|
+
module_function
|
|
9
|
+
|
|
10
|
+
# @param file [String] an existing file.
|
|
11
|
+
# @param root [String, nil] written relative to this directory when given.
|
|
12
|
+
# @return [String] "path:mtime:size".
|
|
13
|
+
def of(file, root: nil)
|
|
14
|
+
name = root ? file.delete_prefix("#{root}#{File::SEPARATOR}") : file
|
|
15
|
+
[name, File.mtime(file).to_r, File.size(file)].join(":")
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
data/lib/andromeda/fix.rb
CHANGED
|
@@ -83,12 +83,10 @@ module Andromeda
|
|
|
83
83
|
Set.new
|
|
84
84
|
end
|
|
85
85
|
|
|
86
|
+
# The same conversion component props get, so a key andromeda:fix
|
|
87
|
+
# renames reads the same as the prop an Astro component would receive.
|
|
86
88
|
def snake_case(key)
|
|
87
|
-
key
|
|
88
|
-
.gsub("-", "_")
|
|
89
|
-
.gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2')
|
|
90
|
-
.gsub(/([a-z\d])([A-Z])/, '\1_\2')
|
|
91
|
-
.downcase
|
|
89
|
+
Andromeda::Components.underscore(key)
|
|
92
90
|
end
|
|
93
91
|
|
|
94
92
|
def content_files(entry_classes)
|
data/lib/andromeda/helpers.rb
CHANGED
|
@@ -11,7 +11,7 @@ module Andromeda
|
|
|
11
11
|
# entry's html and wrapped once, when the page is served. Marked
|
|
12
12
|
# html_safe because the build
|
|
13
13
|
# produced this markup from content the application's own authors wrote,
|
|
14
|
-
# the same trust model Astro applies to `.md`/`.mdx
|
|
14
|
+
# the same trust model Astro applies to `.md`/`.mdx`.
|
|
15
15
|
# Inside a component rendered at conversion time the asset markers are
|
|
16
16
|
# left in place, for the same reason `andromeda_image_url` leaves them.
|
|
17
17
|
#
|
data/lib/andromeda/loader.rb
CHANGED
|
@@ -119,7 +119,8 @@ module Andromeda
|
|
|
119
119
|
# edit would -- `digest` is a cache key for the
|
|
120
120
|
# content, and the frontmatter is as much "the content" as the
|
|
121
121
|
# body is.
|
|
122
|
-
digest: Digest::SHA256.hexdigest(source)
|
|
122
|
+
digest: Digest::SHA256.hexdigest(source),
|
|
123
|
+
raw_frontmatter: frontmatter
|
|
123
124
|
)
|
|
124
125
|
[entry, nil]
|
|
125
126
|
rescue Andromeda::SyntaxError => e
|
data/lib/andromeda/pipeline.rb
CHANGED
|
@@ -59,7 +59,9 @@ module Andromeda
|
|
|
59
59
|
# that want every problem across a whole collection reported together
|
|
60
60
|
# should go through `#build_collection` instead of calling this
|
|
61
61
|
# directly in a loop.
|
|
62
|
-
|
|
62
|
+
# @param index [Boolean] whether to fold the entry into `_index.json`;
|
|
63
|
+
# `#build_collection` writes the whole index once at the end instead.
|
|
64
|
+
def convert(entry, index: true)
|
|
63
65
|
result = Andromeda::BuildContext.converting("#{entry.collection}/#{entry.id}") { render(entry) }
|
|
64
66
|
|
|
65
67
|
payload = {
|
|
@@ -76,7 +78,7 @@ module Andromeda
|
|
|
76
78
|
render_key: render_key,
|
|
77
79
|
file_path: entry.file_path
|
|
78
80
|
}
|
|
79
|
-
@store.write_entry(entry.collection, entry.id, payload)
|
|
81
|
+
@store.write_entry(entry.collection, entry.id, payload, index: index)
|
|
80
82
|
payload
|
|
81
83
|
end
|
|
82
84
|
|
|
@@ -115,7 +117,7 @@ module Andromeda
|
|
|
115
117
|
convert(entry)
|
|
116
118
|
end
|
|
117
119
|
|
|
118
|
-
# The list-view read path behind
|
|
120
|
+
# The list-view read path behind `Content::Post.index`:
|
|
119
121
|
# in production, just reads `_index.json` (never touches source files);
|
|
120
122
|
# in development, does a full staleness-aware pass over the collection
|
|
121
123
|
# first (via `#refresh_collection`) so the index reflects edits/deletes
|
|
@@ -242,7 +244,7 @@ module Andromeda
|
|
|
242
244
|
errors = []
|
|
243
245
|
payloads = entries.filter_map do |entry|
|
|
244
246
|
begin
|
|
245
|
-
convert(entry)
|
|
247
|
+
convert(entry, index: false)
|
|
246
248
|
rescue Andromeda::Error => e
|
|
247
249
|
errors << "[#{entry_class.collection_name}] #{entry.file_path}: #{e.message}"
|
|
248
250
|
nil
|
|
@@ -290,9 +292,11 @@ module Andromeda
|
|
|
290
292
|
end
|
|
291
293
|
|
|
292
294
|
# MDX's `frontmatter` is the frontmatter as written, as in Astro, not the
|
|
293
|
-
# schema's coerced `data
|
|
294
|
-
# without a readable source (built
|
|
295
|
+
# schema's coerced `data`. The Loader keeps it on the entry; otherwise the
|
|
296
|
+
# source is read again for it. An entry without a readable source (built
|
|
297
|
+
# in memory) falls back to `data`.
|
|
295
298
|
def raw_frontmatter(entry)
|
|
299
|
+
return entry.raw_frontmatter if entry.raw_frontmatter
|
|
296
300
|
return entry.data unless entry.file_path && File.file?(entry.file_path)
|
|
297
301
|
|
|
298
302
|
Andromeda::Frontmatter.parse(File.read(entry.file_path), path: entry.file_path).first
|
|
@@ -304,11 +308,16 @@ module Andromeda
|
|
|
304
308
|
# the MDX file itself changed. Partials outside `components_path` (an
|
|
305
309
|
# import pointing elsewhere under app/views) are not tracked; scanning
|
|
306
310
|
# every view on every development request would cost more than it saves.
|
|
311
|
+
#
|
|
312
|
+
# Computed once per build: partials do not change while it runs, and
|
|
313
|
+
# globbing them for every entry adds up on a large collection.
|
|
307
314
|
def render_key
|
|
308
|
-
|
|
309
|
-
|
|
315
|
+
Andromeda::BuildContext.per_build(:render_key) { compute_render_key }
|
|
316
|
+
end
|
|
310
317
|
|
|
311
|
-
|
|
318
|
+
def compute_render_key
|
|
319
|
+
partials = Dir.glob(File.join(Andromeda.config.project_root, Andromeda.config.components_path, "**", "*")).sort.filter_map do |file|
|
|
320
|
+
Andromeda::FileStamp.of(file) if File.file?(file)
|
|
312
321
|
end
|
|
313
322
|
# Whether MDX ran as JavaScript changes the HTML too.
|
|
314
323
|
Digest::SHA256.hexdigest(
|
|
@@ -320,12 +329,6 @@ module Andromeda
|
|
|
320
329
|
@mode == :production
|
|
321
330
|
end
|
|
322
331
|
|
|
323
|
-
# Only constructed for `.mdx` sources: a plain Markdown parse (`mdx:
|
|
324
|
-
# false`) never produces an `mdxJsxFlowElement`/`mdxJsxTextElement` node
|
|
325
|
-
# for the Renderer to call this on, so there is nothing to inject for
|
|
326
|
-
# `.md` entries. Resolved lazily (by constant name, not a `require`) so
|
|
327
|
-
# this file loads and works whether or not
|
|
328
|
-
# `Andromeda::Components` has landed yet.
|
|
329
332
|
# `image` attributes are published alongside the ones written in the body,
|
|
330
333
|
# so a hero image declared only in frontmatter is served the same way and
|
|
331
334
|
# a view never has to publish anything while handling a request.
|
|
@@ -387,9 +390,12 @@ module Andromeda
|
|
|
387
390
|
end
|
|
388
391
|
end
|
|
389
392
|
|
|
393
|
+
# Only constructed for `.mdx` sources: a plain Markdown parse (`mdx:
|
|
394
|
+
# false`) never produces an `mdxJsxFlowElement`/`mdxJsxTextElement` node
|
|
395
|
+
# for the Renderer to call this on, so there is nothing to inject for
|
|
396
|
+
# `.md` entries.
|
|
390
397
|
def components_for(entry, tree)
|
|
391
398
|
return nil unless Andromeda::Parser.mdx?(entry.file_path)
|
|
392
|
-
return nil unless defined?(Andromeda::Components)
|
|
393
399
|
|
|
394
400
|
Andromeda::Components.new(
|
|
395
401
|
tree: tree, path: entry.file_path, view: nil, frontmatter: entry.data,
|
data/lib/andromeda/renderer.rb
CHANGED
|
@@ -20,8 +20,8 @@ module Andromeda
|
|
|
20
20
|
class Renderer
|
|
21
21
|
# `render` returns one of these: `html` is the full rendered document,
|
|
22
22
|
# `headings` is `[{depth:, slug:, text:}, ...]` in document order --
|
|
23
|
-
# the same shape Astro's `render()` result carries,
|
|
24
|
-
#
|
|
23
|
+
# the same shape Astro's `render()` result carries, which
|
|
24
|
+
# `andromeda_toc` walks without re-parsing the tree.
|
|
25
25
|
Result = Struct.new(:html, :headings, keyword_init: true)
|
|
26
26
|
|
|
27
27
|
# @param components [#render, nil] receives `(tag_name, attributes,
|
|
@@ -40,7 +40,7 @@ module Andromeda
|
|
|
40
40
|
class ModuleGraph
|
|
41
41
|
COMPONENT_EXTENSIONS = %w[.astro .jsx .tsx .vue .svelte .md .mdx].freeze
|
|
42
42
|
MODULE_EXTENSIONS = %w[.js .mjs .ts .mts].freeze
|
|
43
|
-
IMAGE_EXTENSIONS =
|
|
43
|
+
IMAGE_EXTENSIONS = Andromeda::Assets::IMAGE_EXTENSIONS
|
|
44
44
|
JSX_RUNTIME = "andromeda/jsx-runtime"
|
|
45
45
|
ENTRY = "entry"
|
|
46
46
|
|
|
@@ -138,8 +138,7 @@ module Andromeda
|
|
|
138
138
|
end
|
|
139
139
|
|
|
140
140
|
def partial_path?(specifier)
|
|
141
|
-
|
|
142
|
-
specifier.start_with?("#{base}/")
|
|
141
|
+
specifier.start_with?("#{Andromeda::Components.partial_prefix}/")
|
|
143
142
|
end
|
|
144
143
|
|
|
145
144
|
# One record per specifier: export name -> the name the component is
|
|
@@ -180,8 +179,7 @@ module Andromeda
|
|
|
180
179
|
end
|
|
181
180
|
|
|
182
181
|
def image(file, specifier)
|
|
183
|
-
|
|
184
|
-
image = Andromeda::Image.new(path: file, relative_path: specifier, asset: Andromeda::Assets.marker_for(logical))
|
|
182
|
+
image = Andromeda::Assets.imported_image(file, specifier, content_root: @content_root)
|
|
185
183
|
@images << image
|
|
186
184
|
{ "$$andromeda_image" => @images.size - 1, src: image.asset, format: File.extname(file).delete_prefix(".").downcase }
|
|
187
185
|
end
|
data/lib/andromeda/store.rb
CHANGED
|
@@ -77,10 +77,14 @@ module Andromeda
|
|
|
77
77
|
# scanning (let alone rewriting) the whole collection would be wasteful.
|
|
78
78
|
#
|
|
79
79
|
# @param payload [Hash] Symbol-keyed, as built by Pipeline#convert.
|
|
80
|
+
# @param index [Boolean] false when the caller rewrites the whole index
|
|
81
|
+
# afterwards (`replace_collection!`): merging each entry into it reads
|
|
82
|
+
# and rewrites the index once per entry, which grows with the square of
|
|
83
|
+
# the collection's size.
|
|
80
84
|
# @return [Hash] `payload`, unchanged, for chaining.
|
|
81
|
-
def write_entry(collection, id, payload)
|
|
85
|
+
def write_entry(collection, id, payload, index: true)
|
|
82
86
|
atomic_write(entry_path(collection, id), dump_json(encode_entry(payload)))
|
|
83
|
-
merge_index_entry(collection, payload)
|
|
87
|
+
merge_index_entry(collection, payload) if index
|
|
84
88
|
payload
|
|
85
89
|
end
|
|
86
90
|
|
data/lib/andromeda/version.rb
CHANGED
data/lib/andromeda_cms.rb
CHANGED
|
@@ -4,6 +4,7 @@ require_relative "andromeda/version"
|
|
|
4
4
|
require_relative "andromeda/errors"
|
|
5
5
|
require_relative "andromeda/configuration"
|
|
6
6
|
require_relative "andromeda/build_context"
|
|
7
|
+
require_relative "andromeda/file_stamp"
|
|
7
8
|
require_relative "andromeda/assets"
|
|
8
9
|
require_relative "andromeda/helpers"
|
|
9
10
|
require_relative "andromeda/fix"
|
|
@@ -19,7 +19,6 @@ module Andromeda
|
|
|
19
19
|
DEFAULT_IMPORT_RE = /^import\s+([A-Za-z_$][\w$]*)\s+from\s+(['"])(.*?)\2\s*;?[ \t]*$/
|
|
20
20
|
NAMED_IMPORT_RE = /^import\s*\{([^}]*)\}\s*from\s+(['"])(.*?)\2\s*;?[ \t]*$/
|
|
21
21
|
NAMED_BINDING_RE = /\A([A-Za-z_$][\w$]*)(?:\s+as\s+([A-Za-z_$][\w$]*))?\z/
|
|
22
|
-
IMAGE_EXTENSIONS = %w[.png .jpg .jpeg .gif .svg .webp .avif].freeze
|
|
23
22
|
|
|
24
23
|
module_function
|
|
25
24
|
|
|
@@ -74,7 +73,7 @@ module Andromeda
|
|
|
74
73
|
end
|
|
75
74
|
|
|
76
75
|
def image_path?(path)
|
|
77
|
-
|
|
76
|
+
Andromeda::Assets.image?(path)
|
|
78
77
|
end
|
|
79
78
|
|
|
80
79
|
# @return [String] `content_components/<underscored name>`, matching
|
|
@@ -82,8 +81,7 @@ module Andromeda
|
|
|
82
81
|
# tags with, minus the `app/views/` prefix a partial
|
|
83
82
|
# path never includes.
|
|
84
83
|
def partial_path(name)
|
|
85
|
-
|
|
86
|
-
"#{base}/#{Andromeda::Components.underscore(name)}"
|
|
84
|
+
"#{Andromeda::Components.partial_prefix}/#{Andromeda::Components.underscore(name)}"
|
|
87
85
|
end
|
|
88
86
|
end
|
|
89
87
|
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: andromeda_cms
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.12.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- LIMHAUS Inc.
|
|
@@ -122,6 +122,7 @@ files:
|
|
|
122
122
|
- lib/andromeda/configuration.rb
|
|
123
123
|
- lib/andromeda/entry.rb
|
|
124
124
|
- lib/andromeda/errors.rb
|
|
125
|
+
- lib/andromeda/file_stamp.rb
|
|
125
126
|
- lib/andromeda/fix.rb
|
|
126
127
|
- lib/andromeda/frontmatter.rb
|
|
127
128
|
- lib/andromeda/helpers.rb
|