@marktiderman/genesis-sites 0.7.6 → 0.8.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.
Files changed (59) hide show
  1. package/README.md +74 -8
  2. package/SKILL.md +10 -0
  3. package/dist/assets/form-island.da6c662a73.js +51 -0
  4. package/dist/assets/{islands.33a445f34e.js → islands.83aaf5e0df.js} +1 -1
  5. package/dist/assets/sites-forms.bac9a6aafd.css +10 -0
  6. package/dist/assets/sites-forms.css +1 -1
  7. package/dist/assets/sites.323090ba26.css +2 -0
  8. package/dist/assets/sites.css +1 -1
  9. package/dist/assets.generated-YGLB7VKL.js +3 -0
  10. package/dist/{assets.generated-LLUGUUWZ.js.map → assets.generated-YGLB7VKL.js.map} +1 -1
  11. package/dist/blocks.js +2 -1
  12. package/dist/blocks.js.map +1 -1
  13. package/dist/{chunk-IU6AI75R.js → chunk-6CXTOPYI.js} +343 -158
  14. package/dist/chunk-6CXTOPYI.js.map +1 -0
  15. package/dist/{chunk-7E3YGYVH.js → chunk-FMQTSXJN.js} +26 -12
  16. package/dist/chunk-FMQTSXJN.js.map +1 -0
  17. package/dist/{chunk-SMJMXQ3T.js → chunk-I767PDBR.js} +260 -62
  18. package/dist/chunk-I767PDBR.js.map +1 -0
  19. package/dist/chunk-MXV2HOJO.js +19 -0
  20. package/dist/chunk-MXV2HOJO.js.map +1 -0
  21. package/dist/{chunk-KY4ALBVH.js → chunk-QE7KS2JS.js} +65 -7
  22. package/dist/chunk-QE7KS2JS.js.map +1 -0
  23. package/dist/{chunk-VJ4HOFBA.js → chunk-YAMQ2JKO.js} +20 -9
  24. package/dist/chunk-YAMQ2JKO.js.map +1 -0
  25. package/dist/editor.d.ts +22 -14
  26. package/dist/editor.js +701 -157
  27. package/dist/editor.js.map +1 -1
  28. package/dist/handler-J5BCH2VW.js +10 -0
  29. package/dist/{handler-UMGSZY33.js.map → handler-J5BCH2VW.js.map} +1 -1
  30. package/dist/import.d.ts +3 -3
  31. package/dist/index.d.ts +51 -10
  32. package/dist/index.js +3 -3
  33. package/dist/redirects-BNSD9MKa.d.ts +43 -0
  34. package/dist/{registry-BIijndsq.d.ts → registry-BPn-tDlL.d.ts} +75 -0
  35. package/dist/sections.d.ts +86 -4
  36. package/dist/sections.js +2 -2
  37. package/dist/{store-BImtGmoF.d.ts → store-B_GMH42V.d.ts} +2 -2
  38. package/dist/supabase.d.ts +4 -4
  39. package/dist/supabase.js +3 -3
  40. package/dist/{templates-kA-jrnWA.d.ts → templates-CFSSG1iU.d.ts} +2 -2
  41. package/dist/templates.d.ts +3 -3
  42. package/dist/{theme-Cg-inpk5.d.ts → theme-Dw42GDI_.d.ts} +1 -1
  43. package/dist/web.d.ts +21 -11
  44. package/dist/web.js +5 -5
  45. package/migrations/0003_genesis_sites_post_dates.sql +117 -0
  46. package/migrations/tests/0003_genesis_sites_post_dates.test.sql +76 -0
  47. package/package.json +8 -4
  48. package/dist/assets/form-island.defb8daccc.js +0 -51
  49. package/dist/assets/sites-forms.aff23b5617.css +0 -10
  50. package/dist/assets/sites.5b3f64c627.css +0 -2
  51. package/dist/assets.generated-LLUGUUWZ.js +0 -3
  52. package/dist/chunk-7E3YGYVH.js.map +0 -1
  53. package/dist/chunk-IU6AI75R.js.map +0 -1
  54. package/dist/chunk-KY4ALBVH.js.map +0 -1
  55. package/dist/chunk-RLYO6VVP.js +0 -19
  56. package/dist/chunk-RLYO6VVP.js.map +0 -1
  57. package/dist/chunk-SMJMXQ3T.js.map +0 -1
  58. package/dist/chunk-VJ4HOFBA.js.map +0 -1
  59. package/dist/handler-UMGSZY33.js +0 -10
