Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions apps/web/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
# Local Netlify folder
.netlify

# Generated Standard.site Record Manifest
src/generated/
3 changes: 3 additions & 0 deletions apps/web/netlify.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
[build]
command = "pnpm run build"
publish = "apps/web/dist"

[context.production.build]
command = "pnpm --filter @lukebennett/web build:production"
8 changes: 6 additions & 2 deletions apps/web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"scripts": {
"astro": "astro",
"build": "astro build",
"build:production": "pnpm run check && pnpm run standard-site:sync -- --write && pnpm run build",
"check": "pnpm exec prettier 'src/**/*.astro' --cache --check && pnpm biome check && pnpm run check:types",
"check:format": "pnpm exec prettier 'src/**/*.astro' --cache --check && pnpm biome format",
"check:lint": "pnpm biome lint",
Expand All @@ -15,7 +16,9 @@
"fix": "pnpm biome check --write",
"fix:format": "pnpm exec prettier 'src/**/*.astro' --cache --write && pnpm biome format --write",
"fix:lint": "pnpm biome lint --write",
"lint": "pnpm biome lint --write"
"lint": "pnpm biome lint --write",
"standard-site:sync": "node --experimental-strip-types scripts/sync-standard-site.ts",
"test:standard-site": "node --experimental-strip-types --test src/lib/standard-site.test.ts scripts/sync-standard-site.test.ts"
},
"dependencies": {
"@astrojs/compiler-rs": "^0.1.2",
Expand All @@ -36,7 +39,8 @@
"shiki": "^4.0.2",
"tailwind-merge": "^3.5.0",
"tailwindcss": "^4.2.4",
"tiny-invariant": "^1.3.3"
"tiny-invariant": "^1.3.3",
"zod": "^4.4.3"
},
"devDependencies": {
"@astrojs/check": "^0.9.9",
Expand Down
181 changes: 181 additions & 0 deletions apps/web/scripts/sync-standard-site.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,181 @@
import assert from 'node:assert/strict';
import test from 'node:test';
import {
buildDocumentRecord,
compareOwnedDocumentFields,
extractPortableContent,
getDocumentUri,
isValidRecordKey,
mergeOwnedDocumentFields,
planReconciliation,
toPlainText,
} from './sync-standard-site.ts';

test('extractPortableContent returns body after frontmatter', () => {
assert.equal(
extractPortableContent(
'hello-world.mdoc',
`---
title: Hello World
publishedAt: 2024-01-20
isDraft: false
---
Hello [there](https://example.com).
`,
),
'Hello [there](https://example.com).\n',
);
});

test('extractPortableContent rejects missing frontmatter boundary', () => {
assert.throws(
() => extractPortableContent('broken.mdoc', 'Hello world'),
/broken.mdoc is missing frontmatter/,
);
});

test('isValidRecordKey accepts current slug shape', () => {
assert.equal(isValidRecordKey('top-picks-2024-february'), true);
assert.equal(isValidRecordKey('uses'), true);
});

test('isValidRecordKey rejects invalid ATProto record keys', () => {
assert.equal(isValidRecordKey('.'), false);
assert.equal(isValidRecordKey('bad/slash'), false);
assert.equal(isValidRecordKey(''), false);
});

test('buildDocumentRecord creates a Standard.site document record with Portable Content', () => {
const record = buildDocumentRecord({
portableContent: 'Hello [there](https://example.com).\n',
publishedAt: '2024-01-20',
slug: 'hello-world',
title: 'Hello World',
});

assert.deepEqual(record, {
$type: 'site.standard.document',
content: {
$type: 'at.markpub.markdown',
text: {
$type: 'at.markpub.text',
markdown: 'Hello [there](https://example.com).\n',
},
},
description: 'Hello there.',
path: '/posts/hello-world',
publishedAt: '2024-01-20T00:00:00.000Z',
site: 'at://did:plc:3z5ja7l2rhnmtr2bni5dyfe7/site.standard.publication/3mnqwgvxn372f',
textContent: 'Hello there.',
title: 'Hello World',
});
});

test('getDocumentUri uses raw slug as record key', () => {
assert.equal(
getDocumentUri('did:plc:example', 'hello-world'),
'at://did:plc:example/site.standard.document/hello-world',
);
});

test('compareOwnedDocumentFields ignores unknown remote fields', () => {
const generated = buildDocumentRecord({
portableContent: 'Hello.',
publishedAt: '2024-01-20',
slug: 'hello-world',
title: 'Hello World',
});

assert.equal(
compareOwnedDocumentFields(generated, {
...generated,
unknownFutureField: true,
}),
true,
);
});

test('mergeOwnedDocumentFields preserves unknown remote fields', () => {
const generated = buildDocumentRecord({
portableContent: 'Hello.',
publishedAt: '2024-01-20',
slug: 'hello-world',
title: 'Hello World',
});

assert.deepEqual(mergeOwnedDocumentFields({ extra: 'keep' }, generated), {
...generated,
extra: 'keep',
});
});

test('planReconciliation creates missing records and deletes withdrawn post records', () => {
const post = {
portableContent: 'Hello.',
publishedAt: '2024-01-20',
slug: 'hello-world',
title: 'Hello World',
};

const plan = planReconciliation({
did: 'did:plc:example',
existingRecords: [
{
uri: 'at://did:plc:example/site.standard.document/old-post',
value: {
$type: 'site.standard.document',
path: '/posts/old-post',
site: 'at://did:plc:3z5ja7l2rhnmtr2bni5dyfe7/site.standard.publication/3mnqwgvxn372f',
},
},
],
posts: [post],
});

assert.deepEqual(
plan.creates.map((item) => item.slug),
['hello-world'],
);
assert.deepEqual(
plan.deletes.map((item) => item.slug),
['old-post'],
);
});

test('planReconciliation fails on unexpected existing record key', () => {
assert.throws(
() =>
planReconciliation({
did: 'did:plc:example',
existingRecords: [
{
uri: 'at://did:plc:example/site.standard.document/generated-key',
value: {
$type: 'site.standard.document',
path: '/posts/hello-world',
site: 'at://did:plc:3z5ja7l2rhnmtr2bni5dyfe7/site.standard.publication/3mnqwgvxn372f',
},
},
],
posts: [
{
portableContent: 'Hello.',
publishedAt: '2024-01-20',
slug: 'hello-world',
title: 'Hello World',
},
],
}),
/manual cleanup/,
);
});

test('toPlainText strips Markdown links and Markdoc component blocks', () => {
assert.equal(
toPlainText(`Hello [there](https://example.com).

{% cloudImage src="https://example.com/image" /%}
`),
'Hello there.',
);
});
Loading