@anthusai/papyrus 1.0.0-next.2 → 1.0.0-next.21
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/amplify/auth/resource.js +17 -4
- package/amplify/auth/resource.ts +21 -4
- package/amplify/data/resource.js +52 -70
- package/amplify/data/resource.ts +57 -70
- package/amplify/data/schema.js +52 -58
- package/amplify/data/schema.ts +57 -58
- package/amplify/functions/console-chat-responder/py/execute_tactus_runner.py +0 -10
- package/amplify/functions/console-chat-responder/resource.js +0 -7
- package/amplify/functions/console-chat-responder/resource.ts +0 -8
- package/amplify/functions/console-chat-responder/src/main.rs +0 -9
- package/amplify/functions/content-actions/handler.py +149 -0
- package/amplify/functions/content-actions/requirements.txt +4 -0
- package/amplify/functions/content-actions/resource.js +40 -0
- package/amplify/functions/content-actions/resource.ts +54 -0
- package/amplify/functions/shared/python-bundle.js +17 -2
- package/amplify/functions/shared/python-bundle.ts +23 -2
- package/amplify/rebuild-trigger-settings.js +22 -0
- package/amplify/rebuild-trigger-settings.ts +42 -0
- package/amplify/site-backend-config.ts +12 -1
- package/amplify/site-backend.js +51 -27
- package/amplify/site-backend.ts +66 -34
- package/amplify/storage/resource.js +3 -0
- package/amplify/storage/resource.ts +3 -0
- package/app/%5F_preview/[[...path]]/route.ts +8 -0
- package/app/[year]/[month]/[day]/[articleSlug]/page.tsx +4 -2
- package/app/[year]/[month]/[day]/edition-route-page.tsx +2 -0
- package/app/api/revalidate/route.ts +8 -7
- package/app/articles/[slug]/page.tsx +6 -4
- package/app/blog-rhythm.css +278 -0
- package/app/globals.css +22 -4
- package/app/layout.tsx +24 -12
- package/app/newsroom/articles/[id]/page.tsx +15 -0
- package/app/newsroom/articles/page.tsx +13 -0
- package/app/page.tsx +12 -4
- package/app/robots.ts +11 -0
- package/bin/papyrus-app.mjs +12 -2
- package/bin/papyrus-infra.mjs +74 -18
- package/components/archive-shell.tsx +2 -22
- package/components/article-video.tsx +247 -3
- package/components/blog-page-background.tsx +23 -6
- package/components/markus-ir-preview.tsx +300 -0
- package/components/news-desk-page.tsx +1 -4
- package/components/newspaper.tsx +6 -2
- package/components/newsroom-access-gate.tsx +66 -0
- package/components/newsroom-article-editor.tsx +741 -0
- package/components/newsroom-articles-view.tsx +129 -0
- package/components/newsroom-ops-overview.tsx +28 -11
- package/components/newsroom-ops-shell.tsx +3 -1
- package/components/pictogram-figure.tsx +9 -2
- package/components/presentation-header.tsx +135 -0
- package/components/presentation-rhythm-hrule.tsx +17 -0
- package/components/settings-page.tsx +2 -1
- package/components/staging-banner.tsx +11 -0
- package/components/topic-steering-workspace.tsx +1 -59
- package/components/use-blog-header-obstacles.ts +81 -0
- package/components/use-brand-fonts-ready.ts +28 -0
- package/components/use-rhythm-overlay.ts +29 -0
- package/infra/amplify-app-shell.js +285 -80
- package/infra/amplify-app-shell.ts +326 -113
- package/infra/build-specs.js +94 -0
- package/infra/build-specs.ts +141 -0
- package/infra/github-oidc-provider.js +24 -0
- package/infra/github-oidc-provider.ts +30 -0
- package/infra/index.js +3 -0
- package/infra/site-config.js +273 -0
- package/infra/site-config.ts +336 -0
- package/lib/blog-feature-solver.ts +459 -0
- package/lib/blog-rhythm.ts +134 -0
- package/lib/brand-fonts-watch.ts +43 -0
- package/lib/brand-fonts.ts +112 -0
- package/lib/cached-content-repository.ts +14 -1
- package/lib/category-repository.ts +1 -93
- package/lib/content-actions-client.ts +98 -0
- package/lib/content-actions-demo.ts +190 -0
- package/lib/content-repository.ts +6 -0
- package/lib/content-source-context.ts +26 -0
- package/lib/content-types.ts +4 -0
- package/lib/edition-routes.ts +31 -29
- package/lib/empty-theme.css +1 -0
- package/lib/graphql-content-repository.ts +239 -43
- package/lib/layout-scenarios.ts +8 -8
- package/lib/newspaper-layout.ts +3 -2
- package/lib/newsroom-articles.ts +325 -0
- package/lib/newsroom-demo-articles.ts +90 -0
- package/lib/newsroom-media-backend.ts +142 -0
- package/lib/newsroom-media.ts +182 -0
- package/lib/newsroom-nav.ts +3 -0
- package/lib/papyrus-web-locations.ts +7 -6
- package/lib/presentation-footer.ts +3 -2
- package/lib/pretext-layout.ts +12 -3
- package/lib/reader-base-path.ts +24 -0
- package/lib/reader-static-params.ts +8 -0
- package/lib/renderer.ts +7 -0
- package/lib/revalidate-secret.ts +59 -0
- package/lib/root-route-redirect.ts +16 -0
- package/lib/site-brand-tenant.ts +3 -22
- package/lib/site-brand.ts +95 -42
- package/lib/site-env.ts +52 -0
- package/lib/staging-gate.ts +37 -0
- package/lib/staging-gated-path.ts +22 -0
- package/lib/staging-preview-object.ts +98 -0
- package/lib/video-mode.ts +42 -0
- package/lib/video-script.ts +77 -0
- package/middleware.ts +56 -42
- package/package.json +40 -1
- package/renderers/pretext/article-page.tsx +40 -9
- package/renderers/pretext/presentation-shared.tsx +113 -0
- package/renderers/pretext/presentation-shell.tsx +18 -112
- package/renderers/pretext/rhythm-article-page.tsx +165 -0
- package/renderers/pretext/rhythm-blog-presentation.tsx +279 -0
- package/renderers/pretext/rhythm-shell-style.ts +35 -0
- package/routes.manifest.json +37 -2
- package/scripts/videoml/build-browser-bundle.mjs +22 -0
- package/scripts/videoml/build-preview-bundle.mjs +50 -0
- package/scripts/videoml/bundle-common.mjs +129 -0
- package/scripts/videoml/preview/preview-entry.tsx +381 -0
- package/scripts/videoml/preview/preview-stage-fit.ts +28 -0
- package/scripts/videoml/preview/preview-timing.ts +42 -0
- package/scripts/videoml/preview.html +77 -0
- package/scripts/videoml/standard-entry.tsx +46 -0
- package/src/sync.mjs +30 -6
- package/src/with-papyrus.mjs +15 -2
- package/amplify/functions/graphql-jwt-authorizer/handler.ts +0 -193
- package/amplify/functions/graphql-jwt-authorizer/resource.js +0 -14
- package/amplify/functions/graphql-jwt-authorizer/resource.ts +0 -15
- package/publications/anth_us/brand.ts +0 -68
- package/publications/anth_us/theme.css +0 -66
- package/publications/pilobol_us/brand.ts +0 -37
- package/publications/pilobol_us/theme.css +0 -140
- package/publications/threat_intelligence/blog-defense/graph.ts +0 -636
- package/publications/threat_intelligence/blog-defense/layout.ts +0 -934
- package/publications/threat_intelligence/blog-defense/page-background.tsx +0 -590
- package/publications/threat_intelligence/brand.ts +0 -40
- package/publications/threat_intelligence/pictograms/art.tsx +0 -608
- package/publications/threat_intelligence/pictograms/figure.tsx +0 -82
- package/publications/threat_intelligence/pictograms/registry.ts +0 -30
- package/publications/threat_intelligence/pictograms/system.tsx +0 -305
- package/publications/threat_intelligence/seed/seed-edition-content.json +0 -629
- package/publications/threat_intelligence/theme.css +0 -1440
- /package/{publications/papyrus/theme.css → app/papyrus-theme.css} +0 -0
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
export type SiteBrandFontFace = {
|
|
2
|
+
/** Public URL of the font file, e.g. `/fonts/acme-serif-regular.woff2`. */
|
|
3
|
+
src: string;
|
|
4
|
+
weight?: number | string;
|
|
5
|
+
style?: "normal" | "italic";
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
export type SiteBrandGoogleFontSource = {
|
|
9
|
+
weights: number[];
|
|
10
|
+
/** Also load the italic style of every listed weight. */
|
|
11
|
+
italics?: boolean;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* One brand-declared font family. Declare exactly one source: `google` loads
|
|
16
|
+
* the family from the Google Fonts stylesheet API; `faces` self-hosts files
|
|
17
|
+
* with `@font-face`. The root layout exposes `cssVariable` as
|
|
18
|
+
* `"<family>", <fallback>` on `<html>`, so publication CSS writes
|
|
19
|
+
* `font-family: var(--font-masthead)`.
|
|
20
|
+
*/
|
|
21
|
+
export type SiteBrandFont = {
|
|
22
|
+
family: string;
|
|
23
|
+
cssVariable: string;
|
|
24
|
+
fallback?: string;
|
|
25
|
+
google?: SiteBrandGoogleFontSource;
|
|
26
|
+
faces?: SiteBrandFontFace[];
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
export type BrandFontAssets = {
|
|
30
|
+
preconnectOrigins: string[];
|
|
31
|
+
stylesheetHrefs: string[];
|
|
32
|
+
fontFaceCss: string;
|
|
33
|
+
rootStyle: Record<string, string>;
|
|
34
|
+
isEmpty: boolean;
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
const GOOGLE_STYLESHEET_ORIGIN = "https://fonts.googleapis.com";
|
|
38
|
+
const GOOGLE_FILE_ORIGIN = "https://fonts.gstatic.com";
|
|
39
|
+
const DEFAULT_FALLBACK = "sans-serif";
|
|
40
|
+
const CSS_VARIABLE_PATTERN = /^--[a-z][a-z0-9-]*$/;
|
|
41
|
+
|
|
42
|
+
export function validateBrandFonts(fonts: SiteBrandFont[]): void {
|
|
43
|
+
const seenVariables = new Set<string>();
|
|
44
|
+
for (const font of fonts) {
|
|
45
|
+
if (!font.family.trim()) throw new Error("A brand font needs a family name.");
|
|
46
|
+
if (!CSS_VARIABLE_PATTERN.test(font.cssVariable)) {
|
|
47
|
+
throw new Error(`Brand font "${font.family}" cssVariable must look like --font-name, got "${font.cssVariable}".`);
|
|
48
|
+
}
|
|
49
|
+
if (seenVariables.has(font.cssVariable)) {
|
|
50
|
+
throw new Error(`Brand font cssVariable ${font.cssVariable} is declared twice.`);
|
|
51
|
+
}
|
|
52
|
+
seenVariables.add(font.cssVariable);
|
|
53
|
+
const sourceCount = Number(Boolean(font.google)) + Number(Boolean(font.faces?.length));
|
|
54
|
+
if (sourceCount !== 1) {
|
|
55
|
+
throw new Error(`Brand font "${font.family}" must declare exactly one source: google or faces.`);
|
|
56
|
+
}
|
|
57
|
+
if (font.google && font.google.weights.length === 0) {
|
|
58
|
+
throw new Error(`Brand font "${font.family}" google source needs at least one weight.`);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
function buildGoogleFamilyQuery(font: SiteBrandFont): string {
|
|
64
|
+
const google = font.google!;
|
|
65
|
+
const weights = [...new Set(google.weights)].sort((left, right) => left - right);
|
|
66
|
+
const familyName = font.family.trim().replace(/\s+/g, "+");
|
|
67
|
+
if (!google.italics) return `family=${familyName}:wght@${weights.join(";")}`;
|
|
68
|
+
const axisValues = [0, 1].flatMap((italic) => weights.map((weight) => `${italic},${weight}`));
|
|
69
|
+
return `family=${familyName}:ital,wght@${axisValues.join(";")}`;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export function buildGoogleFontsHref(fonts: SiteBrandFont[]): string | null {
|
|
73
|
+
const googleFonts = fonts.filter((font) => font.google);
|
|
74
|
+
if (googleFonts.length === 0) return null;
|
|
75
|
+
return `${GOOGLE_STYLESHEET_ORIGIN}/css2?${googleFonts.map(buildGoogleFamilyQuery).join("&")}&display=swap`;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
function buildFontFaceCss(font: SiteBrandFont): string {
|
|
79
|
+
return (font.faces ?? [])
|
|
80
|
+
.map((face) => {
|
|
81
|
+
const declarations = [
|
|
82
|
+
`font-family:${JSON.stringify(font.family)}`,
|
|
83
|
+
`src:url(${JSON.stringify(face.src)})`,
|
|
84
|
+
`font-weight:${face.weight ?? 400}`,
|
|
85
|
+
`font-style:${face.style ?? "normal"}`,
|
|
86
|
+
"font-display:swap",
|
|
87
|
+
];
|
|
88
|
+
return `@font-face{${declarations.join(";")}}`;
|
|
89
|
+
})
|
|
90
|
+
.join("");
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
export function resolveBrandFontAssets(fonts: SiteBrandFont[] | undefined): BrandFontAssets {
|
|
94
|
+
if (!fonts || fonts.length === 0) {
|
|
95
|
+
return { preconnectOrigins: [], stylesheetHrefs: [], fontFaceCss: "", rootStyle: {}, isEmpty: true };
|
|
96
|
+
}
|
|
97
|
+
validateBrandFonts(fonts);
|
|
98
|
+
const googleHref = buildGoogleFontsHref(fonts);
|
|
99
|
+
return {
|
|
100
|
+
preconnectOrigins: googleHref ? [GOOGLE_STYLESHEET_ORIGIN, GOOGLE_FILE_ORIGIN] : [],
|
|
101
|
+
stylesheetHrefs: googleHref ? [googleHref] : [],
|
|
102
|
+
fontFaceCss: fonts.map(buildFontFaceCss).join(""),
|
|
103
|
+
rootStyle: Object.fromEntries(
|
|
104
|
+
fonts.map((font) => [font.cssVariable, `${JSON.stringify(font.family)}, ${font.fallback ?? DEFAULT_FALLBACK}`]),
|
|
105
|
+
),
|
|
106
|
+
isEmpty: false,
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
export function listBrandFontFamilies(fonts: SiteBrandFont[] | undefined): string[] {
|
|
111
|
+
return (fonts ?? []).map((font) => font.family);
|
|
112
|
+
}
|
|
@@ -10,6 +10,8 @@ import type {
|
|
|
10
10
|
} from "./content-types";
|
|
11
11
|
import { graphqlContentRepository } from "./graphql-content-repository";
|
|
12
12
|
import { READER_REVALIDATE_SECONDS } from "./reader-route-config";
|
|
13
|
+
import type { VideoScriptRef } from "./video-script";
|
|
14
|
+
import { getContentSource } from "./site-env";
|
|
13
15
|
|
|
14
16
|
const bypassReaderCacheInDevelopment = process.env.NODE_ENV === "development";
|
|
15
17
|
|
|
@@ -34,7 +36,7 @@ function withReaderCache<T>(
|
|
|
34
36
|
tags: string[],
|
|
35
37
|
loader: () => Promise<T>,
|
|
36
38
|
): Promise<T> {
|
|
37
|
-
if (bypassReaderCacheInDevelopment) return loader();
|
|
39
|
+
if (bypassReaderCacheInDevelopment || getContentSource() === "drafts") return loader();
|
|
38
40
|
return unstable_cache(loader, cacheKey, {
|
|
39
41
|
tags,
|
|
40
42
|
revalidate: READER_REVALIDATE_SECONDS,
|
|
@@ -87,3 +89,14 @@ export function getCachedLatestPublishedEdition(): Promise<EditionRouteSummary |
|
|
|
87
89
|
async () => graphqlContentRepository.getLatestPublishedEdition(),
|
|
88
90
|
);
|
|
89
91
|
}
|
|
92
|
+
|
|
93
|
+
export function getCachedVideoScript(targetSlug: string): Promise<VideoScriptRef | null> {
|
|
94
|
+
if (bypassReaderCacheInDevelopment) {
|
|
95
|
+
return Promise.resolve(graphqlContentRepository.loadVideoScript(targetSlug)).then((result) => result ?? null);
|
|
96
|
+
}
|
|
97
|
+
return withReaderCache(
|
|
98
|
+
["reader-video-script", targetSlug],
|
|
99
|
+
[articleCacheTag(targetSlug), ARTICLES_CACHE_TAG],
|
|
100
|
+
async () => graphqlContentRepository.loadVideoScript(targetSlug),
|
|
101
|
+
);
|
|
102
|
+
}
|
|
@@ -769,85 +769,7 @@ function knowledgeCorpusIdFromKey(corpusKey: string): string {
|
|
|
769
769
|
}
|
|
770
770
|
|
|
771
771
|
export async function loadCategorySteeringDashboard(): Promise<CategorySteeringDashboard> {
|
|
772
|
-
|
|
773
|
-
if (proposals.length === 0) return createEmptyCategorySteeringDashboard();
|
|
774
|
-
return {
|
|
775
|
-
...createEmptyCategorySteeringDashboard(),
|
|
776
|
-
isPublicSkeleton: false,
|
|
777
|
-
proposals: sortProposals(proposals),
|
|
778
|
-
loadError: null,
|
|
779
|
-
};
|
|
780
|
-
}
|
|
781
|
-
|
|
782
|
-
const SERVER_STEERING_PROPOSALS_QUERY = `
|
|
783
|
-
query ListSteeringProposals($limit: Int, $nextToken: String) {
|
|
784
|
-
listSteeringProposals(limit: $limit, nextToken: $nextToken) {
|
|
785
|
-
items {
|
|
786
|
-
id
|
|
787
|
-
categorySetId
|
|
788
|
-
corpusId
|
|
789
|
-
proposalKind
|
|
790
|
-
steeringDomain
|
|
791
|
-
status
|
|
792
|
-
title
|
|
793
|
-
summary
|
|
794
|
-
categoryKey
|
|
795
|
-
targetCategoryKey
|
|
796
|
-
graphEntityId
|
|
797
|
-
relationshipType
|
|
798
|
-
displayName
|
|
799
|
-
shortTitle
|
|
800
|
-
subtitle
|
|
801
|
-
description
|
|
802
|
-
evidenceItemIds
|
|
803
|
-
suggestedSeedItemIds
|
|
804
|
-
suggestedHoldoutItemIds
|
|
805
|
-
sourceSnapshotId
|
|
806
|
-
proposedAt
|
|
807
|
-
reviewedAt
|
|
808
|
-
reviewedBy
|
|
809
|
-
updatedAt
|
|
810
|
-
}
|
|
811
|
-
nextToken
|
|
812
|
-
}
|
|
813
|
-
}
|
|
814
|
-
`;
|
|
815
|
-
|
|
816
|
-
async function loadServerSteeringProposals(): Promise<CategorySteeringProposal[]> {
|
|
817
|
-
const endpoint = process.env.PAPYRUS_GRAPHQL_ENDPOINT;
|
|
818
|
-
const jwt = process.env.PAPYRUS_GRAPHQL_JWT;
|
|
819
|
-
if (!endpoint || !jwt) return [];
|
|
820
|
-
|
|
821
|
-
const items: CategorySteeringProposal[] = [];
|
|
822
|
-
let nextToken: string | null = null;
|
|
823
|
-
|
|
824
|
-
for (let page = 0; page < 20; page += 1) {
|
|
825
|
-
const response = await fetch(endpoint, {
|
|
826
|
-
method: "POST",
|
|
827
|
-
headers: {
|
|
828
|
-
"content-type": "application/json",
|
|
829
|
-
Authorization: `Bearer ${jwt}`,
|
|
830
|
-
},
|
|
831
|
-
body: JSON.stringify({
|
|
832
|
-
query: SERVER_STEERING_PROPOSALS_QUERY,
|
|
833
|
-
variables: { limit: 500, nextToken },
|
|
834
|
-
}),
|
|
835
|
-
cache: "no-store",
|
|
836
|
-
});
|
|
837
|
-
if (!response.ok) return [];
|
|
838
|
-
const payload = await response.json() as {
|
|
839
|
-
data?: { listSteeringProposals?: { items?: Array<CategorySteeringProposal | null> | null; nextToken?: string | null } | null } | null;
|
|
840
|
-
errors?: Array<{ message?: string }> | null;
|
|
841
|
-
};
|
|
842
|
-
if (payload.errors?.length) return [];
|
|
843
|
-
const connection = payload.data?.listSteeringProposals;
|
|
844
|
-
if (!connection) return [];
|
|
845
|
-
items.push(...(connection.items ?? []).filter(Boolean) as CategorySteeringProposal[]);
|
|
846
|
-
nextToken = connection.nextToken ?? null;
|
|
847
|
-
if (!nextToken) break;
|
|
848
|
-
}
|
|
849
|
-
|
|
850
|
-
return items;
|
|
772
|
+
return createEmptyCategorySteeringDashboard();
|
|
851
773
|
}
|
|
852
774
|
|
|
853
775
|
function sortCategorySets(categorySets: CategorySteeringCategorySet[], importRuns: CategorySteeringImportRun[]): CategorySteeringCategorySet[] {
|
|
@@ -895,20 +817,6 @@ function sortCategorys(categorys: CategorySteeringCategory[]): CategorySteeringC
|
|
|
895
817
|
});
|
|
896
818
|
}
|
|
897
819
|
|
|
898
|
-
function sortProposals(proposals: CategorySteeringProposal[]): CategorySteeringProposal[] {
|
|
899
|
-
const statusWeight = new Map([
|
|
900
|
-
["proposed", 0],
|
|
901
|
-
["deferred", 1],
|
|
902
|
-
["accepted", 2],
|
|
903
|
-
["rejected", 3],
|
|
904
|
-
]);
|
|
905
|
-
return [...proposals].sort((left, right) => {
|
|
906
|
-
const statusDiff = (statusWeight.get(left.status) ?? 9) - (statusWeight.get(right.status) ?? 9);
|
|
907
|
-
if (statusDiff !== 0) return statusDiff;
|
|
908
|
-
return (right.proposedAt ?? right.updatedAt ?? "").localeCompare(left.proposedAt ?? left.updatedAt ?? "");
|
|
909
|
-
});
|
|
910
|
-
}
|
|
911
|
-
|
|
912
820
|
function defaultNewsroomSections(importedAt: string, sectionsConfigPath = DEFAULT_NEWSROOM_SECTIONS_CONFIG_PATH): NewsroomSectionRecord[] {
|
|
913
821
|
return loadNewsroomSectionSeedRows(sectionsConfigPath).map((row, index) => ({
|
|
914
822
|
...row,
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { generateClient } from "aws-amplify/data";
|
|
2
|
+
import type { Schema } from "../amplify/data/resource";
|
|
3
|
+
|
|
4
|
+
export type ContentActionError = { code: string; message: string; line: number | null };
|
|
5
|
+
|
|
6
|
+
export type DeriveMarkusInput = { frontMatterYaml: string | null; bodyMarkus: string; includeIr?: boolean };
|
|
7
|
+
export type SaveItemDraftInput = {
|
|
8
|
+
id: string | null;
|
|
9
|
+
type: string;
|
|
10
|
+
slug: string;
|
|
11
|
+
section: string | null;
|
|
12
|
+
frontMatterYaml: string | null;
|
|
13
|
+
bodyMarkus: string;
|
|
14
|
+
aliases: string[];
|
|
15
|
+
expectedContentHash: string | null;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export type DeriveMarkusResult = { ok: true; bodyIrBytes: number; bodyIr?: unknown; errors: [] };
|
|
19
|
+
export type SavedItemSummary = {
|
|
20
|
+
id: string;
|
|
21
|
+
contentHash: string;
|
|
22
|
+
status: string;
|
|
23
|
+
slug: string;
|
|
24
|
+
versionNumber: number | null;
|
|
25
|
+
};
|
|
26
|
+
export type SaveItemDraftResult = { ok: true; item: SavedItemSummary };
|
|
27
|
+
export type PublishItemResult = { ok: true; changed: boolean; publishedId: string; versionNumber: number | null };
|
|
28
|
+
export type UnpublishItemResult = { ok: true; changed: boolean };
|
|
29
|
+
|
|
30
|
+
export class ContentActionFailure extends Error {
|
|
31
|
+
readonly errors: ContentActionError[];
|
|
32
|
+
|
|
33
|
+
constructor(errors: ContentActionError[]) {
|
|
34
|
+
super(errors.map((error) => error.message).join("; ") || "Content action failed");
|
|
35
|
+
this.name = "ContentActionFailure";
|
|
36
|
+
this.errors = errors;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
type GraphqlEnvelope = { data?: unknown; errors?: { message?: string }[] | null };
|
|
41
|
+
|
|
42
|
+
export type ContentActionsTransport = {
|
|
43
|
+
queries: { deriveMarkus: (args: { input: string }, options: { authMode: "userPool" }) => Promise<GraphqlEnvelope> };
|
|
44
|
+
mutations: {
|
|
45
|
+
saveItemDraft: (args: { input: string }, options: { authMode: "userPool" }) => Promise<GraphqlEnvelope>;
|
|
46
|
+
publishItem: (args: { input: string }, options: { authMode: "userPool" }) => Promise<GraphqlEnvelope>;
|
|
47
|
+
unpublishItem: (args: { input: string }, options: { authMode: "userPool" }) => Promise<GraphqlEnvelope>;
|
|
48
|
+
};
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
const USER_POOL = { authMode: "userPool" } as const;
|
|
52
|
+
|
|
53
|
+
function parseActionResponse<T>(envelope: GraphqlEnvelope): T {
|
|
54
|
+
if (envelope.errors && envelope.errors.length > 0) {
|
|
55
|
+
throw new Error(envelope.errors.map((error) => error.message ?? "GraphQL error").join("; "));
|
|
56
|
+
}
|
|
57
|
+
const raw = envelope.data;
|
|
58
|
+
const parsed = typeof raw === "string" ? JSON.parse(raw) : raw;
|
|
59
|
+
if (!parsed || typeof parsed !== "object") {
|
|
60
|
+
throw new Error("The content action returned no data.");
|
|
61
|
+
}
|
|
62
|
+
const response = parsed as { ok?: boolean; errors?: ContentActionError[] };
|
|
63
|
+
if (response.ok !== true) {
|
|
64
|
+
throw new ContentActionFailure(response.errors ?? []);
|
|
65
|
+
}
|
|
66
|
+
return parsed as T;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export function createContentActionsClient(transport: ContentActionsTransport) {
|
|
70
|
+
return {
|
|
71
|
+
async deriveMarkus(input: DeriveMarkusInput): Promise<DeriveMarkusResult> {
|
|
72
|
+
return parseActionResponse(await transport.queries.deriveMarkus({ input: JSON.stringify(input) }, USER_POOL));
|
|
73
|
+
},
|
|
74
|
+
async saveItemDraft(input: SaveItemDraftInput): Promise<SaveItemDraftResult> {
|
|
75
|
+
return parseActionResponse(await transport.mutations.saveItemDraft({ input: JSON.stringify(input) }, USER_POOL));
|
|
76
|
+
},
|
|
77
|
+
async publishItem(id: string): Promise<PublishItemResult> {
|
|
78
|
+
return parseActionResponse(await transport.mutations.publishItem({ input: JSON.stringify({ id }) }, USER_POOL));
|
|
79
|
+
},
|
|
80
|
+
async unpublishItem(id: string): Promise<UnpublishItemResult> {
|
|
81
|
+
return parseActionResponse(await transport.mutations.unpublishItem({ input: JSON.stringify({ id }) }, USER_POOL));
|
|
82
|
+
},
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
let defaultClient: ReturnType<typeof createContentActionsClient> | null = null;
|
|
87
|
+
|
|
88
|
+
function contentActionsClient() {
|
|
89
|
+
if (!defaultClient) {
|
|
90
|
+
defaultClient = createContentActionsClient(generateClient<Schema>() as unknown as ContentActionsTransport);
|
|
91
|
+
}
|
|
92
|
+
return defaultClient;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
export const deriveMarkus = (input: DeriveMarkusInput) => contentActionsClient().deriveMarkus(input);
|
|
96
|
+
export const saveItemDraft = (input: SaveItemDraftInput) => contentActionsClient().saveItemDraft(input);
|
|
97
|
+
export const publishItem = (id: string) => contentActionsClient().publishItem(id);
|
|
98
|
+
export const unpublishItem = (id: string) => contentActionsClient().unpublishItem(id);
|
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
import { ContentActionFailure } from "./content-actions-client";
|
|
2
|
+
import type {
|
|
3
|
+
DeriveMarkusInput,
|
|
4
|
+
DeriveMarkusResult,
|
|
5
|
+
PublishItemResult,
|
|
6
|
+
SaveItemDraftInput,
|
|
7
|
+
SaveItemDraftResult,
|
|
8
|
+
UnpublishItemResult,
|
|
9
|
+
} from "./content-actions-client";
|
|
10
|
+
import {
|
|
11
|
+
createDemoArticleRecords,
|
|
12
|
+
demoContentHash,
|
|
13
|
+
type DemoArticleRecord,
|
|
14
|
+
} from "./newsroom-demo-articles";
|
|
15
|
+
import { sourceLineOffset, type ArticlesBackend, type EditableArticle, type NewsroomArticleRow } from "./newsroom-articles";
|
|
16
|
+
|
|
17
|
+
function titleFromYaml(frontMatterYaml: string | null, fallback: string): string {
|
|
18
|
+
for (const line of (frontMatterYaml ?? "").split("\n")) {
|
|
19
|
+
const match = /^title\s*:\s*(.*)$/.exec(line);
|
|
20
|
+
if (match && match[1].trim()) return match[1].trim().replace(/^["']|["']$/g, "");
|
|
21
|
+
}
|
|
22
|
+
return fallback;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const DEMO_IMAGE_DIRECTIVE = /^::image\{([^}]*)\}$/;
|
|
26
|
+
|
|
27
|
+
function demoAttribute(attributes: string, name: string): string {
|
|
28
|
+
const match = new RegExp(`${name}="([^"]*)"`).exec(attributes);
|
|
29
|
+
return match ? match[1] : "";
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function demoEnvelope(bodyMarkus: string) {
|
|
33
|
+
const images: Record<string, Record<string, unknown>> = {};
|
|
34
|
+
const children = bodyMarkus
|
|
35
|
+
.split(/\n{2,}/)
|
|
36
|
+
.map((block) => block.trim())
|
|
37
|
+
.filter(Boolean)
|
|
38
|
+
.map((block) => {
|
|
39
|
+
const heading = /^(#{1,6})\s+(.*)$/.exec(block);
|
|
40
|
+
if (heading) {
|
|
41
|
+
return { type: "heading", level: heading[1].length, inline: [{ type: "text", text: heading[2] }], line: null };
|
|
42
|
+
}
|
|
43
|
+
const image = DEMO_IMAGE_DIRECTIVE.exec(block);
|
|
44
|
+
if (image) {
|
|
45
|
+
const token = `PAPYRUSMARKUP${String(Object.keys(images).length + 1).padStart(5, "0")}END`;
|
|
46
|
+
images[token] = {
|
|
47
|
+
src: demoAttribute(image[1], "src"),
|
|
48
|
+
alt: demoAttribute(image[1], "alt"),
|
|
49
|
+
layout: demoAttribute(image[1], "layout") || null,
|
|
50
|
+
};
|
|
51
|
+
return { type: "paragraph", inline: [{ type: "text", text: token }], line: null };
|
|
52
|
+
}
|
|
53
|
+
return { type: "paragraph", inline: [{ type: "text", text: block }], line: null };
|
|
54
|
+
});
|
|
55
|
+
return {
|
|
56
|
+
schemaVersion: 1,
|
|
57
|
+
markus: { version: "demo", irSchemaVersion: 1 },
|
|
58
|
+
document: { type: "document", schema_version: 1, front_matter: {}, children },
|
|
59
|
+
papyrus: { images, citations: {}, citationLists: {}, entries: {}, bibliography: [] },
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export function createDemoArticlesBackend(): ArticlesBackend {
|
|
64
|
+
const records = new Map<string, DemoArticleRecord>(createDemoArticleRecords().map((record) => [record.id, record]));
|
|
65
|
+
let created = 0;
|
|
66
|
+
|
|
67
|
+
const requireRecord = (id: string): DemoArticleRecord => {
|
|
68
|
+
const record = records.get(id);
|
|
69
|
+
if (!record) throw new ContentActionFailure([{ code: "not-found", message: "That article was not found.", line: null }]);
|
|
70
|
+
return record;
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
return {
|
|
74
|
+
actions: {
|
|
75
|
+
async deriveMarkus(input: DeriveMarkusInput): Promise<DeriveMarkusResult> {
|
|
76
|
+
const lines = input.bodyMarkus.split("\n");
|
|
77
|
+
const invalidIndex = lines.findIndex((line) => line.includes(":::nope"));
|
|
78
|
+
if (invalidIndex >= 0) {
|
|
79
|
+
throw new ContentActionFailure([
|
|
80
|
+
{ code: "markus-validation", message: 'Unknown directive "nope".', line: invalidIndex + 1 + sourceLineOffset(input.frontMatterYaml) },
|
|
81
|
+
]);
|
|
82
|
+
}
|
|
83
|
+
const envelope = demoEnvelope(input.bodyMarkus);
|
|
84
|
+
return {
|
|
85
|
+
ok: true,
|
|
86
|
+
bodyIrBytes: JSON.stringify(envelope).length,
|
|
87
|
+
...(input.includeIr ? { bodyIr: envelope } : {}),
|
|
88
|
+
errors: [],
|
|
89
|
+
};
|
|
90
|
+
},
|
|
91
|
+
async saveItemDraft(input: SaveItemDraftInput): Promise<SaveItemDraftResult> {
|
|
92
|
+
const existing = input.id ? requireRecord(input.id) : null;
|
|
93
|
+
if (existing && input.expectedContentHash !== null && input.expectedContentHash !== existing.contentHash) {
|
|
94
|
+
throw new ContentActionFailure([
|
|
95
|
+
{ code: "conflict", message: "The item changed since it was loaded.", line: null },
|
|
96
|
+
]);
|
|
97
|
+
}
|
|
98
|
+
if (existing && existing.everPublished && existing.slug !== input.slug) {
|
|
99
|
+
throw new ContentActionFailure([
|
|
100
|
+
{ code: "slug-locked", message: "The slug cannot change once the item has been published.", line: null },
|
|
101
|
+
]);
|
|
102
|
+
}
|
|
103
|
+
const id = existing?.id ?? `demo-article-new-${(created += 1)}`;
|
|
104
|
+
const title = titleFromYaml(input.frontMatterYaml, input.slug);
|
|
105
|
+
const frontMatterYaml = input.frontMatterYaml ?? "";
|
|
106
|
+
const record: DemoArticleRecord = {
|
|
107
|
+
id,
|
|
108
|
+
type: input.type,
|
|
109
|
+
slug: input.slug,
|
|
110
|
+
section: input.section,
|
|
111
|
+
title,
|
|
112
|
+
status: existing?.status ?? "draft",
|
|
113
|
+
frontMatterYaml,
|
|
114
|
+
bodyMarkus: input.bodyMarkus,
|
|
115
|
+
contentHash: demoContentHash(frontMatterYaml, input.bodyMarkus),
|
|
116
|
+
publishedContentHash: existing?.publishedContentHash ?? null,
|
|
117
|
+
versionNumber: existing?.versionNumber ?? null,
|
|
118
|
+
everPublished: existing?.everPublished ?? false,
|
|
119
|
+
updatedAt: new Date().toISOString(),
|
|
120
|
+
};
|
|
121
|
+
records.set(id, record);
|
|
122
|
+
return {
|
|
123
|
+
ok: true,
|
|
124
|
+
item: {
|
|
125
|
+
id,
|
|
126
|
+
contentHash: record.contentHash,
|
|
127
|
+
status: record.status,
|
|
128
|
+
slug: record.slug,
|
|
129
|
+
versionNumber: record.versionNumber,
|
|
130
|
+
},
|
|
131
|
+
};
|
|
132
|
+
},
|
|
133
|
+
async publishItem(id: string): Promise<PublishItemResult> {
|
|
134
|
+
const record = requireRecord(id);
|
|
135
|
+
const changed = record.status !== "published" || record.publishedContentHash !== record.contentHash;
|
|
136
|
+
const versionNumber = changed ? (record.versionNumber ?? 0) + 1 : record.versionNumber;
|
|
137
|
+
records.set(id, {
|
|
138
|
+
...record,
|
|
139
|
+
status: "published",
|
|
140
|
+
everPublished: true,
|
|
141
|
+
publishedContentHash: record.contentHash,
|
|
142
|
+
versionNumber,
|
|
143
|
+
updatedAt: new Date().toISOString(),
|
|
144
|
+
});
|
|
145
|
+
return { ok: true, changed, publishedId: `published-${id}`, versionNumber };
|
|
146
|
+
},
|
|
147
|
+
async unpublishItem(id: string): Promise<UnpublishItemResult> {
|
|
148
|
+
const record = requireRecord(id);
|
|
149
|
+
const changed = record.status === "published";
|
|
150
|
+
records.set(id, {
|
|
151
|
+
...record,
|
|
152
|
+
status: "draft",
|
|
153
|
+
publishedContentHash: null,
|
|
154
|
+
updatedAt: new Date().toISOString(),
|
|
155
|
+
});
|
|
156
|
+
return { ok: true, changed };
|
|
157
|
+
},
|
|
158
|
+
},
|
|
159
|
+
async listRows(): Promise<NewsroomArticleRow[]> {
|
|
160
|
+
return [...records.values()]
|
|
161
|
+
.map((record) => ({
|
|
162
|
+
id: record.id,
|
|
163
|
+
type: record.type,
|
|
164
|
+
slug: record.slug,
|
|
165
|
+
section: record.section,
|
|
166
|
+
title: record.title || record.slug,
|
|
167
|
+
status: record.status,
|
|
168
|
+
pending: record.status === "published" && record.publishedContentHash !== record.contentHash,
|
|
169
|
+
updatedAt: record.updatedAt,
|
|
170
|
+
}))
|
|
171
|
+
.sort((left, right) => right.updatedAt.localeCompare(left.updatedAt));
|
|
172
|
+
},
|
|
173
|
+
async loadArticle(id: string): Promise<EditableArticle> {
|
|
174
|
+
const record = requireRecord(id);
|
|
175
|
+
return {
|
|
176
|
+
id: record.id,
|
|
177
|
+
type: record.type,
|
|
178
|
+
section: record.section,
|
|
179
|
+
slug: record.slug,
|
|
180
|
+
frontMatterYaml: record.frontMatterYaml,
|
|
181
|
+
bodyMarkus: record.bodyMarkus,
|
|
182
|
+
contentHash: record.contentHash,
|
|
183
|
+
status: record.status,
|
|
184
|
+
versionNumber: record.versionNumber,
|
|
185
|
+
aliases: [],
|
|
186
|
+
everPublished: record.everPublished,
|
|
187
|
+
};
|
|
188
|
+
},
|
|
189
|
+
};
|
|
190
|
+
}
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import type { ContentRepository } from "./content-types";
|
|
2
2
|
import { graphqlContentRepository } from "./graphql-content-repository";
|
|
3
3
|
import { getLayoutScenario } from "./layout-scenarios";
|
|
4
|
+
import { assertContentSourceMatchesEnv } from "./site-env";
|
|
5
|
+
|
|
6
|
+
assertContentSourceMatchesEnv();
|
|
4
7
|
|
|
5
8
|
export const contentRepository: ContentRepository = {
|
|
6
9
|
loadEditionContent({ scenarioId, editionDate, editionSlug } = {}) {
|
|
@@ -28,6 +31,9 @@ export const contentRepository: ContentRepository = {
|
|
|
28
31
|
listArticleSlugs() {
|
|
29
32
|
return graphqlContentRepository.listArticleSlugs();
|
|
30
33
|
},
|
|
34
|
+
loadVideoScript(targetSlug: string) {
|
|
35
|
+
return graphqlContentRepository.loadVideoScript(targetSlug);
|
|
36
|
+
},
|
|
31
37
|
};
|
|
32
38
|
|
|
33
39
|
export function getScenarioIdParam(scenario: string | string[] | null | undefined): string | null {
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { AsyncLocalStorage } from "node:async_hooks";
|
|
2
|
+
import { getContentSource, type ContentSource } from "./site-env";
|
|
3
|
+
|
|
4
|
+
export type ContentSourceContext = {
|
|
5
|
+
source: ContentSource;
|
|
6
|
+
/** Request-scoped data client (drafts mode: carries the visitor's session cookies). */
|
|
7
|
+
client?: unknown;
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
const contentSourceStorage = new AsyncLocalStorage<ContentSourceContext>();
|
|
11
|
+
|
|
12
|
+
export function runWithContentSource<T>(
|
|
13
|
+
source: ContentSource,
|
|
14
|
+
operation: () => Promise<T>,
|
|
15
|
+
client?: unknown,
|
|
16
|
+
): Promise<T> {
|
|
17
|
+
return contentSourceStorage.run({ source, client }, operation);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export function currentRequestClient<T>(): T | undefined {
|
|
21
|
+
return contentSourceStorage.getStore()?.client as T | undefined;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export function currentContentSource(): ContentSource {
|
|
25
|
+
return contentSourceStorage.getStore()?.source ?? getContentSource();
|
|
26
|
+
}
|
package/lib/content-types.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { Article, ArticleVideoAsset } from "./articles";
|
|
2
2
|
import type { EditionLayoutPlan } from "./layout-plan";
|
|
3
3
|
import type { PublicationItem } from "./publication-items";
|
|
4
|
+
import type { VideoScriptRef } from "./video-script";
|
|
4
5
|
|
|
5
6
|
export type ContentSource = "scenario" | "graphql";
|
|
6
7
|
|
|
@@ -55,6 +56,8 @@ export type EditionContent = {
|
|
|
55
56
|
scenarioId?: string;
|
|
56
57
|
description?: string;
|
|
57
58
|
editionVideo?: ArticleVideoAsset | null;
|
|
59
|
+
/** Video scripts by item slug (`"edition-overview"` for the edition video), for the VideoML preview. */
|
|
60
|
+
videoScripts?: Record<string, VideoScriptRef>;
|
|
58
61
|
};
|
|
59
62
|
|
|
60
63
|
export type EditionRouteSummary = {
|
|
@@ -101,4 +104,5 @@ export type ContentRepository = {
|
|
|
101
104
|
getEditionArticle(options: GetEditionArticleOptions): Article | undefined | Promise<Article | undefined>;
|
|
102
105
|
getEditionItem(options: GetEditionItemOptions): PublicationItem | undefined | Promise<PublicationItem | undefined>;
|
|
103
106
|
listArticleSlugs(): string[] | Promise<string[]>;
|
|
107
|
+
loadVideoScript(targetSlug: string): VideoScriptRef | null | Promise<VideoScriptRef | null>;
|
|
104
108
|
};
|