@taprootio/site-authoring 0.42.0 → 0.56.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 (80) hide show
  1. package/README.md +110 -12
  2. package/examples/riverbend-wellness/settings/site-publishing-preferences.json +3 -0
  3. package/examples/riverbend-wellness/settings/taproot-styles.json +11 -0
  4. package/package.json +4 -3
  5. package/src/api.js +242 -23
  6. package/src/appearance-contract.js +264 -3
  7. package/src/authored-tag-names.js +88 -0
  8. package/src/authors-contract.js +71 -3
  9. package/src/block-flow.js +103 -1
  10. package/src/brand-color.js +22 -0
  11. package/src/breadcrumb-artwork.js +234 -0
  12. package/src/breadcrumb-separators.js +11 -0
  13. package/src/changelog.json +160 -0
  14. package/src/chrome-features.js +6 -2
  15. package/src/chrome-input.js +1 -0
  16. package/src/chrome-paint-catalog-taproot.json +3 -3
  17. package/src/chrome-report.js +91 -12
  18. package/src/cli.js +136 -38
  19. package/src/constants.js +1 -0
  20. package/src/content/components.js +27 -4
  21. package/src/content/external-link.js +2 -1
  22. package/src/content/markdown.js +271 -101
  23. package/src/content/tiptap-prosemirror.ts +125 -43
  24. package/src/content/validate-document.js +4 -1
  25. package/src/content-inset.js +48 -0
  26. package/src/errors.js +1 -0
  27. package/src/espalier-shared.js +26 -0
  28. package/src/field-suggestions.js +40 -0
  29. package/src/fixture-init.js +22 -5
  30. package/src/font-catalog.js +11 -1
  31. package/src/footer-brand-inputs.js +22 -3
  32. package/src/footer-content.js +1 -0
  33. package/src/footer-contract.js +11 -0
  34. package/src/footer-cta-styles.js +6 -0
  35. package/src/footer-draft-hash.js +4 -2
  36. package/src/footer-fit.js +62 -15
  37. package/src/footer-workspace.js +44 -7
  38. package/src/latest-posts-tags.js +57 -0
  39. package/src/page-metadata.js +15 -13
  40. package/src/page-structure-checks.js +5 -0
  41. package/src/page-tag-badge-modes.js +6 -0
  42. package/src/page-tag-writes.js +158 -0
  43. package/src/page-type-tags.js +16 -0
  44. package/src/presentation-reference.js +297 -86
  45. package/src/recipe-page-options.js +22 -0
  46. package/src/recipe-step-contract.js +164 -0
  47. package/src/recipe-step-contract.json +65 -0
  48. package/src/reference-help.js +182 -79
  49. package/src/session.js +39 -24
  50. package/src/setting-reference.js +239 -48
  51. package/src/settings-catalog.js +63 -0
  52. package/src/site-check-findings.js +23 -5
  53. package/src/site-check-rules.json +1 -0
  54. package/src/site-health-findings.js +13 -13
  55. package/src/styling-fixed-values.js +71 -0
  56. package/src/tag-destination-warnings.js +35 -0
  57. package/src/template-token-reach.json +242 -0
  58. package/src/theme-proposals.js +18 -27
  59. package/src/theme-resolve.js +265 -23
  60. package/src/theme-validation.js +118 -7
  61. package/src/token-reach.js +222 -0
  62. package/src/typed-page-reference.js +94 -16
  63. package/src/typed-pages.js +233 -74
  64. package/src/verbs/authors.js +198 -33
  65. package/src/verbs/deploy.js +6 -0
  66. package/src/verbs/footer-push.js +30 -5
  67. package/src/verbs/forms-push.js +11 -3
  68. package/src/verbs/index.js +4 -2
  69. package/src/verbs/pages-delete.js +19 -10
  70. package/src/verbs/pages-push.js +225 -71
  71. package/src/verbs/plan.js +10 -4
  72. package/src/verbs/pull.js +324 -69
  73. package/src/verbs/staging-review.js +27 -1
  74. package/src/verbs/status.js +22 -0
  75. package/src/verbs/theme-push.js +93 -25
  76. package/src/verbs/theme-resolve.js +189 -55
  77. package/src/verbs/validate.js +6 -5
  78. package/src/workspace-check.js +35 -3
  79. package/src/workspace.js +73 -2
  80. package/test/fixtures/default-site-theme.json +516 -0
@@ -36,11 +36,13 @@ import { normalizeColumnsBody, validateColumnsBody } from "../content/free-form-
36
36
  import { autolinkWarnings } from "../content/link-warnings.js";
37
37
  import { placedFormKeys, readFormIndex, withFormIds } from "../form-references.js";
38
38
  import { workspaceFormKeys } from "../forms-workspace.js";
39
+ import { latestPostsTagProblems } from "../latest-posts-tags.js";
39
40
  import { ApiError } from "../transport.js";
40
41
  import { waitForProcessing } from "./media-upload.js";
41
42
  import { outcomeUnknown, SiteAuthoringError } from "../errors.js";
42
43
  import { DESCRIPTION_MAXIMUM_LENGTH, DESCRIPTION_WARN_LENGTH, descriptionWarnings } from "../page-metadata.js";
43
44
  import { stableJson } from "../footer-draft-hash.js";
