fix(publish): changedPostDirs normalisiert ../-präfix im contentRoot
This commit is contained in:
parent
367af9df9f
commit
b89442bf5c
|
|
@ -4,6 +4,10 @@ function escapeRegex(s: string): string {
|
||||||
return s.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')
|
return s.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function stripParentSegments(path: string): string {
|
||||||
|
return path.replace(/^(\.\.\/)+/, '')
|
||||||
|
}
|
||||||
|
|
||||||
export function filterPostDirs(lines: string[], contentRoot: string): string[] {
|
export function filterPostDirs(lines: string[], contentRoot: string): string[] {
|
||||||
const root = contentRoot.replace(/\/$/, '')
|
const root = contentRoot.replace(/\/$/, '')
|
||||||
const prefix = root + '/'
|
const prefix = root + '/'
|
||||||
|
|
@ -49,7 +53,8 @@ export interface DiffArgs {
|
||||||
export async function changedPostDirs(args: DiffArgs): Promise<string[]> {
|
export async function changedPostDirs(args: DiffArgs): Promise<string[]> {
|
||||||
const runner = args.runner ?? defaultRunner
|
const runner = args.runner ?? defaultRunner
|
||||||
const stdout = await runner(['diff', '--name-only', `${args.from}..${args.to}`])
|
const stdout = await runner(['diff', '--name-only', `${args.from}..${args.to}`])
|
||||||
return filterPostDirs(stdout.split('\n'), args.contentRoot)
|
const normalizedRoot = stripParentSegments(args.contentRoot)
|
||||||
|
return filterPostDirs(stdout.split('\n'), normalizedRoot)
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function allPostDirs(contentRoot: string): Promise<string[]> {
|
export async function allPostDirs(contentRoot: string): Promise<string[]> {
|
||||||
|
|
|
||||||
|
|
@ -85,6 +85,30 @@ 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('changedPostDirs: normalisiert contentRoot mit ../-präfix', async () => {
|
||||||
|
const runner: GitRunner = () =>
|
||||||
|
Promise.resolve('content/posts/de/alpha/index.md\ncontent/posts/en/beta/index.md\n')
|
||||||
|
const dirs = await changedPostDirs({
|
||||||
|
from: 'HEAD~1',
|
||||||
|
to: 'HEAD',
|
||||||
|
contentRoot: '../content/posts',
|
||||||
|
runner,
|
||||||
|
})
|
||||||
|
assertEquals(dirs.sort(), ['content/posts/de/alpha', 'content/posts/en/beta'])
|
||||||
|
})
|
||||||
|
|
||||||
|
Deno.test('changedPostDirs: normalisiert contentRoot mit mehrfachem ../-präfix', async () => {
|
||||||
|
const runner: GitRunner = () =>
|
||||||
|
Promise.resolve('content/posts/de/alpha/index.md\n')
|
||||||
|
const dirs = await changedPostDirs({
|
||||||
|
from: 'HEAD~1',
|
||||||
|
to: 'HEAD',
|
||||||
|
contentRoot: '../../content/posts',
|
||||||
|
runner,
|
||||||
|
})
|
||||||
|
assertEquals(dirs, ['content/posts/de/alpha'])
|
||||||
|
})
|
||||||
|
|
||||||
Deno.test('allPostDirs: findet posts in sprach-unterordnern', async () => {
|
Deno.test('allPostDirs: findet posts in sprach-unterordnern', async () => {
|
||||||
const tmp = await Deno.makeTempDir()
|
const tmp = await Deno.makeTempDir()
|
||||||
try {
|
try {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue