@tideworthy/tidysites-platform 0.10.0 → 0.10.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.
- package/CHANGELOG.md +4 -0
- package/package.json +1 -1
- package/src/editor/revisions.ts +18 -12
- package/src/routes/revisions.ts +5 -1
- package/src/version.ts +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.10.2
|
|
4
|
+
|
|
5
|
+
- Editor: the Revisions list starts after the newest publish, which is what is live now and has nothing to view or restore; a deep link to it opens the list. Inside the revision viewer EmDash's pill is hidden along with the bar.
|
|
6
|
+
|
|
3
7
|
## 0.9.1
|
|
4
8
|
|
|
5
9
|
- Editor: one editor on the site. An article page (a post, a service area, a page with the article layout) gets the bar too, with Publish from the entry's draft state, Business details and Done, over EmDash's inline prose editing; EmDash's own pill is hidden under the bar everywhere. Inside sections and record regions this editor owns the fields and EmDash's inline editor does not mount; outside them (article prose) it keeps working.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tideworthy/tidysites-platform",
|
|
3
|
-
"version": "0.10.
|
|
3
|
+
"version": "0.10.2",
|
|
4
4
|
"description": "The Tidysites platform integration for EmDash sites: bootstrap, sessions, maintenance, health, and publish hooks under /_tidy/*.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
package/src/editor/revisions.ts
CHANGED
|
@@ -64,15 +64,16 @@ export function startRevisions(): void {
|
|
|
64
64
|
}
|
|
65
65
|
|
|
66
66
|
function renderList() {
|
|
67
|
-
const head = el("div", { class: "tidy-panel-head" }, [el("h2", { text: "Revisions" }), el("p", { text: "Every
|
|
67
|
+
const head = el("div", { class: "tidy-panel-head" }, [el("h2", { text: "Revisions" }), el("p", { text: "Every earlier publish of the website. Open one to see this page as it was then." })]);
|
|
68
68
|
const list = el("div", { class: "tidy-add-list" });
|
|
69
|
-
|
|
70
|
-
|
|
69
|
+
// The newest revision is what is live now: nothing to view or restore, so the list starts after it.
|
|
70
|
+
revisions.slice(1).forEach((rev) => {
|
|
71
|
+
const note = rev.restoredFrom ? "Restored" : "";
|
|
71
72
|
const item = el("button", { type: "button", class: "tidy-add-item" }, [el("strong", { text: when(rev.at) }), el("span", { text: [note, rev.pages ? `${rev.pages} pages` : ""].filter(Boolean).join(" · ") })]);
|
|
72
|
-
item.addEventListener("click", () => void view(rev
|
|
73
|
+
item.addEventListener("click", () => void view(rev));
|
|
73
74
|
list.append(item);
|
|
74
75
|
});
|
|
75
|
-
if (revisions.length
|
|
76
|
+
if (revisions.length < 2) list.append(el("p", { class: "tidy-field-note", text: "No earlier revisions yet." }));
|
|
76
77
|
const closeBtn = el("button", { type: "button", class: "tidy-btn", text: "Close" });
|
|
77
78
|
closeBtn.addEventListener("click", close);
|
|
78
79
|
panel.replaceChildren(head, list, el("div", { class: "tidy-panel-actions" }, [closeBtn]));
|
|
@@ -91,18 +92,22 @@ export function startRevisions(): void {
|
|
|
91
92
|
document.body.append(viewer);
|
|
92
93
|
backBtn.addEventListener("click", () => { viewer.hidden = true; frame.removeAttribute("srcdoc"); renderList(); });
|
|
93
94
|
|
|
94
|
-
async function view(rev: Revision
|
|
95
|
+
async function view(rev: Revision) {
|
|
95
96
|
panel.hidden = true;
|
|
96
|
-
viewerLabel.textContent =
|
|
97
|
-
restoreBtn.hidden = isLive;
|
|
97
|
+
viewerLabel.textContent = when(rev.at);
|
|
98
98
|
const r = await fetch(`${ROUTE}?id=${encodeURIComponent(rev.id)}&path=${encodeURIComponent(here)}`, { credentials: "same-origin" });
|
|
99
99
|
if (!r.ok) {
|
|
100
100
|
const j = (await r.json().catch(() => ({}))) as { error?: string };
|
|
101
101
|
frame.srcdoc = `<p style="font:15px system-ui;margin:2rem">${j.error ?? "This revision could not be read."}</p>`;
|
|
102
102
|
} else {
|
|
103
|
-
// The stored copy links its assets by absolute path;
|
|
103
|
+
// The stored copy links its built assets by absolute path (/_astro/...);
|
|
104
|
+
// those are read from the revision itself, so the page shows the way it
|
|
105
|
+
// was built. Everything else (uploads, links) resolves against this site.
|
|
104
106
|
const html = await r.text();
|
|
105
|
-
|
|
107
|
+
const own = (p: string) => `${ROUTE}?id=${encodeURIComponent(rev.id)}&path=${encodeURIComponent(p)}`;
|
|
108
|
+
frame.srcdoc = html
|
|
109
|
+
.replace(/(href|src)="(\/_astro\/[^"]+)"/g, (_m, attr: string, p: string) => `${attr}="${own(p)}"`)
|
|
110
|
+
.replace(/<head([^>]*)>/i, `<head$1><base href="${location.origin}/"><style>html.tidy-has-bar body{padding-top:0!important}#tidy-bar,.tidy-bar,#emdash-toolbar{display:none!important}</style>`);
|
|
106
111
|
}
|
|
107
112
|
viewer.hidden = false;
|
|
108
113
|
restoreBtn.onclick = async () => {
|
|
@@ -144,8 +149,9 @@ export function startRevisions(): void {
|
|
|
144
149
|
const want = params.get("tidy-revision");
|
|
145
150
|
if (want || params.get("tidy-revisions")) {
|
|
146
151
|
void load().then((list) => {
|
|
147
|
-
|
|
148
|
-
|
|
152
|
+
// The newest revision is live now and is not in the list, so a link to it opens the list.
|
|
153
|
+
const rev = want ? list.slice(1).find((x) => x.id === want) : null;
|
|
154
|
+
if (rev) void view(rev);
|
|
149
155
|
else renderList();
|
|
150
156
|
}).catch(() => undefined);
|
|
151
157
|
}
|
package/src/routes/revisions.ts
CHANGED
|
@@ -47,7 +47,11 @@ export const GET: APIRoute = async (context) => {
|
|
|
47
47
|
if (!/^[0-9a-f-]{36}$/i.test(id)) return json({ error: "bad revision id" }, 400);
|
|
48
48
|
const r = await c.call(`/releases/${id}/page?path=${encodeURIComponent(path)}`);
|
|
49
49
|
if (!r.ok) return json({ error: r.status === 404 ? "That page was not in this revision." : "The revision could not be read." }, r.status === 404 ? 404 : 502);
|
|
50
|
-
|
|
50
|
+
// A page comes back as HTML; a path with an extension is one of the
|
|
51
|
+
// revision's own files (its stylesheets, scripts, images), passed through
|
|
52
|
+
// with its type so the page shows the way it was built.
|
|
53
|
+
const type = r.headers.get("content-type") ?? "application/octet-stream";
|
|
54
|
+
return new Response(r.body, { headers: { "content-type": type, "cache-control": "no-store" } });
|
|
51
55
|
}
|
|
52
56
|
const r = await c.call("/releases");
|
|
53
57
|
if (!r.ok) return json({ error: "The revisions could not be read." }, 502);
|
package/src/version.ts
CHANGED