@nickpaustian/tela 0.1.2 → 0.2.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 (43) hide show
  1. package/CHANGELOG.md +34 -0
  2. package/README.md +1 -1
  3. package/bin/tela.ts +18 -2
  4. package/lib/index.js +172 -7
  5. package/package.json +5 -2
  6. package/scripts/check-components.ts +20 -0
  7. package/scripts/media-sync.ts +41 -0
  8. package/scripts/republish.ts +24 -0
  9. package/src/api.ts +3 -3
  10. package/src/components/EntryEditor.lsp +174 -11
  11. package/src/components/EntryList.lsp +8 -0
  12. package/src/components/Field.lsp +92 -2
  13. package/src/components/LinkField.lsp +477 -0
  14. package/src/components/MarkdownField.lsp +19 -24
  15. package/src/components/PersonField.lsp +255 -0
  16. package/src/components/ReferenceField.lsp +22 -1
  17. package/src/components/RepeaterField.lsp +141 -13
  18. package/src/components/ToggleField.lsp +63 -0
  19. package/src/config/fields.ts +134 -1
  20. package/src/config/seo.ts +4 -2
  21. package/src/config/types.ts +158 -7
  22. package/src/content/derive-values.ts +14 -3
  23. package/src/content/entries.ts +1 -1
  24. package/src/content/entry.ts +15 -1
  25. package/src/content/export.ts +173 -14
  26. package/src/content/git.ts +1 -1
  27. package/src/content/hooks.ts +75 -0
  28. package/src/content/link-address.ts +168 -0
  29. package/src/content/links.ts +13 -0
  30. package/src/content/person.ts +11 -0
  31. package/src/content/placement.ts +48 -0
  32. package/src/content/references.ts +48 -4
  33. package/src/content/rules.ts +24 -4
  34. package/src/content/shape.ts +192 -0
  35. package/src/content/store.ts +17 -0
  36. package/src/content/url.ts +15 -1
  37. package/src/content/users.ts +32 -0
  38. package/src/content/validate.ts +12 -2
  39. package/src/index.ts +4 -1
  40. package/src/keys.ts +47 -0
  41. package/src/media/index.ts +5 -0
  42. package/src/server/index.ts +168 -34
  43. package/src/server/library-routes.ts +11 -3
package/CHANGELOG.md ADDED
@@ -0,0 +1,34 @@
1
+ # Changelog
2
+
3
+ ## 0.2.0
4
+
5
+ ### Upgrading from 0.1.x
6
+
7
+ - **Pictures are published by reference.** A page now names each picture by its media id, and publishing writes the picture itself to `content/media/<id>.json`. A site reading published content has to read those files (or resolve `picture: "<id>"` some other way). Data sources and previews still carry pictures copied in. Run `tela republish` once after upgrading, so content published before moves over in one commit.
8
+ - **`data` is reserved.** No collection may be named `data`, since data sources publish under `content/data/`.
9
+
10
+ ### Added
11
+
12
+ - **Link field** (`link()`): search pages and files, or paste any address. A field chooses what it accepts (pages, web addresses, files, email, phone), and `siteAliases` turns links pasted from the live site into pages.
13
+ - **Data sources:** a record of facts with no page, published to `content/data/<name>.json`, previewed as a page or as data. Each publish writes its shape beside it (`<name>.schema.json`) and refuses a change that would break what reads it.
14
+ - **Publish hooks** (`afterPublish`): called after each publish, such as to tell another service the content changed.
15
+ - **Toggle input** for yes-or-no fields.
16
+ - **Date fields can default to today.**
17
+ - **Fallbacks and blocks made for particular pages.**
18
+ - **Limits on many references** (`maxRows`), and an entry is kept out of its own picker.
19
+ - **`tela media-sync`:** checks every published picture against the media library and republishes what changed there (alt text, credit, a picture binned).
20
+ - **`tela republish [collection …]`:** writes every published entry again under the current rules, from the published versions, in one commit.
21
+ - A picture's words changing in the library republishes it straight away, with the data sources carrying it.
22
+
23
+ ### Fixed
24
+
25
+ - `defineConfig` keeps site aliases, the data address and publish hooks.
26
+ - Collection names are checked, and a data source's own slug is accepted.
27
+ - A markdown field's length is measured by what a reader sees, not by its link addresses.
28
+ - A save that leaves out a composite field is checked like any other.
29
+ - Keyboard shortcuts are labelled for the keyboard in use.
30
+ - Data preview text, and a page preview that can't be shown says why.
31
+
32
+ ## 0.1.3
33
+
34
+ The first release as `@nickpaustian/tela`.
package/README.md CHANGED
@@ -29,7 +29,7 @@ A project component with the same name as one of Tela's fails the build unless t
29
29
 
