Skip to content

Commit

Permalink
partial-build-extension works for git dir of grandchildren
Browse files Browse the repository at this point in the history
Previously, if the playbook is in a grandchild dir it incorrectly resolves
the dir of ./.. because the regex was invalid

This ensures that playbooks in folders that are grandchildren of the gitdir
still work

Closes gh-35
  • Loading branch information
rwinch committed Jul 29, 2024
1 parent 4d2c208 commit e9ee611
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/partial-build-extension.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ function resolveAuthorUrl (dir) {
return '.'
}
const relpath = ospath.relative(gitRoot, dir)
const segments = (relpath.match(/path.sep/g) || []).length + 1
const segments = [...relpath].filter((c) => c === ospath.sep).length + 1
return '.' + '/..'.repeat(segments)
}

Expand Down
12 changes: 12 additions & 0 deletions test/partial-build-extension-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,18 @@ describe('partial-build-extension', () => {
})
})

it('should rewrite content sources if refname is HEAD and playbook in grandchild dir', async () => {
const playBookDir = ospath.join(WORK_DIR, 'docs/src/main/antora')
await fsp.mkdir(playBookDir, { recursive: true })
await fsp.mkdir(ospath.join(WORK_DIR, '.git'), { recursive: true })
await runScenario({
refname: 'HEAD',
version: '6.1.0-SNAPSHOT',
expectedRefs: { branches: ['HEAD'], tags: [], url: './../../../..' },
playbookDir: playBookDir,
})
})

it('should rewrite content sources when SNAPSHOT version not found if refname is HEAD', async () => {
const playBookDir = WORK_DIR
await fsp.mkdir(ospath.join(WORK_DIR, '.git'), { recursive: true })
Expand Down

0 comments on commit e9ee611

Please sign in to comment.