From 0c2e99dfebaf3bfb8d2f0bc0f2d4f90d6c85b283 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Lohrer?= Date: Tue, 21 Apr 2026 09:10:27 +0200 Subject: [PATCH] feat(publish): allPostDirs traversiert sprach-ebene --- publish/src/core/change-detection.ts | 13 +++++++++---- publish/tests/change-detection_test.ts | 23 +++++++++++++++++++++++ 2 files changed, 32 insertions(+), 4 deletions(-) diff --git a/publish/src/core/change-detection.ts b/publish/src/core/change-detection.ts index e4dc0e0..2dacde0 100644 --- a/publish/src/core/change-detection.ts +++ b/publish/src/core/change-detection.ts @@ -54,12 +54,17 @@ export async function changedPostDirs(args: DiffArgs): Promise { export async function allPostDirs(contentRoot: string): Promise { const result: string[] = [] - for await (const entry of Deno.readDir(contentRoot)) { - if (entry.isDirectory && !entry.name.startsWith('_')) { - const indexPath = `${contentRoot}/${entry.name}/index.md` + for await (const langEntry of Deno.readDir(contentRoot)) { + if (!langEntry.isDirectory) continue + if (!/^[a-z]{2}$/.test(langEntry.name)) continue + const langDir = `${contentRoot}/${langEntry.name}` + for await (const postEntry of Deno.readDir(langDir)) { + if (!postEntry.isDirectory) continue + if (postEntry.name.startsWith('_')) continue + const indexPath = `${langDir}/${postEntry.name}/index.md` try { const stat = await Deno.stat(indexPath) - if (stat.isFile) result.push(`${contentRoot}/${entry.name}`) + if (stat.isFile) result.push(`${langDir}/${postEntry.name}`) } catch { // skip folders without index.md } diff --git a/publish/tests/change-detection_test.ts b/publish/tests/change-detection_test.ts index 1e0c24e..fdecbd8 100644 --- a/publish/tests/change-detection_test.ts +++ b/publish/tests/change-detection_test.ts @@ -1,5 +1,6 @@ import { assertEquals } from '@std/assert' import { + allPostDirs, changedPostDirs, filterPostDirs, type GitRunner, @@ -83,3 +84,25 @@ Deno.test('filterPostDirs: _drafts unter sprach-ebene wird ignoriert', () => { ] assertEquals(filterPostDirs(lines, 'content/posts'), ['content/posts/de/real']) }) + +Deno.test('allPostDirs: findet posts in sprach-unterordnern', async () => { + const tmp = await Deno.makeTempDir() + try { + await Deno.mkdir(`${tmp}/de/alpha`, { recursive: true }) + await Deno.writeTextFile(`${tmp}/de/alpha/index.md`, '---\n---') + await Deno.mkdir(`${tmp}/de/beta`, { recursive: true }) + await Deno.writeTextFile(`${tmp}/de/beta/index.md`, '---\n---') + await Deno.mkdir(`${tmp}/en/alpha`, { recursive: true }) + await Deno.writeTextFile(`${tmp}/en/alpha/index.md`, '---\n---') + await Deno.mkdir(`${tmp}/de/_draft/index`, { recursive: true }) + await Deno.writeTextFile(`${tmp}/de/_draft/index.md`, '---\n---') + + const result = await allPostDirs(tmp) + assertEquals( + result.sort(), + [`${tmp}/de/alpha`, `${tmp}/de/beta`, `${tmp}/en/alpha`].sort(), + ) + } finally { + await Deno.remove(tmp, { recursive: true }) + } +})