30
30
  ## Working on Tela and a project together
31
31
 
32
- A linked Tela is live in the project with no build step (outside `node_modules`, Node loads its source):
32
+ A linked Tela is live in the project with no build step: run from a checkout, the `tela` command compiles `lib/` before Vite reads it.
33
33
 
34
34
  ```sh
35
35
  cd tela && bun link
package/bin/tela.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env bun
2
- import { existsSync } from "fs"
2
+ import { existsSync, realpathSync } from "fs"
3
3
  import { createRequire } from "module"
4
- import { dirname, resolve } from "path"
4
+ import { dirname, resolve, sep } from "path"
5
5
  import { fileURLToPath } from "url"
6
6
 
7
7
  /**
@@ -35,6 +35,8 @@ const USAGE = `tela <command>
35
35
  create-user <email> [--editor]
36
36
  set-password <email>
37
37
  media-words [--apply] move words on media records into the library
38
+ media-sync republish pictures whose words changed in the library
39
+ republish [collection …] write every published entry again under the current rules
38
40
 
39
41
  Run from the folder holding tela.config.ts, or set TELA_CONFIG.`
40
42
 
@@ -96,6 +98,14 @@ async function vite(sub: "dev" | "build"): Promise<number> {
96
98
  return 1
97
99
  }
98
100
 
101
+ // Vite reads the compiled `lib/` for the entry points its config imports. An
102
+ // install ships it; a checkout (linked, or Tela itself) compiles it first,
103
+ // so a change there is live without a step to remember.
104
+ if (!realpathSync(TELA_ROOT).split(sep).includes("node_modules")) {
105
+ const built = await run(["bun", "run", "--silent", "build:lib"], TELA_ROOT, process.env)
106
+ if (built !== 0) return built
107
+ }
108
+
99
109
  const options = ["--experimental-strip-types", "--disable-warning=ExperimentalWarning"]
100
110
  const env = {
101
111
  ...process.env,
@@ -126,6 +136,12 @@ switch (command) {
126
136
  if (code === 0) code = await vite("build")
127
137
  break
128
138
  }
139
+ case "republish":
140
+ code = await run(["bun", script("scripts/republish.ts"), ...rest])
141
+ break
142
+ case "media-sync":
143
+ code = await run(["bun", script("scripts/media-sync.ts")])
144
+ break
129
145
  case "check":
130
146
  code = await run(["bun", script("scripts/check-components.ts")])
131
147
  break
package/lib/index.js CHANGED
@@ -1,3 +1,39 @@
1
+ // src/content/link-address.ts
2
+ var LINK_KINDS = ["pages", "files", "web", "sections", "email", "phone"];
3
+ var DEFAULT_LINK_KINDS = ["pages", "web", "sections", "email", "phone"];
4
+ function acceptedKinds(accepts) {
5
+ const known = (accepts ?? DEFAULT_LINK_KINDS).filter((one) => LINK_KINDS.includes(one));
6
+ return known.length ? known : DEFAULT_LINK_KINDS;
7
+ }
8
+ var UUID = "[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}";
9
+ var escapeName = (name) => name.replace(/[^\w-]/g, "");
10
+ function linkPattern(kinds, collections) {
11
+ const entries = collections?.length ? `(${collections.map(escapeName).join("|")})` : "(?!media/)[\\w-]+";
12
+ const parts = {
13
+ pages: [`tela:${entries}/${UUID}(#\\S*)?`, "/(?!/)\\S*"],
14
+ files: [`tela:media/${UUID}`],
15
+ web: ["https?://\\S+"],
16
+ sections: ["#\\S+"],
17
+ email: ["mailto:\\S+@\\S+"],
18
+ phone: ["tel:\\+?\\d+"]
19
+ };
20
+ return `^(${kinds.flatMap((kind) => parts[kind]).join("|")})$`;
21
+ }
22
+ var listed = (words) => words.length <= 1 ? words[0] ?? "" : `${words.slice(0, -1).join(", ")} or ${words[words.length - 1]}`;
23
+ function linkMessage(kinds) {
24
+ const choose = [kinds.includes("pages") ? "a page" : "", kinds.includes("files") ? "a file" : ""].filter(Boolean);
25
+ const paste = [
26
+ kinds.includes("web") ? "a full address" : "",
27
+ kinds.includes("email") ? "an email" : "",
28
+ kinds.includes("phone") ? "a phone number" : ""
29
+ ].filter(Boolean);
30
+ const said = [
31
+ choose.length ? `Choose ${choose.join(" or ")} from the list` : "",
32
+ paste.length ? `paste ${listed(paste)}` : ""
33
+ ].filter(Boolean).join(", or ");
34
+ return said.charAt(0).toUpperCase() + said.slice(1) + ".";
35
+ }
36
+
1
37
  // src/config/fields.ts