package/dist/web.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { ImageUrlBuilder } from '@marktiderman/genesis-media';
2
- import { F as FormsResolver, U as ReleaseSnapshot, h as ReleasePage, d as ResolvedForm, O as PostsContext } from './registry-BIijndsq.js';
3
- import { S as SiteStore, R as ReservedPaths } from './store-BImtGmoF.js';
4
- import { a as BrandSource, b as SiteTheme } from './theme-Cg-inpk5.js';
2
+ import { F as FormsResolver, U as ReleaseSnapshot, h as ReleasePage, d as ResolvedForm, O as PostsContext } from './registry-BPn-tDlL.js';
3
+ import { S as SiteStore, R as ReservedPaths } from './store-B_GMH42V.js';
4
+ import { a as BrandSource, b as SiteTheme } from './theme-Dw42GDI_.js';
5
5
  import * as React from 'react';
6
6
  import 'zod';
7
7
  import '@marktiderman/genesis-design-system';
@@ -20,8 +20,9 @@ import '@marktiderman/genesis-design-system';
20
20
  *
21
21
  * Order: reserved paths (null), this package's assets, robots.txt and
22
22
  * sitemap.xml, redirects, the trailing-slash redirect, then the page. An
23
- * unknown path is null (or the site's 404 page, with `unknownPath:
24
- * "not-found"`). Pages render to HTML with no hydration.
23
+ * unknown path is null (or, with `unknownPath: "not-found"`, the site's 404
24
+ * page: its page at `/404`, or the built-in text when it has none), status
25
+ * 404. Pages render to HTML with no hydration.
25
26
  */
26
27
 
27
28
  /** Where this package serves its own files, under the site's base path. Reserved for pages. */
@@ -70,7 +71,10 @@ interface SiteRequestOptions {
70
71
  path: string;
71
72
  status: number;
72
73
  }) => void;
73
- /** An unknown path: `fall-through` (default) returns null; `not-found` serves the site's 404 page. */
74
+ /**
75
+ * An unknown path: `fall-through` (default) returns null; `not-found` serves
76
+ * the site's 404 page (its page at `/404`, or the built-in text), status 404.
77
+ */
74
78
  unknownPath?: "fall-through" | "not-found";
75
79
  /**
76
80
  * The site's font files, served by this package under `/_gs/` (default
@@ -134,8 +138,14 @@ interface SiteAssets {
134
138
  }
135
139
  interface SiteRendererProps {
136
140
  snapshot: ReleaseSnapshot;
137
- /** The page to render, or null for the site's "not found" page. */
141
+ /** The page to render, or null for the built-in "Page not found" text. */
138
142
  page: ReleasePage | null;
143
+ /**
144
+ * The page stands for an address the site doesn't have (the site's 404
145
+ * page): `noindex`, no canonical URL, Open Graph or structured data.
146
+ * Default: true when `page` is null or is the page at `/404`.
147
+ */
148
+ notFound?: boolean;
139
149
  theme: SiteTheme;
140
150
  /** The site's primary origin, for canonical and Open Graph URLs. */
141
151
  origin: string;
@@ -180,13 +190,13 @@ declare function collectFormSlugs(_snapshot: ReleaseSnapshot, page: ReleasePage
180
190
  *
181
191
  * @stability Beta
182
192
  */
183
- declare function SiteRenderer({ snapshot, page, theme, origin, basePath, mode, logo, forms, assets, posts, imageUrl }: SiteRendererProps): React.JSX.Element;
193
+ declare function SiteRenderer({ snapshot, page, notFound, theme, origin, basePath, mode, logo, forms, assets, posts, imageUrl }: SiteRendererProps): React.JSX.Element;
184
194
 
185
195
  declare const ASSET_SIZES: {
186
- readonly css: 47444;
187
- readonly formsCss: 92819;
196
+ readonly css: 49084;
197
+ readonly formsCss: 94982;
188
198
  readonly islands: 3010;
189
- readonly formIsland: 553078;
199
+ readonly formIsland: 553656;
190
200
  readonly fonts: 861576;
191
201
  };
192
202
  /** Each self-hosted font file's name under the assets prefix, by its key (`inter-700`). */
package/dist/web.js CHANGED
@@ -1,10 +1,10 @@
1
- export { ASSETS_PREFIX, SiteRenderer, collectFormSlugs, fontFaces, handleSiteRequest, pageStyleText, renderSitePageToString } from './chunk-7E3YGYVH.js';
2
- export { ASSET_SIZES, FONT_FILES } from './chunk-RLYO6VVP.js';
1
+ export { ASSETS_PREFIX, SiteRenderer, collectFormSlugs, fontFaces, handleSiteRequest, pageStyleText, renderSitePageToString } from './chunk-FMQTSXJN.js';
2
+ export { ASSET_SIZES, FONT_FILES } from './chunk-MXV2HOJO.js';
3
3
  import './chunk-OFJISW3T.js';
4
- import './chunk-SMJMXQ3T.js';
4
+ import './chunk-I767PDBR.js';
5
5
  import './chunk-VZUDRPFG.js';
6
- import './chunk-VJ4HOFBA.js';
7
- import './chunk-IU6AI75R.js';
6
+ import './chunk-YAMQ2JKO.js';
7
+ import './chunk-6CXTOPYI.js';
8
8
  import './chunk-MU2Z2C4F.js';
9
9
  //# sourceMappingURL=web.js.map
10
10
  //# sourceMappingURL=web.js.map
@@ -0,0 +1,117 @@
1
+ -- Genesis Sites 0003: an imported post keeps its date
2
+ --
3
+ -- Two fixes to 0002's import_posts and publish_post:
4
+ -- 1. A publishedAt of "infinity" was clamped to now() before the finite check,
5
+ -- so it was accepted as today. The date is now checked (finite, not before
6
+ -- 1970) before it is clamped to now.
7
+ -- 2. A post imported as a draft lost its publishedAt, so its first publish was
8
+ -- dated that day. A draft import now keeps the date in
9
+ -- site_posts.imported_published_at, and publish_post uses it when the post
10
+ -- has never been published.
11
+ --
12
+ -- This migration needs 0002. `add column if not exists`: an app that already
13
+ -- added the column under this name keeps it.
14
+ --
15
+ -- Use: `genesis add sites` copies this file into supabase/migrations under a
16
+ -- new timestamped name. Never edit it once applied; change it with a new migration.
17
+ --
18
+ -- Verify: the pgTAP test beside this file (`tests/0003_genesis_sites_post_dates.test.sql`).
19
+
20
+ alter table genesis_sites.site_posts add column if not exists imported_published_at timestamptz;
21
+ comment on column genesis_sites.site_posts.imported_published_at is
22
+ 'A draft import''s date from the old site: its first publish uses it as published_at, so the post keeps its date. Null otherwise.';
23
+
24
+ create or replace function genesis_sites.publish_post(post_id uuid, expected_rev integer)
25
+ returns jsonb
26
+ language plpgsql
27
+ security definer
28
+ set search_path = ''
29
+ as $$
30
+ declare
31
+ post genesis_sites.site_posts;
32
+ site_status text;
33
+ begin
34
+ perform genesis_sites.assert_can_edit((select p.site_id from genesis_sites.site_posts p where p.id = post_id));
35
+ select s.status into site_status from genesis_sites.sites s where s.id = (select p.site_id from genesis_sites.site_posts p where p.id = post_id) for update;
36
+ -- Archiving is a takedown: an editor can't put posts back up.
37
+ if site_status = 'archived' then
38
+ raise exception 'genesis_sites: an archived site can''t publish posts' using errcode = '22023';
39
+ end if;
40
+ select * into post from genesis_sites.site_posts p where p.id = post_id and p.deleted_at is null for update;
41
+ if not found then
42
+ raise exception 'genesis_sites: no post %', post_id using errcode = 'P0002';
43
+ end if;
44
+ if post.draft_rev is distinct from expected_rev then
45
+ raise exception 'genesis_sites: the post changed since it was checked' using errcode = 'GS409', detail = post.draft_rev::text;
46
+ end if;
47
+ perform genesis_sites.assert_post(post.slug, post.draft);
48
+ update genesis_sites.site_posts p
49
+ set published = p.draft, status = 'published', published_at = coalesce(p.published_at, p.imported_published_at, now()), published_updated_at = now()
50
+ where p.id = post_id
51
+ returning * into post;
52
+ return genesis_sites.post_json(post);
53
+ end;
54
+ $$;
55
+
56
+ create or replace function genesis_sites.import_posts(site_id uuid, posts jsonb)
57
+ returns jsonb
58
+ language plpgsql
59
+ security definer
60
+ set search_path = ''
61
+ as $$
62
+ declare
63
+ item jsonb;
64
+ item_slug text;
65
+ item_status text;
66
+ item_at timestamptz;
67
+ new_id uuid;
68
+ imported jsonb := '[]'::jsonb;
69
+ skipped jsonb := '[]'::jsonb;
70
+ begin
71
+ perform genesis_sites.assert_can_edit(site_id);
72
+ if posts is null or jsonb_typeof(posts) <> 'array' or jsonb_array_length(posts) > 500 then
73
+ raise exception 'genesis_sites: posts is an array of at most 500 posts' using errcode = '22023';
74
+ end if;
75
+ perform 1 from genesis_sites.sites s where s.id = import_posts.site_id and s.status <> 'archived' for update;
76
+ if not found then
77
+ raise exception 'genesis_sites: no site % to import into', site_id using errcode = 'P0002';
78
+ end if;
79
+ for item in select * from jsonb_array_elements(posts) loop
80
+ item_slug := item ->> 'slug';
81
+ begin
82
+ perform genesis_sites.assert_post(item_slug, item -> 'doc');
83
+ if exists (select 1 from genesis_sites.site_posts p where p.site_id = import_posts.site_id and p.slug = item_slug and p.deleted_at is null) then
84
+ skipped := skipped || jsonb_build_array(jsonb_build_object('slug', item_slug, 'reason', 'The site already has a post at this slug.'));
85
+ continue;
86
+ end if;
87
+ -- Published only when asked: a post with no status (or any other) comes in as a draft.
88
+ item_status := case when item ->> 'status' = 'published' then 'published' else 'draft' end;
89
+ item_at := (item ->> 'publishedAt')::timestamptz;
90
+ -- A real date: not infinity, not before 1970 (the feeds and the sitemap print it). Checked
91
+ -- before the clamp to now, which would turn infinity into now.
92
+ if item_at is not null and (not isfinite(item_at) or item_at < '1970-01-01T00:00:00Z'::timestamptz) then
93
+ raise exception 'genesis_sites: "%" isn''t a usable publish date', item ->> 'publishedAt' using errcode = '22008';
94
+ end if;
95
+ -- Never later than now (only a given date: least() skips a null, which would stamp an
96
+ -- undated draft with the import time). A draft keeps the date given for its first publish.
97
+ if item_at is not null then
98
+ item_at := least(item_at, now());
99
+ end if;
100
+ insert into genesis_sites.site_posts (site_id, slug, draft, published, status, published_at, published_updated_at, imported_published_at)
101
+ values (
102
+ site_id, item_slug, item -> 'doc',
103
+ case when item_status = 'published' then item -> 'doc' end,
104
+ item_status,
105
+ case when item_status = 'published' then coalesce(item_at, now()) end,
106
+ case when item_status = 'published' then coalesce(item_at, now()) end,
107
+ case when item_status = 'draft' then item_at end
108
+ )
109
+ returning id into new_id;
110
+ imported := imported || jsonb_build_array(jsonb_build_object('slug', item_slug, 'id', new_id, 'status', item_status));
111
+ exception when sqlstate '22023' or sqlstate '22007' or sqlstate '22008' or sqlstate '23514' or sqlstate '23505' then
112
+ skipped := skipped || jsonb_build_array(jsonb_build_object('slug', coalesce(item_slug, '?'), 'reason', sqlerrm));
113
+ end;
114
+ end loop;
115
+ return jsonb_build_object('imported', imported, 'skipped', skipped);
116
+ end;
117
+ $$;
@@ -0,0 +1,76 @@
1
+ -- @feat:sites
2
+ -- pgTAP test for 0003_genesis_sites_post_dates.sql (after 0001 and 0002).
3
+ -- Copy into your app's `supabase/tests/database/` and run `supabase test db`.
4
+ -- It writes only its own user, site and hook versions, and rolls everything
5
+ -- back. If your app already replaced the hooks (genesis_sites.can_edit,
6
+ -- can_view), they are replaced again inside this transaction only.
7
+ begin;
8
+ create extension if not exists pgtap with schema extensions;
9
+ select plan(7);
10
+
11
+ insert into auth.users (id, aud, role, email, instance_id)
12
+ values ('00000000-0000-4000-8000-0000000003e1', 'authenticated', 'authenticated', 'genesis-sites-post-dates@example.test', '00000000-0000-0000-0000-000000000000');
13
+
14
+ create function pg_temp.sign_in() returns void language plpgsql as $$
15
+ begin
16
+ perform set_config('request.jwt.claims', json_build_object('sub', '00000000-0000-4000-8000-0000000003e1', 'role', 'authenticated')::text, true);
17
+ perform set_config('request.jwt.claim.sub', '00000000-0000-4000-8000-0000000003e1', true);
18
+ perform set_config('role', 'authenticated', true);
19
+ end $$;
20
+ create function pg_temp.post(title text) returns jsonb language sql immutable as $$
21
+ select jsonb_build_object('schemaVersion', 1, 'title', title, 'excerpt', 'About ' || title,
22
+ 'body', jsonb_build_object('type', 'doc', 'content', jsonb_build_array(jsonb_build_object('type', 'paragraph', 'content', jsonb_build_array(jsonb_build_object('type', 'text', 'text', title || ' body'))))))
23
+ $$;
24
+ grant execute on function pg_temp.sign_in(), pg_temp.post(text) to authenticated;
25
+
26
+ create temp table t (k text primary key, v uuid);
27
+ grant select on t to authenticated;
28
+ insert into t select 'a', genesis_sites.create_site('Hilltop Collective', 'hilltop-post-dates-test',
29
+ '{"schemaVersion":1,"name":"Hilltop Collective","redirects":[]}'::jsonb,
30
+ jsonb_build_array(jsonb_build_object('path', '/', 'doc', jsonb_build_object('schemaVersion', 1, 'root', jsonb_build_object('props', jsonb_build_object('title', 'Home')), 'content', '[]'::jsonb))));
31
+ create function pg_temp.site() returns uuid language sql stable as $$ select v from t where k = 'a' $$;
32
+ create function pg_temp.post_id(slug text) returns uuid language sql stable as $$
33
+ select id from genesis_sites.site_posts where site_id = pg_temp.site() and site_posts.slug = post_id.slug
34
+ $$;
35
+ grant execute on function pg_temp.site(), pg_temp.post_id(text) to authenticated;
36
+
37
+ -- The app's hooks: the test login edits the site.
38
+ create or replace function genesis_sites.can_edit(site_id uuid) returns boolean
39
+ language sql stable security definer set search_path = '' as $$ select auth.uid() = '00000000-0000-4000-8000-0000000003e1'::uuid $$;
40
+ create or replace function genesis_sites.can_view(site_id uuid) returns boolean
41
+ language sql stable security definer set search_path = '' as $$ select auth.uid() = '00000000-0000-4000-8000-0000000003e1'::uuid $$;
42
+
43
+ select has_column('genesis_sites', 'site_posts', 'imported_published_at', 'a post keeps a draft import''s date');
44
+
45
+ select pg_temp.sign_in();
46
+
47
+ -- A date that isn't one: refused, infinity included (it was clamped to today before the check).
48
+ select is(
49
+ (genesis_sites.import_posts(pg_temp.site(), jsonb_build_array(
50
+ jsonb_build_object('slug', 'forever', 'doc', pg_temp.post('Forever'), 'status', 'published', 'publishedAt', 'infinity')
51
+ ))) -> 'skipped' @> '[{"slug": "forever"}]'::jsonb,
52
+ true,
53
+ 'an import refuses infinity, not only -infinity'
54
+ );
55
+
56
+ -- A dated draft keeps its date for its first publish.
57
+ select is(
58
+ (genesis_sites.import_posts(pg_temp.site(), jsonb_build_array(
59
+ jsonb_build_object('slug', 'dated-draft', 'doc', pg_temp.post('Dated draft'), 'publishedAt', '2022-05-01T08:00:00Z')
60
+ ))) #>> '{imported,0,status}',
61
+ 'draft',
62
+ 'a dated post with no status comes in as a draft'
63
+ );
64
+ select is((select published_at from genesis_sites.site_posts where id = pg_temp.post_id('dated-draft')), null, '... with no publish date yet (its slug can still change)');
65
+ select genesis_sites.publish_post(pg_temp.post_id('dated-draft'), (select draft_rev from genesis_sites.site_posts where id = pg_temp.post_id('dated-draft')));
66
+ select is((select published_at from genesis_sites.site_posts where id = pg_temp.post_id('dated-draft')), '2022-05-01T08:00:00Z'::timestamptz, '... and its first publish keeps the old site''s date');
67
+
68
+ -- An undated draft keeps no date, and its first publish dates it.
69
+ select genesis_sites.import_posts(pg_temp.site(), jsonb_build_array(jsonb_build_object('slug', 'later', 'doc', pg_temp.post('Later'))));
70
+ select is((select imported_published_at from genesis_sites.site_posts where id = pg_temp.post_id('later')), null, 'an undated draft keeps no import date');
71
+ select genesis_sites.publish_post(pg_temp.post_id('later'), (select draft_rev from genesis_sites.site_posts where id = pg_temp.post_id('later')));
72
+ -- now() is the transaction's time, so the publish date is exactly it.
73
+ select is((select published_at from genesis_sites.site_posts where id = pg_temp.post_id('later')), now(), '... and its first publish dates it now');
74
+
75
+ select * from finish();
76
+ rollback;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@marktiderman/genesis-sites",
3
- "version": "0.7.6",
3
+ "version": "0.8.0",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "sideEffects": [
@@ -91,7 +91,7 @@
91
91
  "@marktiderman/genesis-media": "^0.3.0"
92
92
  },
93
93
  "peerDependencies": {
94
- "@marktiderman/genesis-design-system": "^1.13.1",
94
+ "@marktiderman/genesis-design-system": "^1.15.0",
95
95
  "@marktiderman/genesis-forms": ">=0.6.0 <1.0.0",
96
96
  "@marktiderman/genesis-forms-web": ">=0.5.0 <1.0.0",
97
97
  "@marktiderman/genesis-ui": ">=2.36.0 <4.0.0",
@@ -126,11 +126,11 @@
126
126
  "@fontsource/source-serif-4": "^5.3.1",
127
127
  "@fontsource/space-grotesk": "^5.3.0",
128
128
  "@fontsource/work-sans": "^5.3.0",
129
- "@marktiderman/genesis-design-system": "^1.13.1",
129
+ "@marktiderman/genesis-design-system": "^1.15.0",
130
130
  "@marktiderman/genesis-forms": "^0.11.1",
131
131
  "@marktiderman/genesis-forms-react": "^0.3.3",
132
132
  "@marktiderman/genesis-forms-web": "^0.8.2",
133
- "@marktiderman/genesis-ui": "^3.2.1",
133
+ "@marktiderman/genesis-ui": "^3.5.0",
134
134
  "@puckeditor/core": "^0.24.0",
135
135
  "@supabase/supabase-js": "^2.118.0",
136
136
  "@tailwindcss/cli": "4.3.5",
@@ -194,6 +194,10 @@
194
194
  {
195
195
  "file": "migrations/0002_genesis_sites_posts.sql",
196
196
  "test": "migrations/tests/0002_genesis_sites_posts.test.sql"
197
+ },
198
+ {
199
+ "file": "migrations/0003_genesis_sites_post_dates.sql",
200
+ "test": "migrations/tests/0003_genesis_sites_post_dates.test.sql"
197
201
  }
198
202
  ],
199
203
  "install": [