45
+ import { outgoingTagIntent, preflightPageTagWrites, tagBaselineAfterWrite, translatePageTagRefusal } from "../page-tag-writes.js";
44
46
  import { CHECK_AREA, collectProblems, planStale, problemsOf, refuseProblems } from "../problems.js";
45
47
  import { RUNTIME_MIRROR_PATH_REASON, isRuntimeMirrorPath } from "../reserved-paths.js";
46
48
  import { boundedByBytes, openSession, successResult, warnIfExternalWritesPaused } from "../session.js";
@@ -53,8 +55,10 @@ import {
53
55
  generatedMarkdownFault,
54
56
  legalMarkdownFault,
55
57
  legalIdentity,
58
+ supportsAuthoredTags,
56
59
  workspaceDocumentFromPage,
57
60
  TEMPLATE_LEGAL,
61
+ TEMPLATE_PLACE_REVIEW,
58
62
  generatedPageDescription,
59
63
  generatedPageTitle,
60
64
  placedVideoIds,
@@ -63,12 +67,16 @@ import {
63
67
  PAGE_TEMPLATES,
64
68
  requireTemplateName,
65
69
  RETIRED_GENERATED_PAGE_KINDS,
70
+ sentDisplayAuthor,
66
71
  sentDisplayDate,
72
+ sentShowOnProfile,
67
73
  TEMPLATE_FREE_FORM,
68
74
  TEMPLATE_GENERATED,
69
75
  templateFrontMatterFault,
70
76
  typedDocumentFromJson,
71
77
  typedDocumentFromMarkdown,
78
+ requireRecipeStepDocuments,
79
+ TEMPLATE_RECIPE,
72
80
  unusedCoverImageId,
73
81
  unsupportedRestrictedNode,
74
82
  wirePageFields,
@@ -85,6 +93,7 @@ import {
85
93
  deleteWorkspaceFile,
86
94
  internalPageObservedRevisionFile,
87
95
  MEDIA_MANIFEST_FILE_NAME,
96
+ normalizeAuthoredTagBaseline,
88
97
  normalizePageBodyRevision,
89
98
  normalizePagePath,
90
99
  PAGE_SOURCE_EXTENSIONS,
@@ -108,8 +117,10 @@ import {
108
117
  canonicalDocumentHash,
109
118
  workspaceContentHash,
110
119
  workspaceFileExists,
120
+ workspacePageSourceBodyHash,
111
121
  writeManifest,
112
122
  writeWorkspaceJson,
123
+ mediaReferenceCandidates,
113
124
  } from "../workspace.js";
114
125
 
115
126
  /**
@@ -191,6 +202,7 @@ const RESOLUTION_METADATA_CODES = new Set([
191
202
  "pages.front_matter_invalid",
192
203
  "pages.front_matter_unknown",
193
204
  "pages.front_matter_duplicate",
205
+ "pages.display_author_invalid",
194
206
  "pages.metadata_missing",
195
207
  "pages.path_missing",
196
208
  "pages.path_unsupported",
@@ -215,7 +227,7 @@ function unquote(value) {
215
227
  * dropping an unrecognized key is how authored metadata disappears without a
216
228
  * trace, and the server would never notice.
217
229
  */
218
- function parseFrontMatter(source, file) {
230
+ export function parseFrontMatter(source, file) {
219
231
  const lines = source.split(/\r?\n/u);
220
232
  if (lines[0]?.trim() !== FRONT_MATTER_FENCE) {
221
233
  throw documentError(
@@ -237,11 +249,12 @@ function parseFrontMatter(source, file) {
237
249
  // as though it were the only one. The caller raises the fault for any page
238
250
  // it actually intends to send.
239
251
  const values = new Map();
252
+ let tagsLine;
240
253
  let fault;
241
254
  const record = (candidate) => {
242
255
  fault ??= candidate;
243
256
  };
244
- for (const line of lines.slice(1, closing)) {
257
+ for (const [index, line] of lines.slice(1, closing).entries()) {
245
258
  if (line.trim() === "" || line.trimStart().startsWith("#")) continue;
246
259
  const match = FRONT_MATTER_ENTRY.exec(line);
247
260
  if (!match) {
@@ -262,8 +275,20 @@ function parseFrontMatter(source, file) {
262
275
  ));
263
276
  continue;
264
277
  }
278
+ // A bare `displayAuthor:` reads as empty, and empty clears the pen name. Only a quoted empty value may
279
+ // do that, so an unfinished line cannot put the member's own byline back on the page (TR01402).
280
+ if (key === "displayAuthor" && rawValue.trim() === "") {
281
+ record(documentError(
282
+ "pages.display_author_invalid",
283
+ `'${file}' declares displayAuthor with no value. Write displayAuthor: "" to clear the display author, `
284
+ + "or a site author's handle.",
285
+ key,
286
+ ));
287
+ continue;
288
+ }
265
289
  const seen = values.get(key);
266
290
  if (seen === undefined) {
291
+ if (key === "tags") tagsLine = index + 1;
267
292
  values.set(key, [unquote(rawValue)]);
268
293
  continue;
269
294
  }
@@ -306,6 +331,8 @@ function parseFrontMatter(source, file) {
306
331
  candidates,
307
332
  fault,
308
333
  template,
334
+ tagsLine,
335
+ markdownFirstLine: closing + 2,
309
336
  markdown: lines.slice(closing + 1).join("\n"),
310
337
  };
311
338
  }
@@ -356,21 +383,6 @@ function unwrapProseMirrorDocument(parsed, file) {
356
383
  );
357
384
  }
358
385
 
359
- /**
360
- * The candidate keys a Markdown image reference could match in the media
361
- * manifest. Authors write `./media/hero.png`, `media/hero.png`, or
362
- * `/media/hero.png` for the same file, and a resolver that accepted only one
363
- * spelling would refuse content that is plainly correct.
364
- */
365
- function mediaReferenceCandidates(reference) {
366
- if (typeof reference !== "string" || reference === "") return [];
367
- const withoutQuery = reference.split("#")[0].split("?")[0];
368
- const stripped = withoutQuery.replace(/^\.\//u, "").replace(/^\/+/u, "");
369
- const candidates = new Set([reference, withoutQuery, stripped]);
370
- if (!stripped.includes("/")) candidates.add(`media/${stripped}`);
371
- return [...candidates];
372
- }
373
-
374
386
  function makeResolveImage(mediaManifest, file) {
375
387
  return async (reference) => {
376
388
  for (const candidate of mediaReferenceCandidates(reference)) {
@@ -431,8 +443,8 @@ function requireContentFunctions(content) {
431
443
  return content;
432
444
  }
433
445
 
434
- function assertValid(content, document_, file, { mayBeEmpty = false } = {}) {
435
- const outcome = content.validateDocument(document_);
446
+ function assertValid(content, document_, file, { mayBeEmpty = false, recipeStep = false } = {}) {
447
+ const outcome = content.validateDocument(document_, { checkLinkValues: !recipeStep });
436
448
  const reported = outcome === null || typeof outcome !== "object" ? undefined : outcome.errors;
437
449
  if (!Array.isArray(reported)) {
438
450
  throw new SiteAuthoringError(
@@ -517,6 +529,8 @@ export async function readWorkspacePageSource({ workspaceDir, file, manifestEntr
517
529
  const source = bytes.toString("utf8");
518
530
 
519
531
  let markdown;
532
+ let markdownFirstLine;
533
+ let markdownBodyHash;
520
534
  let fault;
521
535
  let pathCandidates = [];
522
536
  let title;
@@ -536,6 +550,12 @@ export async function readWorkspacePageSource({ workspaceDir, file, manifestEntr
536
550
  declaredAuthor = frontMatter.fields.get("author") || manifestEntry?.author;
537
551
  declaredPath = frontMatter.fields.has("path") ? frontMatter.fields.get("path") : manifestEntry?.path;
538
552
  markdown = frontMatter.markdown;
553
+ markdownFirstLine = frontMatter.markdownFirstLine;
554
+ if (frontMatter.tagsLine !== undefined) {
555
+ const lines = source.split(/(?<=\n)/u);
556
+ lines.splice(frontMatter.tagsLine, 1);
557
+ markdownBodyHash = workspaceContentHash(lines.join(""));
558
+ }
539
559
  fault = frontMatter.fault;
540
560
  pathCandidates = frontMatter.candidates.get("path") ?? [];
541
561
  } else {
@@ -608,7 +628,9 @@ export async function readWorkspacePageSource({ workspaceDir, file, manifestEntr
608
628
  fields,
609
629
  sourceFormat: isMarkdown ? PAGE_SOURCE_FORMAT_MARKDOWN : PAGE_SOURCE_FORMAT_PROSEMIRROR,
610
630
  sourceHash: workspaceContentHash(bytes),
631
+ markdownBodyHash,
611
632
  markdown,
633
+ markdownFirstLine,
612
634
  text: source,
613
635
  };
614
636
  }
@@ -657,29 +679,33 @@ export function requireReconciledRevision({ file, pagePath, target, entry, obser
657
679
  }
658
680
 
659
681
  /**
660
- * The same guard for a typed page's display date, which the revision does not
661
- * cover. It refuses only when this push would change a date that moved on the
662
- * site since the workspace last saw it: an unset date is left alone by the
663
- * update, and a pull that showed the operator a conflict has already handed
664
- * them the site's version.
682
+ * The same guard for a typed page's display date, display author and showOnProfile, which the
683
+ * revision does not cover. It refuses only when this push would change a value
684
+ * that moved on the site since the workspace last saw it: an unset value is
685
+ * left alone by the update, and a pull that showed the operator a conflict has
686
+ * already handed them the site's version. `key` names the value in the
687
+ * document, the target, the baseline and the observed record, and `label` the
688
+ * value in the refusal (TR01402).
665
689
  */
666
- function requireReconciledDisplayDate({ file, pagePath, target, entry, document_, observed }) {
667
- const sent = documentTemplate(document_) === TEMPLATE_FREE_FORM ? undefined : document_.displayDate;
668
- const recorded = entry?.baseline?.displayDate;
669
- const live = target.displayDate;
690
+ function requireReconciledPageValue(key, label, { file, pagePath, target, entry, document_, observed }) {
691
+ const sent = documentTemplate(document_) === TEMPLATE_FREE_FORM ? undefined : document_[key];
692
+ const recorded = entry?.baseline?.[key];
693
+ const live = target[key];
670
694
  if (sent === undefined || recorded === undefined) return;
671
- // A refused pull records the date it showed. Only that date is overridable: a
672
- // page whose date moved again since is refused again, like a moved revision.
673
- // A record from a pull that named no date still counts as having shown it.
674
- if (observed !== undefined && (observed.displayDate === undefined || observed.displayDate === live)) return;
675
- if (typeof recorded !== "string" || live === recorded || live === sent) return;
695
+ // A refused pull records the value it showed. Only that value is overridable: a
696
+ // page whose value moved again since is refused again, like a moved revision.
697
+ // A record from a pull that named no value still counts as having shown it.
698
+ if (observed !== undefined && (observed[key] === undefined || observed[key] === live)) return;
699
+ if (live === recorded || live === sent) return;
700
+ // A flag reads as true or false. An empty text value reads as "not set": "none" is a handle a site may use.
701
+ const shown = (value) => typeof value === "boolean" ? String(value) : value ? `'${value}'` : "not set";
676
702
  throw new SiteAuthoringError(
677
703
  "pages.push_conflict",
678
- `Page '${pagePath || "/"}' has a different display date on the site (${live || "none"}) than the one this `
679
- + `workspace last reconciled with (${recorded || "none"}), and '${file}' would replace it with `
680
- + `${sent || "none"}. No page was pushed. Run 'taproot-site pull' to adopt the site's date, or delete `
704
+ `Page '${pagePath || "/"}' has a different ${label} on the site (${shown(live)}) than the one this `
705
+ + `workspace last reconciled with (${shown(recorded)}), and '${file}' would replace it with `
706
+ + `${shown(sent)}. No page was pushed. Run 'taproot-site pull' to adopt the site's ${label}, or delete `
681
707
  + `'${file}' and pull again.`,
682
- { field: file, alternatives: [recorded, live] },
708
+ { field: file, alternatives: [String(recorded), String(live)] },
683
709
  );
684
710
  }
685
711
 
@@ -749,7 +775,11 @@ export function requireCompletePageMetadata(source) {
749
775
  * wire carries — converting Markdown through the bounded subset and resolving
750
776
  * its media, or unwrapping an authored document.
751
777
  */
752
- export async function convertWorkspacePageSource({ source, mediaManifest, content: injectedContent }) {
778
+ export async function convertWorkspacePageSource(options) {
779
+ return (await convertedWorkspacePageSource(options)).document;
780
+ }
781
+
782
+ async function convertedWorkspacePageSource({ source, mediaManifest, content: injectedContent }) {
753
783
  const content = requireContentFunctions(await loadContentModule(injectedContent));
754
784
  const { file } = source;
755
785
  if (source.sourceFormat === PAGE_SOURCE_FORMAT_MARKDOWN) {
@@ -761,15 +791,19 @@ export async function convertWorkspacePageSource({ source, mediaManifest, conten
761
791
  file,
762
792
  );
763
793
  };
764
- if (source.template === TEMPLATE_FREE_FORM) return await convert(source.markdown);
765
- return await typedDocumentFromMarkdown({
766
- template: source.template,
767
- fields: source.fields,
768
- markdown: source.markdown,
769
- file,
770
- convert,
771
- resolveImage,
772
- });
794
+ const document = source.template === TEMPLATE_FREE_FORM
795
+ ? await convert(source.markdown)
796
+ : await typedDocumentFromMarkdown({
797
+ template: source.template,
798
+ fields: source.fields,
799
+ markdown: source.markdown,
800
+ file,
801
+ convert,
802
+ convertStep: (markdown, firstLine) => content.markdownToProseMirror(markdown, { resolveImage, recipeStep: true, firstLine }),
803
+ firstLine: source.markdownFirstLine,
804
+ resolveImage,
805
+ });
806
+ return { document };
773
807
  }
774
808
  let parsed;
775
809
  try {
@@ -777,8 +811,21 @@ export async function convertWorkspacePageSource({ source, mediaManifest, conten
777
811
  } catch {
778
812
  throw documentError("pages.document_shape", `'${file}' is not valid JSON.`, file);
779
813
  }
780
- if (source.template !== TEMPLATE_FREE_FORM) return typedDocumentFromJson(parsed, file);
781
- return normalizeColumnsBody(unwrapProseMirrorDocument(parsed, file)).body;
814
+ if (source.template !== TEMPLATE_FREE_FORM) {
815
+ const document = typedDocumentFromJson(parsed, file);
816
+ const sourceBodyHash = supportsAuthoredTags(source.template) ? workspacePageSourceBodyHash(parsed) : undefined;
817
+ return { document, sourceBodyHash };
818
+ }
819
+ if (parsed !== null && typeof parsed === "object" && Object.hasOwn(parsed, "tags")) {
820
+ throw documentError("pages.tags_unsupported", `'${file}' declares tags, which the free-form template does not accept.`, "tags");
821
+ }
822
+ // Dropping one of these silently would publish the page under the member's own byline (TR01402, TR01403).
823
+ for (const key of ["displayAuthor", "showOnProfile"]) {
824
+ if (parsed !== null && typeof parsed === "object" && Object.hasOwn(parsed, key)) {
825
+ throw documentError("pages.document_shape", `'${file}' declares ${key}, which the free-form template does not accept.`, key);
826
+ }
827
+ }
828
+ return { document: normalizeColumnsBody(unwrapProseMirrorDocument(parsed, file)).body };
782
829
  }
783
830
 
784
831
  /**
@@ -820,19 +867,19 @@ export async function validateWorkspacePageDocument({
820
867
  getSharedThemeContexts,
821
868
  }) {
822
869
  const content = requireContentFunctions(await loadContentModule(injectedContent));
823
- // A typed page carries several ProseMirror documents (an introduction, each
824
- // recipe step); every one goes through the same vocabulary and context checks
825
- // a free-form body does.
870
+ if (documentTemplate(document_) === TEMPLATE_RECIPE) {
871
+ requireRecipeStepDocuments(document_.data.instructionSections ?? [], file);
872
+ }
826
873
  const unusedCover = unusedCoverImageId(document_);
827
874
  if (unusedCover !== undefined) {
828
875
  throw documentError(
829
876
  "pages.cover_image_unused",
830
877
  `${COVER_IMAGE_UNUSED_MESSAGE} '${file}' selects cover image ${unusedCover}, but no image in the page's own `
831
- + "content uses it: place that image in the body (or introduction, steps, or album images), or remove coverImage.",
878
+ + "content uses it: place that image in the body, introduction or album images, or remove coverImage.",
832
879
  `${file}:coverImageId`,
833
880
  );
834
881
  }
835
- for (const { doc, path, mayBeEmpty, restricted } of contentDocuments(document_)) {
882
+ for (const { doc, path, mayBeEmpty, restricted, recipeStep } of contentDocuments(document_)) {
836
883
  const location = path === "" ? file : `${file}:${path}`;
837
884
  const columns = validateColumnsBody(doc, { allowColumns: documentTemplate(document_) === TEMPLATE_FREE_FORM });
838
885
  if (columns.errors.length > 0) {
@@ -840,12 +887,12 @@ export async function validateWorkspacePageDocument({
840
887
  throw documentError("pages.document_invalid", `'${location}' has an invalid columns layout. Columns are available only inside sections of a free-form page.`, `${location}:${first.path}`)
841
888
  .withProblems(columns.errors.map(error => ({ code: error.code, field: `${location}:${error.path}`, message: "Use a valid columns layout in a free-form section." })));
842
889
  }
843
- assertValid(content, doc, location, { mayBeEmpty });
890
+ assertValid(content, doc, location, { mayBeEmpty, recipeStep });
844
891
  const unsupported = restricted ? unsupportedRestrictedNode(doc) : undefined;
845
892
  if (unsupported !== undefined) {
846
893
  throw documentError(
847
894
  "pages.node_unsupported_for_template",
848
- `'${location}' uses the '${unsupported}' node, which a ${documentTemplate(document_)} introduction or step `
895
+ `'${location}' uses the '${unsupported}' node, which a ${documentTemplate(document_)} introduction `
849
896
  + "does not accept. Put that content in a free-form page or an article, or remove it.",
850
897
  location,
851
898
  );
@@ -1036,6 +1083,11 @@ export function liveAuthorsRefresher({ client, workspaceDir, siteId, write, onPr
1036
1083
  };
1037
1084
  }
1038
1085
 
1086
+ /** The display author a write left on the page: what the site reports, else what was declared. */
1087
+ function displayAuthorAfterWrite(page, summary) {
1088
+ return summary.displayAuthor || page.document.displayAuthor || "";
1089
+ }
1090
+
1039
1091
  /**
1040
1092
  * Decides what a page says about its author before anything is sent
1041
1093
  * (TR01196). `declared` is what the source (or, for a `.pm.json` page, its
@@ -1102,6 +1154,30 @@ async function resolvePageAuthor({ file, pagePath, declared, recorded, markdown,
1102
1154
  return { author: reference.value, sendAuthor: true, unverified };
1103
1155
  }
1104
1156
 
1157
+ /**
1158
+ * Checks a declared display author against the site's authors (TR01402), as
1159
+ * `resolvePageAuthor` checks a new author: `authors.json` first, then, online,
1160
+ * the site's own list once, refusing only a handle the site really lacks. An
1161
+ * offline run cannot ask, so it flags the handle as unverified. The empty value
1162
+ * clears the display author and a value the site already holds needs no check.
1163
+ */
1164
+ async function checkDisplayAuthor({ file, declared, held, knownAuthors, refreshAuthors }) {
1165
+ if (declared === undefined || declared === "" || declared === held) return {};
1166
+ let known = authorKnown(await knownAuthors(), declared);
1167
+ if (known === true) return {};
1168
+ if (refreshAuthors === undefined) return known === false ? { unverified: true } : {};
1169
+ known = authorKnown(await refreshAuthors(), declared);
1170
+ if (known === false) {
1171
+ throw documentError(
1172
+ "pages.display_author_unknown",
1173
+ `'${file}' names displayAuthor '${declared}', who is not one of the site's authors. Run 'taproot-site authors `
1174
+ + "list' to see the handles, or 'taproot-site authors add' to create a site author.",
1175
+ file,
1176
+ );
1177
+ }
1178
+ return {};
1179
+ }
1180
+
1105
1181
  /**
1106
1182
  * Phase one over the workspace's page sources (TR01002): resolve which file is
1107
1183
  * each page's one source, convert and validate it, and decide create, update,
@@ -1354,7 +1430,7 @@ export async function planPages({
1354
1430
  );
1355
1431
  return;
1356
1432
  }
1357
- const document_ = await convertWorkspacePageSource({ source, mediaManifest, content });
1433
+ const { document: document_, sourceBodyHash } = await convertedWorkspacePageSource({ source, mediaManifest, content });
1358
1434
  if (documentTemplate(document_) === TEMPLATE_LEGAL && target === undefined && manifestEntry?.pageId !== undefined) {
1359
1435
  throw documentError("pages.legal_missing", `'${file}' tracks a legal page that the site no longer lists. Pull and reconcile it before creating another page.`, file);
1360
1436
  }
@@ -1364,6 +1440,9 @@ export async function planPages({
1364
1440
  // fields the workspace never restated; without it the whole-object
1365
1441
  // UpdatePage sends "" and false and silently clears both.
1366
1442
  const targetEntry = target === undefined ? undefined : manifestByPageId.get(target.pageId);
1443
+ const baseline = targetEntry?.baseline;
1444
+ const tagBaseline = normalizeAuthoredTagBaseline(baseline);
1445
+ const tagIntent = outgoingTagIntent(document_.tags, tagBaseline?.authoredTagSlugs);
1367
1446
  const description = generated
1368
1447
  // The manifest's title and description are what the site reported; the owner's are in the document.
1369
1448
  ? generatedPageDescription(document_.data, declaredDescription ?? targetEntry?.description ?? "")
@@ -1374,29 +1453,45 @@ export async function planPages({
1374
1453
  // already covers; only a .pm.json page keeps one in the manifest, where
1375
1454
  // the key has to see it. Absent, the key is the one it always was.
1376
1455
  const markdownSource = source.sourceFormat === PAGE_SOURCE_FORMAT_MARKDOWN;
1377
- const contentKeyFor = (author) => pageContentKey(
1378
- source.sourceHash,
1456
+ const markdownDocumentHash = !markdownSource
1457
+ ? ""
1458
+ : document_.tags === undefined
1459
+ ? canonicalDocumentHash(document_)
1460
+ : workspacePageSourceBodyHash(document_);
1461
+ const contentKeyFor = (author, inputHash = source.markdownBodyHash ?? source.sourceHash) => pageContentKey(
1462
+ inputHash,
1379
1463
  {
1380
1464
  title: sentTitle,
1381
1465
  path: pagePath,
1382
1466
  description: sentDescription,
1383
1467
  author: markdownSource ? "" : author,
1384
1468
  },
1385
- markdownSource ? canonicalDocumentHash(document_) : "",
1469
+ markdownDocumentHash,
1386
1470
  );
1387
1471
  // A generated page has no author, so its key is final here. Every other
1388
1472
  // page's key waits for the author resolved below.
1389
1473
  let contentKey = contentKeyFor("");
1474
+ const bodyMatches = (author) => {
1475
+ if (baseline?.contentKey === contentKey) return true;
1476
+ if (
1477
+ sourceBodyHash === undefined || sourceBodyHash !== baseline?.sourceBodyHash
1478
+ || (document_.tags === undefined && !Array.isArray(tagBaseline?.authoredTagSlugs))
1479
+ ) return false;
1480
+ // Tag-bearing JSON can keep its body and metadata through edits to the tag labels.
1481
+ return baseline.contentKey === contentKeyFor(author, sourceBodyHash)
1482
+ || (baseline.sourceHash !== undefined && baseline.contentKey === contentKeyFor(author, baseline.sourceHash));
1483
+ };
1390
1484
  // The source and everything sent with it match what the site last agreed
1391
1485
  // to, so sending again would only turn an approved page back into a draft.
1392
1486
  // Not when the operator was shown a conflict for this page (the record
1393
1487
  // exists to let this push reassert the source), and not when the source
1394
1488
  // moved or changed format, which the send re-registers in the manifest.
1395
- const isUnchanged = (record) => target !== undefined
1396
- && targetEntry?.baseline?.contentKey === contentKey
1489
+ const isUnchanged = (record, author = "") => target !== undefined
1490
+ && tagIntent === undefined
1397
1491
  && record === undefined
1398
- && targetEntry.file === file
1399
- && targetEntry.sourceFormat === source.sourceFormat;
1492
+ && targetEntry?.file === file
1493
+ && targetEntry.sourceFormat === source.sourceFormat
1494
+ && bodyMatches(author);
1400
1495
  // An untouched generated page is not this push's to judge. Taproot
1401
1496
  // moves its revision and its path on its own (a folder that
1402
1497
  // gained a post), and refusing the whole push for a page nothing here
@@ -1459,8 +1554,10 @@ export async function planPages({
1459
1554
  };
1460
1555
  if (sourceTemplate === TEMPLATE_LEGAL) legalRevisionGuard = guard;
1461
1556
  else {
1462
- requireReconciledRevision(guard);
1463
- requireReconciledDisplayDate({ ...guard, document_, observed });
1557
+ if (tagIntent === undefined) requireReconciledRevision(guard);
1558
+ requireReconciledPageValue("displayDate", "display date", { ...guard, document_, observed });
1559
+ requireReconciledPageValue("displayAuthor", "display author", { ...guard, document_, observed });
1560
+ requireReconciledPageValue("showOnProfile", "showOnProfile setting", { ...guard, document_, observed });
1464
1561
  }
1465
1562
  }
1466
1563
  }
@@ -1513,10 +1610,20 @@ export async function planPages({
1513
1610
  knownAuthors: getRecordedAuthors,
1514
1611
  refreshAuthors: getLiveAuthors,
1515
1612
  });
1613
+ const displayAuthor = generated
1614
+ ? {}
1615
+ : await checkDisplayAuthor({
1616
+ file,
1617
+ declared: document_.displayAuthor,
1618
+ held: online && target !== undefined ? target.displayAuthor : baseline?.displayAuthor,
1619
+ knownAuthors: getRecordedAuthors,
1620
+ refreshAuthors: getLiveAuthors,
1621
+ });
1516
1622
  contentKey = contentKeyFor(authorship.author);
1517
1623
  // An author the site no longer holds is a change to send, however the
1518
1624
  // source compares with the record.
1519
- const unchanged = isUnchanged(observedRecord) && !(online && target !== undefined && authorship.sendAuthor);
1625
+ const unchanged = isUnchanged(observedRecord, authorship.author)
1626
+ && !(online && target !== undefined && authorship.sendAuthor);
1520
1627
  if (documentTemplate(document_) === TEMPLATE_LEGAL && !unchanged && online) {
1521
1628
  if (legalRevisionGuard !== undefined) requireReconciledRevision(legalRevisionGuard);
1522
1629
  if (!legalDrafts) {
@@ -1547,6 +1654,18 @@ export async function planPages({
1547
1654
  file,
1548
1655
  );
1549
1656
  }
1657
+ // The byline the page will have after this push (TR01402): the declared
1658
+ // display author, none after an explicit clear, else the site's value.
1659
+ const declaredDisplayAuthor = document_.displayAuthor;
1660
+ const siteDisplayAuthor = (online && target !== undefined ? target.displayAuthor : baseline?.displayAuthor) ?? "";
1661
+ const reviewAuthorMissing = documentTemplate(document_) === TEMPLATE_PLACE_REVIEW
1662
+ && authorship.author === ""
1663
+ && (declaredDisplayAuthor ?? siteDisplayAuthor) === ""
1664
+ // The site's own flag decides for a page it already has, so a display author cleared by this
1665
+ // push shows its warning on the next run, once the site reports the page without a credit.
1666
+ && (online && target !== undefined
1667
+ ? target.reviewAuthorMissing === true
1668
+ : targetEntry?.pageId === undefined || targetEntry.reviewAuthorMissing === true);
1550
1669
  planned.push({
1551
1670
  file,
1552
1671
  pagePath,
@@ -1559,10 +1678,17 @@ export async function planPages({
1559
1678
  description: sentDescription,
1560
1679
  author: authorship.author,
1561
1680
  sendAuthor: authorship.sendAuthor,
1681
+ reviewAuthorMissing,
1562
1682
  ...(authorship.unverified === true ? { authorUnverified: true } : {}),
1683
+ ...(displayAuthor.unverified === true ? { displayAuthorUnverified: true } : {}),
1563
1684
  document: document_,
1564
1685
  sourceFormat: source.sourceFormat,
1565
1686
  sourceHash: source.sourceHash,
1687
+ sourceBodyHash,
1688
+ tagIntent,
1689
+ ...(tagIntent === undefined || target === undefined ? {} : {
1690
+ tagUpdate: { target, tagBaseline, bodyRevision: baseline?.revision },
1691
+ }),
1566
1692
  pageId: target?.pageId,
1567
1693
  // The live revision this page would be sent against; `plan` binds it
1568
1694
  // into its hash so a concurrent edit invalidates the plan.
@@ -1595,6 +1721,20 @@ export function staleGeneratedSourcesField(staleGenerated) {
1595
1721
  : { staleGeneratedSources: { total: staleGenerated.length, ...reportedList("items", staleGenerated, LIST_BYTES) } };
1596
1722
  }
1597
1723
 
1724
+ /** The live target and any tag write that apply must still find after earlier steps. */
1725
+ export function plannedPageWriteIdentity(page) {
1726
+ return [
1727
+ page.pageId ?? "",
1728
+ page.revision ?? "",
1729
+ page.action,
1730
+ ...(page.tagIntent === undefined ? [] : [
1731
+ page.tagIntent.names,
1732
+ page.tagFields?.expectedAuthoredTagRevision ?? "",
1733
+ page.tagFields?.expectedBodyRevision ?? "",
1734
+ ]),
1735
+ ];
1736
+ }
1737
+
1598
1738
  /** What a dry run or a plan reports for one planned page. */
1599
1739
  export function plannedPageItem(page) {
1600
1740
  return { file: page.file, path: displayPagePath(page.pagePath), action: page.unchanged ? "unchanged" : page.action };
@@ -1734,6 +1874,8 @@ export async function pagesPush(invocation) {
1734
1874
  onProgress,
1735
1875
  });
1736
1876
  const { planned, targeted, unresolved, staleGenerated } = plan;
1877
+ await preflightPageTagWrites(client, siteId, plan, invocation.pageTagCapabilities);
1878
+ plan.problems.push(...latestPostsTagProblems(planned, manifest, { sendingOnly: true }));
1737
1879
  // A page that places a video names it by id, and only the library knows
1738
1880
  // whether that id is one of this site's videos. Asked once for the whole
1739
1881
  // push, before anything is written, so a page cannot be sent that
@@ -1753,8 +1895,8 @@ export async function pagesPush(invocation) {
1753
1895
  const byFile = new Map(planned.map((page) => [page.file, page]));
1754
1896
  for (const [file, expected] of invocation.plannedPages) {
1755
1897
  const page = byFile.get(file);
1756
- if (page === undefined || stableJson([page.pageId ?? "", page.revision ?? "", page.action]) !== expected) {
1757
- throw planStale(`'${file}'`, file);
1898
+ if (page === undefined || stableJson(plannedPageWriteIdentity(page)) !== expected) {
1899
+ throw planStale(`'${file}'`, file).withProblems(plan.problems);
1758
1900
  }
1759
1901
  }
1760
1902
  const unplanned = planned.find((page) => !page.unchanged && !invocation.plannedPages.has(page.file));
@@ -1821,6 +1963,7 @@ export async function pagesPush(invocation) {
1821
1963
  shortDescription: page.description,
1822
1964
  template: wireTemplate(withFormIds(page.document, placedForms.idByKey)),
1823
1965
  ...wirePageFields(page.document),
1966
+ ...page.tagFields,
1824
1967
  // Only a name the site has not been told: repeating the author a page
1825
1968
  // already has would let a later change of that person's permissions
1826
1969
  // refuse a push that changes nothing about authorship.
@@ -1840,7 +1983,7 @@ export async function pagesPush(invocation) {
1840
1983
  ? await createPage(client, { siteId, ...fields })
1841
1984
  : await updatePage(client, page.pageId, { pageId: page.pageId, ...fields });
1842
1985
  } catch (error) {
1843
- throw translateAuthorRefusal(error, page.file);
1986
+ throw translateAuthorRefusal(translatePageTagRefusal(error, page), page.file);
1844
1987
  }
1845
1988
  attempting = undefined;
1846
1989
  manifestDirty = true;
@@ -1855,6 +1998,7 @@ export async function pagesPush(invocation) {
1855
1998
  action: page.action,
1856
1999
  status: summary.status,
1857
2000
  ...(page.author === "" ? {} : { author: page.author }),
2001
+ ...(displayAuthorAfterWrite(page, summary) === "" ? {} : { displayAuthor: displayAuthorAfterWrite(page, summary) }),
1858
2002
  });
1859
2003
  // `entry?.` because a hand-edited manifest can hold a null in the list,
1860
2004
  // and a raw TypeError here would collapse to an opaque `site.failed`
@@ -1900,11 +2044,18 @@ export async function pagesPush(invocation) {
1900
2044
  // this workspace made itself.
1901
2045
  baseline: {
1902
2046
  sourceHash: page.sourceHash,
2047
+ ...(page.sourceBodyHash === undefined ? {} : { sourceBodyHash: page.sourceBodyHash }),
1903
2048
  contentKey: page.contentKey,
2049
+ ...tagBaselineAfterWrite(record.baseline, page, summary),
1904
2050
  ...(summary.bodyRevision === undefined ? {} : { revision: summary.bodyRevision }),
1905
2051
  // Recorded for the pages whose push sends a date, so the next push
1906
2052
  // can tell a date the site changed from one it already holds.
1907
2053
  ...(sentDisplayDate(page.templateType) ? { displayDate: summary.displayDate } : {}),
2054
+ // Recorded from the handle the write's answer returns, so a second
2055
+ // push with no pull between compares with what the site holds now.
2056
+ ...(sentDisplayAuthor(page.templateType) ? { displayAuthor: summary.displayAuthor } : {}),
2057
+ // The value the write's answer returns, in the workspace's sense (TR01403).
2058
+ ...(sentShowOnProfile(page.templateType) ? { showOnProfile: summary.showOnProfile } : {}),
1908
2059
  ...(heldAuthor === "" ? {} : { author: heldAuthor }),
1909
2060
  },
1910
2061
  pendingApproval: true,
@@ -1912,6 +2063,8 @@ export async function pagesPush(invocation) {
1912
2063
  // What the source names, kept beside the site's own for a .pm.json
1913
2064
  // page, whose manifest entry is the only place it is written down.
1914
2065
  if (documentTemplate(page.document) === TEMPLATE_LEGAL) record.legal = legalIdentity(page.document.data);
2066
+ if (summary.reviewAuthorMissing === undefined) delete record.reviewAuthorMissing;
2067
+ else record.reviewAuthorMissing = summary.reviewAuthorMissing && page.author === "";
1915
2068
  if (page.author === "") delete record.author;
1916
2069
  else record.author = page.author;
1917
2070
  if (existing === undefined) manifest.pages.push(record);
@@ -1988,7 +2141,8 @@ export async function pagesPush(invocation) {
1988
2141
 
1989
2142
  // Pages are authorless unless a source names an author, and an owner
1990
2143
  // otherwise finds the missing byline only after publishing (TR01196).
1991
- const authorless = applied.filter((entry) => entry.action === "created" && entry.author === undefined);
2144
+ const authorless = applied.filter((entry) =>
2145
+ entry.action === "created" && entry.author === undefined && entry.displayAuthor === undefined);
1992
2146
  if (authorless.length > 0) {
1993
2147
  onProgress(
1994
2148
  `${authorless.length} page(s) were created without an author, so they publish with no byline. To credit one, `