2
38
  function slugField({ from = "title", label = "Slug" } = {}) {
3
39
  return {
@@ -60,6 +96,70 @@ function imageUse(name, label, options = {}) {
60
96
  ]
61
97
  };
62
98
  }
99
+ function person(name, label, options = {}) {
100
+ return {
101
+ name,
102
+ label,
103
+ type: "block",
104
+ component: "person",
105
+ ...options.required ? { required: true } : {},
106
+ ...options.hint ? { options: { hint: options.hint } } : {},
107
+ fields: [
108
+ { name: "user", type: "reference", to: "users", label: "Person" },
109
+ { name: "name", type: "text", label: "Name", maxLength: 200 }
110
+ ]
111
+ };
112
+ }
113
+ function link(name, label, options = {}) {
114
+ const { required, accepts, collections, ...rest } = options;
115
+ const kinds = acceptedKinds(accepts);
116
+ return {
117
+ name,
118
+ label,
119
+ type: "link",
120
+ ...required ? { required: true } : {},
121
+ patterns: [{ pattern: linkPattern(kinds, collections), message: linkMessage(kinds) }],
122
+ options: { ...rest, accepts: kinds, ...collections?.length ? { collections } : {} }
123
+ };
124
+ }
125
+ function customBlock(name, {
126
+ label,
127
+ description,
128
+ note,
129
+ for: pages,
130
+ uses,
131
+ once = true,
132
+ kept = true,
133
+ content = {},
134
+ editable = []
135
+ }) {
136
+ return {
137
+ name,
138
+ label,
139
+ description,
140
+ note,
141
+ for: pages,
142
+ ...uses?.length ? { uses } : {},
143
+ once,
144
+ kept,
145
+ content,
146
+ fields: editable.map((field) => field.fallback === undefined && content[field.name] !== undefined ? { ...field, fallback: content[field.name] } : field)
147
+ };
148
+ }
149
+ function dataSource(name, options) {
150
+ return { ...options, name, data: true };
151
+ }
152
+
153
+ // src/config/components.ts
154
+ function dataFields(fields) {
155
+ return fields.flatMap((field) => {
156
+ if (field.type === "note")
157
+ return [];
158
+ if (field.type === "group" && field.fields)
159
+ return dataFields(field.fields);
160
+ return [field];
161
+ });
162
+ }
63
163
 
