feat(publish): allPostDirs traversiert sprach-ebene
This commit is contained in:
parent
d3215fa760
commit
0c2e99dfeb
|
|
@ -54,12 +54,17 @@ export async function changedPostDirs(args: DiffArgs): Promise<string[]> {
|
||||||
|
|
||||||
export async function allPostDirs(contentRoot: string): Promise<string[]> {
|
export async function allPostDirs(contentRoot: string): Promise<string[]> {
|
||||||
const result: string[] = []
|
const result: string[] = []
|
||||||
for await (const entry of Deno.readDir(contentRoot)) {
|
for await (const langEntry of Deno.readDir(contentRoot)) {
|
||||||
if (entry.isDirectory && !entry.name.startsWith('_')) {
|
if (!langEntry.isDirectory) continue
|
||||||
const indexPath = `${contentRoot}/${entry.name}/index.md`
|
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 {
|
try {
|
||||||
const stat = await Deno.stat(indexPath)
|
const stat = await Deno.stat(indexPath)
|
||||||
if (stat.isFile) result.push(`${contentRoot}/${entry.name}`)
|
if (stat.isFile) result.push(`${langDir}/${postEntry.name}`)
|
||||||
} catch {
|
} catch {
|
||||||
// skip folders without index.md
|
// skip folders without index.md
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
import { assertEquals } from '@std/assert'
|
import { assertEquals } from '@std/assert'
|
||||||
import {
|
import {
|
||||||
|
allPostDirs,
|
||||||
changedPostDirs,
|
changedPostDirs,
|
||||||
filterPostDirs,
|
filterPostDirs,
|
||||||
type GitRunner,
|
type GitRunner,
|
||||||
|
|
@ -83,3 +84,25 @@ Deno.test('filterPostDirs: _drafts unter sprach-ebene wird ignoriert', () => {
|
||||||
]
|
]
|
||||||
assertEquals(filterPostDirs(lines, 'content/posts'), ['content/posts/de/real'])
|
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 })
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue