Skip to content

Commit 7d07aff

Browse files
3mcdtefkah
andauthored
feat: de-astro-ify the site builder; add extensions to pages (#1428)
* feat: de-astro-ify the site builder; add extensions to pages * fix: lint * fix: remove empty file * fix: optimize fetching, logging * fix: pino-pretty * fix: add json * fix: lint --------- Co-authored-by: Thomas F. K. Jorna <hello@tefkah.com>
1 parent 3708191 commit 7d07aff

26 files changed

Lines changed: 286 additions & 471 deletions

File tree

core/actions/buildSite/action.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,15 @@ const schema = z.object({
8888
.string()
8989
.describe("A filter expression that selects which pubs to include"),
9090
slug: z.string().describe("JSONata expression for the page URL slug"),
91-
transform: z.string().describe("JSONata expression that outputs HTML for the page"),
91+
transform: z
92+
.string()
93+
.describe("JSONata expression that outputs content for the page"),
94+
extension: z
95+
.string()
96+
.default("html")
97+
.describe(
98+
"File extension for the generated output (e.g., 'html', 'json', 'xml'). Only 'html' pages are wrapped in an HTML shell."
99+
),
92100
})
93101
)
94102
.min(1)

core/actions/buildSite/form.tsx

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { useFieldArray, useWatch } from "react-hook-form"
66

77
import { Button } from "ui/button"
88
import { FieldDescription, FieldLabel, FieldSet } from "ui/field"
9+
import { Input } from "ui/input"
910
import { MonacoFormField } from "ui/monaco"
1011
import { FieldOutputMap } from "ui/outputMap"
1112
import { usePubFieldContext } from "ui/pubFields"
@@ -154,6 +155,25 @@ export default function BuildSiteActionForm() {
154155
/>
155156
</div>
156157

158+
<div>
159+
<FieldLabel className="text-xs">File Extension</FieldLabel>
160+
<FieldDescription className="text-xs">
161+
Output file type. Only &quot;html&quot; pages are wrapped in an HTML
162+
shell.
163+
</FieldDescription>
164+
<ActionField
165+
name={`pages.${index}.extension`}
166+
render={({ field }) => (
167+
<Input
168+
{...field}
169+
value={field.value ?? "html"}
170+
placeholder="html"
171+
className="h-8 text-sm"
172+
/>
173+
)}
174+
/>
175+
</div>
176+
157177
<div>
158178
<div className="mb-1 flex items-center justify-between">
159179
<FieldLabel className="text-xs">Content Template</FieldLabel>
@@ -224,7 +244,12 @@ export default function BuildSiteActionForm() {
224244
type="button"
225245
size="sm"
226246
onClick={() =>
227-
append({ filter: "", slug: "$.pub.id", transform: DEFAULT_PAGE_TEMPLATE })
247+
append({
248+
filter: "",
249+
slug: "$.pub.id",
250+
transform: DEFAULT_PAGE_TEMPLATE,
251+
extension: "html",
252+
})
228253
}
229254
>
230255
<Plus size={14} className="mr-1" />

core/actions/buildSite/run.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ export const run = defineRun<typeof action>(
110110
slug: pub.slug as string,
111111
})),
112112
transform: page.transform,
113+
extension: page.extension ?? "html",
113114
}
114115
})
115116
)

core/prisma/seeds/coar-notify.ts

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -487,9 +487,10 @@ pre { background: #f3f4f6; padding: 1rem; border-radius: 0.5rem; overflow-x: aut
487487
{
488488
// Individual review page - one per Review pub
489489
slug: "$.pub.id",
490-
// Use all published pubs
491490
filter: '$.pub.pubType.name = "Review"',
492-
transform: `'<article>' &
491+
extension: "html",
492+
transform: `'<link rel="alternate" type="application/json" href="' & $.pub.id & '.json" />' &
493+
'<article>' &
493494
'<h1>' & $.pub.title & '</h1>' &
494495
$join(
495496
$map(
@@ -504,13 +505,27 @@ pre { background: #f3f4f6; padding: 1rem; border-radius: 0.5rem; overflow-x: aut
504505
),
505506
''
506507
) &
508+
'<p><a href="' & $.pub.id & '.json">JSON</a></p>' &
507509
'<p><a href="/">← Back to all reviews</a></p>' &
508510
'</article>'`,
511+
},
512+
{
513+
// JSON manifest - companion metadata for each review
514+
slug: "$.pub.id",
515+
filter: '$.pub.pubType.name = "Review"',
516+
extension: "json",
517+
transform: `$string({
518+
"title": $.pub.title,
519+
"id": $.pub.id,
520+
"type": "Review",
521+
"pubType": $.pub.pubType.name
522+
})`,
509523
},
510524
{
511525
// Index page - lists all published reviews
512526
slug: '"/"',
513527
filter: '$.pub.pubType.name = "Review"',
528+
extension: "html",
514529
transform: `'<h1>Published Reviews</h1>' &
515530
'<ul class="review-list">' &
516531
'<li><a href="/coar-notify/reviews/' & $.pub.id & '">' & $.pub.title & '</a></li>' &

packages/contracts/src/resources/site-builder-2.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ export const siteBuilderApi = contract.router(
2929
})
3030
),
3131
transform: z.string(),
32+
extension: z.string().default("html"),
3233
})
3334
),
3435
siteUrl: z.string(),

pnpm-lock.yaml

Lines changed: 56 additions & 42 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

site-builder-2/.gitignore

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,6 @@
22
dist/**
33
!dist/.gitkeep
44

5-
# generated types
6-
.astro/**
7-
8-
!.astro/.gitkeep
9-
105
# dependencies
116
node_modules/
127

@@ -32,6 +27,5 @@ builds/**
3227
!.env.development
3328
!.env.server.development
3429

30+
.storage/
3531

36-
.storage/**
37-
!.storage/.gitkeep

0 commit comments

Comments
 (0)