Skip to content

Commit 4305d22

Browse files
authored
Merge pull request #875 from opsmill/fix/sidebar-cross-repo-paths
fix: make sidebar path detection work in both repos
2 parents ca47d40 + 1564076 commit 4305d22

3 files changed

Lines changed: 24 additions & 4 deletions

File tree

docs/sidebars/sidebar-utils.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,23 @@
1+
import { existsSync } from 'fs';
2+
import { join } from 'path';
3+
4+
/**
5+
* Detects the base directory containing the docs content (python-sdk/, infrahubctl/, etc.).
6+
*
7+
* The sidebar files live in different locations depending on which repo they are in:
8+
* - infrahub-sdk-python: docs/sidebars/ → content is at docs/docs/
9+
* - infrahub-docs: docs/ → content is at docs/docs-python-sdk/
10+
*
11+
* We detect the active layout by checking whether the SDK-repo content path exists.
12+
*/
13+
export function getDocsBaseDir(): string {
14+
const sdkRepoDocsDir = join(__dirname, '..', 'docs');
15+
if (existsSync(join(sdkRepoDocsDir, 'python-sdk'))) {
16+
return sdkRepoDocsDir;
17+
}
18+
return join(__dirname, 'docs-python-sdk');
19+
}
20+
121
export function getCommandItems(files: string[], indexFile: string = 'infrahubctl.mdx'): string[] {
222
return files
323
.filter(file => file.endsWith('.mdx') && file !== indexFile)

docs/sidebars/sidebars-infrahubctl.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import type {SidebarsConfig} from '@docusaurus/plugin-content-docs';
22
import {readdirSync} from 'fs';
33
import {join} from 'path';
4-
import {getCommandItems} from './sidebar-utils';
4+
import {getCommandItems, getDocsBaseDir} from './sidebar-utils';
55

6-
const docsDir = join(__dirname, '..', 'docs', 'infrahubctl');
6+
const docsDir = join(getDocsBaseDir(), 'infrahubctl');
77
const commandItems = getCommandItems(readdirSync(docsDir));
88

99
const sidebars: SidebarsConfig = {

docs/sidebars/sidebars-python-sdk.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import type { SidebarsConfig } from '@docusaurus/plugin-content-docs';
22
import { readdirSync } from 'fs';
33
import { join } from 'path';
4-
import { getItemsWithOrder } from './sidebar-utils';
4+
import { getDocsBaseDir, getItemsWithOrder } from './sidebar-utils';
55

6-
const pythonSdkDocsDir = join(__dirname, '..', 'docs', 'python-sdk');
6+
const pythonSdkDocsDir = join(getDocsBaseDir(), 'python-sdk');
77

88
const guidesItems = getItemsWithOrder(
99
readdirSync(join(pythonSdkDocsDir, 'guides')),

0 commit comments

Comments
 (0)