@perkyzz/emvb 0.2.0 → 0.2.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/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
[](https://emvb.dev) [](https://www.npmjs.com/package/@perkyzz/emvb)
|
|
4
4
|
|
|
5
|
-
A visual page builder plugin for [EmDash CMS](https://github.com/emdash-cms/emdash) 1.0.
|
|
5
|
+
A visual page builder plugin for [EmDash CMS](https://github.com/emdash-cms/emdash) 1.0–1.2. Pages are built in a full-screen editor inside the EmDash admin and published as plain HTML and CSS. It runs on Node (SQLite) and Cloudflare Workers (D1).
|
|
6
6
|
|
|
7
7
|

|
|
8
8
|
|
|
@@ -12,7 +12,7 @@ A visual page builder plugin for [EmDash CMS](https://github.com/emdash-cms/emda
|
|
|
12
12
|
npm i @perkyzz/emvb
|
|
13
13
|
```
|
|
14
14
|
|
|
15
|
-
Peers, which an EmDash 1.
|
|
15
|
+
Peers, which an EmDash 1.x site already has: `emdash` ^1.0.0, `astro` ^7, `react` and `react-dom` ^19, `@cloudflare/kumo` 2.6.0 and `@phosphor-icons/react` ^2.1.10. `@emdash-cms/plugin-forms` is optional and enables forms.
|
|
16
16
|
|
|
17
17
|
## Register the plugin
|
|
18
18
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@perkyzz/emvb",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.1",
|
|
4
4
|
"description": "Visual page builder plugin for EmDash CMS",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"astro",
|
|
@@ -56,7 +56,7 @@
|
|
|
56
56
|
"@types/react": "19.3.0",
|
|
57
57
|
"@types/react-dom": "19.3.0",
|
|
58
58
|
"astro": "7.3.5",
|
|
59
|
-
"emdash": "1.0
|
|
59
|
+
"emdash": "1.2.0",
|
|
60
60
|
"react": "19.3.0",
|
|
61
61
|
"react-dom": "19.3.0",
|
|
62
62
|
"vitest": "5.0.2"
|
|
@@ -65,6 +65,8 @@ export function ShadowControl({
|
|
|
65
65
|
label="Position"
|
|
66
66
|
className={FIELD}
|
|
67
67
|
value={value.inset === true ? "inset" : "outset"}
|
|
68
|
+
// W-306: Kumo's Select shows the raw value ("inset") without a renderValue.
|
|
69
|
+
renderValue={(v: unknown) => (v === "inset" ? "Inset" : "Outset")}
|
|
68
70
|
onValueChange={(next) => {
|
|
69
71
|
const checked = next === "inset";
|
|
70
72
|
patch({ inset: checked === true ? true : undefined });
|
|
@@ -32,8 +32,8 @@ import {
|
|
|
32
32
|
} from "../core/index.ts";
|
|
33
33
|
import { THEME_PARTS_COLLECTION } from "../constants.ts";
|
|
34
34
|
import { loadDesign, readLayout, renderStored, type RenderedPage } from "./render.ts";
|
|
35
|
-
import { themeContextFrom } from "./theme-context.ts";
|
|
36
|
-
import { themePostFromEntry } from "./theme-posts.ts";
|
|
35
|
+
import { decodePathSegment, themeContextFrom } from "./theme-context.ts";
|
|
36
|
+
import { entryTimestamp, themePostFromEntry } from "./theme-posts.ts";
|
|
37
37
|
|
|
38
38
|
/** The landmark element for a part's wrapper (W-216); other parts get a plain div. */
|
|
39
39
|
const WRAPPER_TAGS: Partial<Record<string, "header" | "footer">> = {
|
|
@@ -150,7 +150,7 @@ function storedPartFrom(entry: { id: string; data: unknown }): StoredPart | unde
|
|
|
150
150
|
conditions: conditions.conditions,
|
|
151
151
|
triggers: triggers.ok ? triggers.triggers : defaultTriggers(),
|
|
152
152
|
float: float.ok ? float.settings : defaultFloatSettings(),
|
|
153
|
-
updatedAt:
|
|
153
|
+
updatedAt: entryTimestamp(data["updatedAt"] ?? data["updated_at"]) ?? "",
|
|
154
154
|
};
|
|
155
155
|
}
|
|
156
156
|
|
|
@@ -232,7 +232,7 @@ async function loadSingularPost(ctx: ThemeRequestContext): Promise<ThemePostFiel
|
|
|
232
232
|
const key = ctx.entryId || undefined;
|
|
233
233
|
// Prefer slug from path `/posts/{slug}` when entry id is missing.
|
|
234
234
|
const pathSlug = /^\/posts\/([^/]+)$/.exec(ctx.path)?.[1];
|
|
235
|
-
const lookup = key || (pathSlug ?
|
|
235
|
+
const lookup = key || (pathSlug ? decodePathSegment(pathSlug) : undefined);
|
|
236
236
|
if (!lookup) return undefined;
|
|
237
237
|
try {
|
|
238
238
|
const { entry } = await getEmDashEntry("posts", lookup);
|
|
@@ -12,15 +12,27 @@ const context = (path: string, rest: Kind & Partial<ThemeRequestContext>): Theme
|
|
|
12
12
|
...rest,
|
|
13
13
|
});
|
|
14
14
|
|
|
15
|
+
/**
|
|
16
|
+
* A percent-decoded path segment, or the raw segment when its escapes are malformed (W-305), the
|
|
17
|
+
* way EmDash 1.2's `decodeSlug` stopped throwing: `/category/%E0` is a lookup that finds nothing.
|
|
18
|
+
*/
|
|
19
|
+
export function decodePathSegment(segment: string): string {
|
|
20
|
+
try {
|
|
21
|
+
return decodeURIComponent(segment);
|
|
22
|
+
} catch {
|
|
23
|
+
return segment;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
15
27
|
/** Archive URLs by pattern, and what each adds to the context. */
|
|
16
28
|
const ARCHIVES: [RegExp, (match: RegExpExecArray) => Partial<ThemeRequestContext>][] = [
|
|
17
29
|
[
|
|
18
30
|
/^\/category\/([^/]+)$/,
|
|
19
|
-
([, slug]) => ({ taxonomy: { type: "category", slug:
|
|
31
|
+
([, slug]) => ({ taxonomy: { type: "category", slug: decodePathSegment(slug ?? "") } }),
|
|
20
32
|
],
|
|
21
33
|
[
|
|
22
34
|
/^\/tag\/([^/]+)$/,
|
|
23
|
-
([, slug]) => ({ taxonomy: { type: "tag", slug:
|
|
35
|
+
([, slug]) => ({ taxonomy: { type: "tag", slug: decodePathSegment(slug ?? "") } }),
|
|
24
36
|
],
|
|
25
37
|
[/^\/posts$/, () => ({ collection: "posts" })],
|
|
26
38
|
];
|
package/src/astro/theme-posts.ts
CHANGED
|
@@ -27,6 +27,15 @@ export function mediaFieldsFrom(value: unknown): {
|
|
|
27
27
|
return { featuredImageUrl, featuredImageAlt };
|
|
28
28
|
}
|
|
29
29
|
|
|
30
|
+
/**
|
|
31
|
+
* An entry timestamp as an ISO string (W-302). EmDash hands system dates (`updatedAt`,
|
|
32
|
+
* `publishedAt`) to templates as `Date` objects, so `String()` gave "Sun Sep 06 2026 …".
|
|
33
|
+
*/
|
|
34
|
+
export function entryTimestamp(value: unknown): string | undefined {
|
|
35
|
+
if (value instanceof Date) return Number.isNaN(value.getTime()) ? undefined : value.toISOString();
|
|
36
|
+
return typeof value === "string" && value.trim() ? value.trim() : undefined;
|
|
37
|
+
}
|
|
38
|
+
|
|
30
39
|
/**
|
|
31
40
|
* Normalize an EmDash posts collection entry (or plain data bag) into ThemePostFields.
|
|
32
41
|
* Permalink defaults to `/posts/{slug}` to match the demo routes.
|
|
@@ -48,7 +57,10 @@ export function themePostFromEntry(
|
|
|
48
57
|
const prefix = options.permalinkPrefix ?? "/posts";
|
|
49
58
|
const permalink = `${prefix.replace(/\/$/, "")}/${slug || id}`;
|
|
50
59
|
const media = mediaFieldsFrom(data["featured_image"]);
|
|
51
|
-
|
|
60
|
+
// W-303: EmDash's own publish date is `data.publishedAt`, a `Date`; a custom field may be text.
|
|
61
|
+
const publishedAt = ["published_at", "publishedAt", "date"]
|
|
62
|
+
.map((key) => entryTimestamp(data[key]))
|
|
63
|
+
.find(Boolean);
|
|
52
64
|
const authorName = authorFrom(data);
|
|
53
65
|
return {
|
|
54
66
|
id: id || slug,
|
|
@@ -80,5 +92,11 @@ function authorFrom(data: Record<string, unknown>): string | undefined {
|
|
|
80
92
|
const name = (author as { name?: unknown }).name;
|
|
81
93
|
if (typeof name === "string" && name.trim()) return name.trim();
|
|
82
94
|
}
|
|
95
|
+
// W-304: EmDash hydrates the primary byline onto `data.byline` (a BylineSummary).
|
|
96
|
+
const byline = data["byline"];
|
|
97
|
+
if (byline && typeof byline === "object" && "displayName" in byline) {
|
|
98
|
+
const name = (byline as { displayName?: unknown }).displayName;
|
|
99
|
+
if (typeof name === "string" && name.trim()) return name.trim();
|
|
100
|
+
}
|
|
83
101
|
return undefined;
|
|
84
102
|
}
|
package/src/constants.ts
CHANGED