64
164
  // src/config/seo.ts
65
165
  var SEO_FIELDS = {
@@ -75,8 +175,9 @@ function seoGroup(collection, siteName) {
75
175
  return null;
76
176
  const options = collection.seo === true ? {} : collection.seo;
77
177
  const at = `Collection "${collection.name}" seo`;
178
+ const stored = dataFields(collection.fields);
78
179
  const named = (name) => {
79
- const field = collection.fields.find((one) => one.name === name);
180
+ const field = stored.find((one) => one.name === name);
80
181
  if (!field)
81
182
  throw new Error(`${at}: falls back to "${name}", which is not one of its fields.`);
82
183
  return field;
@@ -97,7 +198,7 @@ function seoGroup(collection, siteName) {
97
198
  maxLength: 70,
98
199
  counter: { target: options.title?.target ?? 60, ...suffix ? { adds: suffix } : {} },
99
200
  options: {
100
- hint: options.title?.hint ?? `Leave empty to use the ${collection.fields.some((one) => one.name === titleField) ? labelOf(titleField) : "title"}.`
201
+ hint: options.title?.hint ?? `Leave empty to use the ${stored.some((one) => one.name === titleField) ? labelOf(titleField) : "title"}.`
101
202
  }
102
203
  },
103
204
  {
@@ -238,6 +339,7 @@ var STORAGE_TYPES = {
238
339
  number: (v) => typeof v === "number" && Number.isFinite(v),
239
340
  boolean: (v) => typeof v === "boolean",
240
341
  repeater: (v) => Array.isArray(v),
342
+ link: (v) => typeof v === "string",
241
343
  reference: (v) => typeof v === "string" || Array.isArray(v) && v.every((one) => typeof one === "string"),
242
344
  block: (v) => typeof v === "object" && v !== null && !Array.isArray(v)
243
345
  };
@@ -306,14 +408,14 @@ var USER_BASE_FIELDS = [
306
408
  ];
307
409
  var BLOCK_KEY = "block";
308
410
  var LABEL_KEY = "internalLabel";
309
- function checkFields(fields, path, known = new Set) {
411
+ function checkFields(fields, path, known = new Set, dataNames = new Set) {
310
412
  for (const field of fields) {
311
413
  const where = `${path}.${field.name}`;
312
414
  if (!STORAGE_TYPES[field.type] && !LAYOUT_TYPES[field.type]) {
313
415
  throw new Error(`${where}: "${field.type}" is not a storage type. ` + `Use one of ${Object.keys(STORAGE_TYPES).join(", ")}, and name the ` + `component with \`component\` if a custom one renders it.`);
314
416
  }
315
417
  if (field.fields)
316
- checkFields(field.fields, where, known);
418
+ checkFields(field.fields, where, known, dataNames);
317
419
  for (const tool of field.tools ?? []) {
318
420
  if (!TOOL_NAMES.includes(tool)) {
319
421
  throw new Error(`${where}: "${tool}" is not a formatting tool. ` + `Use one of ${TOOL_NAMES.join(", ")}.`);
@@ -343,18 +445,38 @@ function checkFields(fields, path, known = new Set) {
343
445
  }
344
446
  }
345
447
  if (field.of)
346
- checkFields(field.of, where, known);
448
+ checkFields(field.of, where, known, dataNames);
347
449
  const seen = new Set;
348
450
  for (const block of field.blocks ?? []) {
349
451
  if (seen.has(block.name)) {
350
452
  throw new Error(`${where}: two blocks are both named "${block.name}".`);
351
453
  }
454
+ if (block.content && BLOCK_KEY in block.content) {
455
+ throw new Error(`${where}: block "${block.name}" has "${BLOCK_KEY}" in its content, which is how a row records its shape.`);
456
+ }
457
+ for (const source of block.uses ?? []) {
458
+ if (!dataNames.has(source)) {
459
+ throw new Error(`${where}: block "${block.name}" uses "${source}", which is not a data source.`);
460
+ }
461
+ }
462
+ if (block.for?.some((page) => !page.startsWith("/"))) {
463
+ throw new Error(`${where}: block "${block.name}" is for pages by address, each starting with "/".`);
464
+ }
352
465
  seen.add(block.name);
353
- checkFields(block.fields, `${where}[${block.name}]`, known);
466
+ checkFields(block.fields, `${where}[${block.name}]`, known, dataNames);
354
467
  }
355
468
  }
356
469
  }
357
470
  var BUILT_IN = ["users", "groups", "media"];
471
+ var COLLECTION_NAME = /^[a-z][a-zA-Z0-9-]*$/;
472
+ function checkCollectionName(name) {
473
+ if (!COLLECTION_NAME.test(name)) {
474
+ throw new Error(`"${name}": a collection's name is a folder in the content repo and part of its rebuild keys, ` + `so start with a lowercase letter and use only letters, digits and hyphens.`);
475
+ }
476
+ if (name === "data") {
477
+ throw new Error(`"data" is reserved: data sources are published to content/data/ and rebuilt as cms:data:<name>, ` + `so a collection called data would overwrite them. Choose another name.`);
478
+ }
479
+ }
358
480
  function checkWorkflow(collection) {
359
481
  const workflow = collection.workflow;
360
482
  if (!workflow)
@@ -385,13 +507,48 @@ function checkWorkflow(collection) {
385
507
  }
386
508
  }
387
509
  }
510
+ function checkDataSource(collection) {
511
+ const where = collection.name;
512
+ if (collection.url)
513
+ throw new Error(`${where}: a data source has no page, so no \`url\`.`);
514
+ if (collection.publishable === false)
515
+ throw new Error(`${where}: a data source is published, so it cannot set \`publishable: false\`.`);
516
+ if (collection.version !== undefined && !(Number.isInteger(collection.version) && collection.version >= 1)) {
517
+ throw new Error(`${where}: \`version\` counts up from 1.`);
518
+ }
519
+ const flat = (fields) => fields.flatMap((field) => field.type === "group" ? flat(field.fields ?? []) : [field]);
520
+ if (flat(collection.fields).some((field) => field.name === "slug")) {
521
+ throw new Error(`${where}: a data source is named by its collection, so it has no "slug" field.`);
522
+ }
523
+ }
524
+ function checkHook(hook, known) {
525
+ let url;
526
+ try {
527
+ url = new URL(hook.url);
528
+ } catch {
529
+ throw new Error(`afterPublish: "${hook.url}" is not an address.`);
530
+ }
531
+ if (url.protocol !== "https:" && url.protocol !== "http:")
532
+ throw new Error(`afterPublish: ${hook.url} must be http or https.`);
533
+ const unknown = (hook.collections ?? []).filter((name) => !known.has(name));
534
+ if (unknown.length)
535
+ throw new Error(`afterPublish: ${hook.url} names ${unknown.join(", ")}, which no collection is called.`);
536
+ }
388
537
  function defineConfig(config) {
389
538
  const known = new Set([...config.collections.map((one) => one.name), ...BUILT_IN]);
390
539
  const declaredCollections = config.collections.map((one) => withSeo(one, config.siteName));
540
+ const dataNames = new Set(config.collections.filter((one) => one.data).map((one) => one.name));
391
541
  for (const collection of declaredCollections) {
392
- checkFields(collection.fields, collection.name, known);
542
+ checkCollectionName(collection.name);
543
+ checkFields(collection.fields, collection.name, known, dataNames);
393
544
  checkWorkflow(collection);
545
+ if (collection.data)
546
+ checkDataSource(collection);
547
+ else if (collection.version !== undefined)
548
+ throw new Error(`${collection.name}: only a data source has a \`version\`.`);
394
549
  }
550
+ for (const hook of config.afterPublish ?? [])
551
+ checkHook(hook, known);
395
552
  const declared = declaredCollections.find((c) => c.name === "users");
396
553
  const [address, ...access] = USER_BASE_FIELDS;
397
554
  const userFields = config.userNames ? [address, ...USER_NAME_FIELDS, ...access] : USER_BASE_FIELDS;
@@ -442,6 +599,9 @@ function defineConfig(config) {
442
599
  ...config.overrides ? { overrides: config.overrides } : {},
443
600
  ...config.components ? { components: config.components } : {},
444
601
  ...config.site ? { site: config.site } : {},
602
+ ...config.siteAliases?.length ? { siteAliases: config.siteAliases } : {},
603
+ ...config.dataAddress ? { dataAddress: config.dataAddress } : {},
604
+ ...config.afterPublish?.length ? { afterPublish: config.afterPublish } : {},
445
605
  ...config.siteName ? { siteName: config.siteName } : {},
446
606
  ...config.userNames ? { userNames: true } : {}
447
607
  };
@@ -737,14 +897,19 @@ function iconFor(collection) {
737
897
  export {
738
898
  BUILT_IN,
739
899
  LAYOUT_TYPES,
900
+ LINK_KINDS,
740
901
  SEO_FIELDS,
741
902
  STORAGE_TYPES,
742
903
  TYPE_ICONS,
904
+ customBlock,
905
+ dataSource,
743
906
  dateRange,
744
907
  defineConfig,
745
908
  iconFor,
746
909
  imageUse,
747
910
  initialsOf,
911
+ link,
912
+ person,
748
913
  personName,
749
914
  slugField,
750
915
  splitBlock,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nickpaustian/tela",
3
- "version": "0.1.2",
3
+ "version": "0.2.0",
4
4
  "description": "A Git-backed headless CMS: collections of fields in TypeScript, edited in a Lightspeed admin, published as JSON commits to a content repo.",
5
5
  "license": "MIT",
6
6
  "author": "Nick Paustian",
@@ -34,8 +34,11 @@
34
34
  "scripts/create-user.ts",
35
35
  "scripts/set-password.ts",
36
36
  "scripts/media-words.ts",
37
+ "scripts/media-sync.ts",
38
+ "scripts/republish.ts",
37
39
  "LICENSE",
38
- "README.md"
40
+ "README.md",
41
+ "CHANGELOG.md"
39
42
  ],
40
43
  "scripts": {
41
44
  "dev": "bun bin/tela.ts dev",
@@ -1,9 +1,29 @@
1
1
  import { config } from "../src/config/load.ts"
2
2
  import { checkProject, reportCheck } from "../src/config/check.ts"
3
3
  import { componentRoots } from "../src/project.ts"
4
+ import { checkShapes } from "../src/content/shape.ts"
4
5
 
5
6
  /**
6
7
  * The pre-build check, runnable on its own. `tela check` is the same call.
7
8
  */
8
9
  const ok = reportCheck(checkProject(config.collections, componentRoots(config.components), config.overrides))
9
10
  if (!ok) process.exit(1)
11
+
12
+ const root = process.env.TELA_CONTENT_REPO
13
+ const sources = config.collections.filter((one) => one.data)
14
+ if (sources.length && !root) {
15
+ console.log("- data source shapes not checked: TELA_CONTENT_REPO is not set")
16
+ } else if (sources.length && root) {
17
+ const found = await checkShapes(config.collections, root)
18
+ if (found.length) {
19
+ console.error("\nA data source no longer matches the shape apps read:\n")
20
+ for (const problem of found) {
21
+ console.error(` ${problem.source}: ${problem.problems.join("; ")}`)
22
+ }
23
+ console.error(
24
+ "\nRaise its `version` if the break is meant, so readers can tell; otherwise put the field back.",
25
+ )
26
+ process.exit(1)
27
+ }
28
+ console.log(`✓ ${sources.length} data source shape(s) checked against ${root}`)
29
+ }
@@ -0,0 +1,41 @@
1
+ import { readdir } from "fs/promises"
2
+ import { join } from "path"
3
+ import { republishPictures } from "../src/content/export.ts"
4
+ import { commitContent } from "../src/content/git.ts"
5
+
6
+ /**
7
+ * Every published picture checked against the media library: a credit
8
+ * corrected or a picture replaced in the library itself, not through Tela,
9
+ * republished with the data sources carrying it, and committed so the site
10
+ * rebuilds what shows it. Nothing changed, nothing is written.
11
+ *
12
+ * tela media-sync
13
+ *
14
+ * Run on a timer beside the server for libraries edited directly.
15
+ */
16
+ const root = process.env.TELA_CONTENT_REPO
17
+ if (!root) {
18
+ console.error("Set TELA_CONTENT_REPO to the content repo checkout.")
19
+ process.exit(1)
20
+ }
21
+
22
+ const files = await readdir(join(root, "content", "media")).catch(() => [] as string[])
23
+ const ids = files.filter((name) => name.endsWith(".json")).map((name) => name.slice(0, -".json".length))
24
+ if (!ids.length) {
25
+ console.log("No published pictures to check.")
26
+ process.exit(0)
27
+ }
28
+
29
+ const exported = await republishPictures(ids, { root })
30
+ if (!exported.files.length) {
31
+ console.log(`${ids.length} published picture(s) checked; none changed.`)
32
+ process.exit(0)
33
+ }
34
+
35
+ const commit = await commitContent(exported, {
36
+ root,
37
+ message: `Update pictures from the media library\n\nRebuild: ${exported.cells.join(" ")}\n`,
38
+ push: process.env.TELA_PUSH !== "false",
39
+ })
40
+ console.log(`${ids.length} checked; updated ${exported.files.join(", ")}${commit.sha ? ` in ${commit.sha.slice(0, 7)}` : ""}.`)
41
+ process.exit(0)
@@ -0,0 +1,24 @@
1
+ import { republishEntries } from "../src/content/export.ts"
2
+ import { commitContent } from "../src/content/git.ts"
3
+
4
+ /**
5
+ * Every published entry written again under the rules publishing follows now,
6
+ * committed as one change: after Tela changes how content is written, so the
7
+ * content repo matches without anyone republishing page by page.
8
+ *
9
+ * tela republish [collection …]
10
+ */
11
+ const root = process.env.TELA_CONTENT_REPO
12
+ if (!root) {
13
+ console.error("Set TELA_CONTENT_REPO to the content repo checkout.")
14
+ process.exit(1)
15
+ }
16
+ const only = process.argv.slice(2)
17
+ const exported = await republishEntries({ root, ...(only.length ? { collections: only } : {}) })
18
+ const commit = await commitContent(exported, {
19
+ root,
20
+ message: `Republish under the current rules\n\nRebuild: ${exported.cells.join(" ")}\n`,
21
+ push: process.env.TELA_PUSH !== "false",
22
+ })
23
+ console.log(commit.sha ? `Rewrote ${commit.files.length} file(s) in ${commit.sha.slice(0, 7)}.` : "Everything already matches.")
24
+ process.exit(0)
package/src/api.ts CHANGED
@@ -148,12 +148,12 @@ export const api = {
148
148
 
149
149
  if (response.status === 401) {
150
150
  window.location.href = "/login"
151
- return { ok: false as const, body: "" }
151
+ return { ok: false as const, body: "", status: 401, headers: new Headers() }
152
152
  }
153
153
 
154
- return { ok: response.ok, body: await response.text() }
154
+ return { ok: response.ok, body: await response.text(), status: response.status, headers: response.headers }
155
155
  } catch {
156
- return { ok: false as const, body: "Could not reach the server." }
156
+ return { ok: false as const, body: "Could not reach the server.", status: 0, headers: new Headers() }
157
157
  }
158
158
  },
159
159