@pmeweb/content 1.0.0 → 1.1.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.
package/README.md CHANGED
@@ -8,7 +8,7 @@ collections in `src/content.schema.json`; this package is what reads that declar
8
8
  | `@pmeweb/content/types` | `CollectionDecl`, `Field`, `ScheduleDecl`, `ContentSchema` | sites, portal |
9
9
  | `@pmeweb/content/zodFrom` | declaration -> Astro zod schema (needs `astro`) | sites |
10
10
  | `@pmeweb/content/fields` | `isDate`, `isDateTime`, `isTime`, `isDayDate`, `TIME_RE` | portal tier 1, `zodFrom` |
11
- | `@pmeweb/content/schedule` | `scheduleState`, `visibleOnSite`, `scheduleErrors`, `jourQuebec`, `quebecDay` | sites, portal |
11
+ | `@pmeweb/content/schedule` | `scheduleState`, `visibleOnSite`, `portalPreview`, `scheduleErrors`, `jourQuebec`, `quebecDay` | sites, portal |
12
12
 
13
13
  ## Dated kinds
14
14
 
@@ -28,6 +28,15 @@ collections in `src/content.schema.json`; this package is what reads that declar
28
28
  latest value in the array. Always read as a Quebec day: the entry stays through that whole day
29
29
  and comes off at the next day's rebuild. A site that declares a schedule needs a daily rebuild.
30
30
 
31
+ ## The portal preview
32
+
33
+ The builder sets `PMEWEB_PORTAL_PREVIEW=1` on the portal's preview builds, and
34
+ `PMEWEB_PORTAL_PREVIEW_PAST=1` too when the client ticked « Afficher les entrées passées ». A site
35
+ reads both once, `const APERCU = portalPreview(process.env)`, and filters with
36
+ `visibleOnSite(scheduleState(data, decl.<collection>, now), APERCU)`: live entries always,
37
+ scheduled ones in the preview, removed ones only in a preview that asked for them. Only the exact
38
+ string `'1'` counts, and the past flag means nothing without the preview flag.
39
+
31
40
  ## Versioning
32
41
 
33
42
  Sites and the portal pin an EXACT version. What `scheduleState` returns and what the field checks
@@ -47,7 +47,22 @@ export declare function scheduleErrors(c: SchedulableLike): string[];
47
47
  */
48
48
  export declare function scheduleState(data: Record<string, unknown>, c: SchedulableLike, now: Date): ScheduleState;
49
49
  /**
50
- * What a site builds. The portal's PRIVATE preview (`PMEWEB_PORTAL_PREVIEW === '1'`) shows a
51
- * scheduled entry early so the client can check it; it never brings back a removed one.
50
+ * What kind of build this is, read from the two variables the portal's builder sets.
51
+ *
52
+ * `active` is the portal's PRIVATE preview (`PMEWEB_PORTAL_PREVIEW`): it shows a scheduled entry
53
+ * early so the client can check it. `showPast` is « Afficher les entrées passées » in the portal
54
+ * (`PMEWEB_PORTAL_PREVIEW_PAST`), which brings back entries already off the site so the client
55
+ * can see the one they are correcting.
56
+ *
57
+ * ONLY THE EXACT STRING `'1'` COUNTS, and `showPast` MEANS NOTHING WITHOUT `active`. The
58
+ * dangerous failure is a past or future entry on the LIVE site, so every other value -- absent,
59
+ * empty, `true` -- reads as « not a preview », and no environment can turn on the past without
60
+ * the preview signal the builder sets for its own builds only.
52
61
  */
53
- export declare function visibleOnSite(state: ScheduleState, portalPreview: boolean): boolean;
62
+ export interface PortalPreview {
63
+ active: boolean;
64
+ showPast: boolean;
65
+ }
66
+ export declare function portalPreview(env: Record<string, string | undefined>): PortalPreview;
67
+ /** What a site builds: live always; scheduled in the preview; removed only when asked for. */
68
+ export declare function visibleOnSite(state: ScheduleState, preview: PortalPreview): boolean;
package/dist/schedule.js CHANGED
@@ -174,10 +174,15 @@ export function scheduleState(data, c, now) {
174
174
  const d = removeDay(data, c);
175
175
  return d !== null && quebecDayOf(now.getTime()) > d ? 'removed' : 'live';
176
176
  }
177
- /**
178
- * What a site builds. The portal's PRIVATE preview (`PMEWEB_PORTAL_PREVIEW === '1'`) shows a
179
- * scheduled entry early so the client can check it; it never brings back a removed one.
180
- */
181
- export function visibleOnSite(state, portalPreview) {
182
- return state === 'live' || (state === 'scheduled' && portalPreview);
177
+ export function portalPreview(env) {
178
+ const active = env.PMEWEB_PORTAL_PREVIEW === '1';
179
+ return { active, showPast: active && env.PMEWEB_PORTAL_PREVIEW_PAST === '1' };
180
+ }
181
+ /** What a site builds: live always; scheduled in the preview; removed only when asked for. */
182
+ export function visibleOnSite(state, preview) {
183
+ if (state === 'live')
184
+ return true;
185
+ if (!preview.active)
186
+ return false;
187
+ return state === 'scheduled' || preview.showPast;
183
188
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pmeweb/content",
3
- "version": "1.0.0",
3
+ "version": "1.1.0",
4
4
  "description": "PmeWeb content contract: content.schema.json types, zodFrom, field checks, scheduling. Read by every site's build and by the client portal.",
5
5
  "type": "module",
6
6
  "license": "MIT",