@rigel-cms/rigel 1.4.0 → 1.5.0-rc.1
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.
- package/docs/media.md +1 -1
- package/docs/preview.md +15 -0
- package/package.json +1 -1
- package/src/preview.ts +16 -1
package/docs/media.md
CHANGED
|
@@ -52,7 +52,7 @@ On the local backend, open an asset in Media, edit its display name, title, desc
|
|
|
52
52
|
|
|
53
53
|
Local file uploads send a browser-supplied author label through `X-Rigel-Author`. Rigel uses the browser identity's name or nickname, falling back to `Local user`. This is a descriptive label, not verified ownership or an audit identity. The metadata editor cannot change it. Existing files and URL or stock imports may have no captured author; the interface displays `Local user` as a fallback.
|
|
54
54
|
|
|
55
|
-
For rich-text image insertion, saved repository-image alt text supplies a default that you can override per use, or leave empty for a decorative image. Image fields store the URL; declare and render a separate alt field where your site needs one. Rigel does not rewrite alt text already stored in content. Rich-text insertions remain unsaved until the document's Save action.
|
|
55
|
+
For rich-text image insertion, saved repository-image alt text supplies a default that you can override per use, or leave empty for a decorative image. Image fields store the URL; declare and render a separate alt field where your site needs one. Store the original URL rather than a path your build generates. [Preview](preview.md) covers the `data-rigel-src` binding for optimized Astro images. Rigel does not rewrite alt text already stored in content. Rich-text insertions remain unsaved until the document's Save action.
|
|
56
56
|
|
|
57
57
|
## Image URLs and stock providers
|
|
58
58
|
|
package/docs/preview.md
CHANGED
|
@@ -44,6 +44,21 @@ These HTML excerpts illustrate the scalar anchors. Render the saved values throu
|
|
|
44
44
|
|
|
45
45
|
Paths use object keys and stable array `_key` values. Array positions are not preview bindings. For schema content, put `data-rigel-doc="page:about"` on each bound element and on section/list containers. It identifies the source document for that element; a parent attribute does not substitute for attributes on descendant anchors. Referenced records use their own IDs and local field paths.
|
|
46
46
|
|
|
47
|
+
### Keep optimized images editable
|
|
48
|
+
|
|
49
|
+
Astro's `Image` and `Picture` components replace `src` with hashed, responsive candidates, so changing `src` alone changes nothing while `srcset` still lists the old files. Mark an editable image with `data-rigel-src` to show the draft instead:
|
|
50
|
+
|
|
51
|
+
```astro
|
|
52
|
+
<Image src={cover} alt={hero.alt} widths={[480, 960]} sizes="100vw" data-rigel-image="hero.image" data-rigel-alt="hero.alt" data-rigel-src={hero.image} />
|
|
53
|
+
<Picture src={cover} formats={["avif", "webp"]} alt={hero.alt} data-rigel-image="hero.image" data-rigel-src={hero.image} />
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
`data-rigel-image` names the field, as before. `data-rigel-src` holds the original browser-addressable URL that the field stores, and it marks the element as optimized. In preview, a marked image loses its `srcset` and `sizes`, and the surrounding `picture` sources lose theirs, so the field value is the file the browser loads. The attribute is not a second source of truth: preview renders the field value, and a value that fails the image URL check is dropped rather than loaded.
|
|
57
|
+
|
|
58
|
+
Public pages are untouched. Rigel patches only the editor iframe, so built markup keeps its hashed URLs, `srcset` and AVIF or WebP sources. Images without `data-rigel-src` keep their previous behavior: the `src` changes and any `srcset` stays.
|
|
59
|
+
|
|
60
|
+
Store the original reference in content, never a generated path. `/images/cover.jpg`, a media URL or an HTTPS URL work; `/_astro/cover.BnV1MXKY.webp` does not, because Astro derives it at build time. An imported file is not addressable either: `src/assets/cover.jpg` has no URL a browser can request. Serve the file from a public path or the media folder and bind that URL, even when the template imports the same file for optimization. Preview shows the original at its own size, not a resized or converted variant, and the built `width` and `height` stay as they were, so check a replacement with different proportions against the template's layout. An upload becomes reachable at its media URL once the host serves it or rebuilds.
|
|
61
|
+
|
|
47
62
|
## Prepare changing sections and lists
|
|
48
63
|
|
|
49
64
|
Scalar anchors update existing elements. Adding sections needs inert templates for each allowed section type. This HTML excerpt uses the `intro` section from [Content model](content-model.md):
|
package/package.json
CHANGED
package/src/preview.ts
CHANGED
|
@@ -217,7 +217,22 @@ export function patchPreview(doc: Document, values: Record<string, unknown>, bod
|
|
|
217
217
|
if (blocks) previews.set(el, mountExtensionPreviews(el));
|
|
218
218
|
rendered.set(el, source);
|
|
219
219
|
}
|
|
220
|
-
for (const
|
|
220
|
+
for (const el of doc.querySelectorAll<HTMLImageElement>("[data-rigel-image]")) {
|
|
221
|
+
if (el.tagName !== "IMG") continue;
|
|
222
|
+
const result = get(el, el.getAttribute("data-rigel-image")!);
|
|
223
|
+
if (!result.found) continue;
|
|
224
|
+
const value = result.value === null || result.value === undefined ? "" : String(result.value);
|
|
225
|
+
const safe = safePreviewUrl(value, true);
|
|
226
|
+
if (el.hasAttribute("data-rigel-src")) {
|
|
227
|
+
el.removeAttribute("srcset");
|
|
228
|
+
el.removeAttribute("sizes");
|
|
229
|
+
for (const source of el.closest("picture")?.querySelectorAll("source") ?? []) { source.removeAttribute("srcset"); source.removeAttribute("sizes"); }
|
|
230
|
+
if (safe) el.setAttribute("data-rigel-src", value);
|
|
231
|
+
}
|
|
232
|
+
if (safe) { if (el.getAttribute("src") !== value) el.setAttribute("src", value); }
|
|
233
|
+
else el.removeAttribute("src");
|
|
234
|
+
}
|
|
235
|
+
for (const [anchor, attr, tag] of [["alt", "alt", "IMG"], ["href", "href", "A"]]) {
|
|
221
236
|
for (const el of doc.querySelectorAll(`[data-rigel-${anchor}]`)) {
|
|
222
237
|
if (el.tagName !== tag) continue;
|
|
223
238
|
const result = get(el, el.getAttribute(`data-rigel-${anchor}`)!);
|