From 1b0872a93f74f31ac7eb8032ab1b9adf447e9c69 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Lohrer?= Date: Tue, 21 Apr 2026 09:19:35 +0200 Subject: [PATCH] =?UTF-8?q?feat(publish):=20validatePost=20pr=C3=BCft=20a-?= =?UTF-8?q?tag-format?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- publish/src/core/validation.ts | 11 +++++++++++ publish/tests/validation_test.ts | 30 ++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+) diff --git a/publish/src/core/validation.ts b/publish/src/core/validation.ts index 17d1184..21792f3 100644 --- a/publish/src/core/validation.ts +++ b/publish/src/core/validation.ts @@ -27,4 +27,15 @@ export function validatePost(fm: Frontmatter): void { if (!(fm.date instanceof Date) || isNaN(fm.date.getTime())) { throw new Error('missing/invalid date (expected YAML date or ISO-string)') } + if (fm.a !== undefined) { + if (!Array.isArray(fm.a)) { + throw new Error('a must be a list of strings') + } + const coordRe = /^\d+:[0-9a-f]+:[a-z0-9][a-z0-9-]*$/ + for (const coord of fm.a) { + if (typeof coord !== 'string' || !coordRe.test(coord)) { + throw new Error(`invalid a-tag: "${coord}" (expected "::")`) + } + } + } } diff --git a/publish/tests/validation_test.ts b/publish/tests/validation_test.ts index c38061d..547f06c 100644 --- a/publish/tests/validation_test.ts +++ b/publish/tests/validation_test.ts @@ -56,3 +56,33 @@ Deno.test('validatePost: akzeptiert ISO-string-date', () => { validatePost(fm) assertEquals(fm.date instanceof Date, true) }) + +Deno.test('validatePost: akzeptiert a-tag im korrekten format', () => { + const fm = { + title: 'T', + slug: 'abc', + date: new Date('2024-01-01'), + a: ['30023:abcdef0123456789:other-slug'], + } as Frontmatter + validatePost(fm) // wirft nicht +}) + +Deno.test('validatePost: lehnt a-tag mit falschem format ab', () => { + const fm = { + title: 'T', + slug: 'abc', + date: new Date('2024-01-01'), + a: ['nur-ein-string'], + } as Frontmatter + assertThrows(() => validatePost(fm), Error, 'invalid a-tag') +}) + +Deno.test('validatePost: lehnt a-tag mit fehlendem d-tag ab', () => { + const fm = { + title: 'T', + slug: 'abc', + date: new Date('2024-01-01'), + a: ['30023:abcdef:'], + } as Frontmatter + assertThrows(() => validatePost(fm), Error, 'invalid a-tag') +})