Skip to content

Commit 78616ff

Browse files
committed
fix(cli): properly map next.js path export for GitHub Pages and user paths
1 parent d2c8669 commit 78616ff

3 files changed

Lines changed: 29 additions & 14 deletions

File tree

cli/application/home/handler.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ export async function executeHome(params, runtime) {
3535
...process.env,
3636
GITHUB_ACTIONS: "true",
3737
GITPAGEDOCS_REPOSITORY_SEARCH: String(repositorySearch),
38-
GITPAGEDOCS_BASE_PATH: pathSegment ? `/${pathSegment}` : "",
38+
GITPAGEDOCS_BASE_PATH: pathSegment ? `/${pathSegment}` : "/",
3939
GITPAGEDOCS_PATH: pathSegment,
4040
};
4141

cli/runtime/workflow.mjs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export async function ensureGitHubPagesWorkflow(getCurrentGitBranch, writeText,
1111
? ` env:
1212
GITHUB_ACTIONS: "true"
1313
GITHUB_REPOSITORY: \${{ github.repository }}
14-
GITPAGEDOCS_BASE_PATH: "/\${{ github.event.repository.name }}/${pathSegment}"`
14+
GITPAGEDOCS_PATH: "${pathSegment}"`
1515
: ` env:
1616
GITHUB_ACTIONS: "true"
1717
GITHUB_REPOSITORY: \${{ github.repository }}`;
@@ -74,6 +74,14 @@ jobs:
7474
working-directory: .gitpagedocs-runtime
7575
${buildEnvBlock}
7676
77+
- name: Relocate output to custom docs path
78+
if: \${{ env.GITPAGEDOCS_PATH != '' }}
79+
run: |
80+
mkdir -p .gitpagedocs-runtime/out_new/\${{ env.GITPAGEDOCS_PATH }}
81+
mv .gitpagedocs-runtime/out/* .gitpagedocs-runtime/out_new/\${{ env.GITPAGEDOCS_PATH }}/
82+
rm -rf .gitpagedocs-runtime/out
83+
mv .gitpagedocs-runtime/out_new .gitpagedocs-runtime/out
84+
7785
- name: Force root URL to docs entrypoint
7886
env:
7987
GITHUB_REPOSITORY: \${{ github.repository }}
@@ -83,6 +91,7 @@ ${buildEnvBlock}
8391
const path = require('path');
8492
const pathSegment = ${JSON.stringify(pathSegment)};
8593
const repoName = (process.env.GITHUB_REPOSITORY || '').split('/')[1] || '';
94+
const isUserPage = repoName.toLowerCase().endsWith('.github.io');
8695
const rootRedirectBase = pathSegment;
8796
const cfgPath = path.join('.gitpagedocs-runtime', 'gitpagedocs', 'config.json');
8897
if (!fs.existsSync(cfgPath)) process.exit(0);
@@ -96,7 +105,7 @@ ${buildEnvBlock}
96105
const rootHtml = '<!doctype html><html><head><meta charset="utf-8"><meta http-equiv="refresh" content="0;url=' + redirectTargetRoot + '"/><script>window.location.replace("' + redirectTargetRoot + '" + (window.location.search || ""));</script></head><body>Redirecting...</body></html>';
97106
fs.writeFileSync(path.join('.gitpagedocs-runtime', 'out', 'index.html'), rootHtml);
98107
const projectPathSegments = [];
99-
if (repoName) projectPathSegments.push(repoName);
108+
if (repoName && !isUserPage) projectPathSegments.push(repoName);
100109
if (pathSegment) projectPathSegments.push(pathSegment);
101110
if (projectPathSegments.length > 0) {
102111
const projectIndexPath = path.join('.gitpagedocs-runtime', 'out', ...projectPathSegments, 'index.html');

next.config.ts

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,29 @@ const isGithubPagesBuild = process.env.GITHUB_ACTIONS === "true";
44
const repositorySearchEnabledByEnv = process.env.GITPAGEDOCS_REPOSITORY_SEARCH === "true";
55
const emulateGithubPagesRuntime = isGithubPagesBuild || repositorySearchEnabledByEnv;
66
const repositoryName = process.env.GITHUB_REPOSITORY?.split("/")[1] ?? "git-page-docs";
7-
const basePathFromEnv = process.env.GITPAGEDOCS_BASE_PATH;
7+
const isUserPage = repositoryName.toLowerCase().endsWith(".github.io");
8+
9+
const rawDocsPath = process.env.GITPAGEDOCS_PATH?.trim();
10+
const docsPathSegment = rawDocsPath ? rawDocsPath.replace(/^\/+|\/+$/g, "") : "";
811

912
// Local path: only when GITPAGEDOCS_REPOSITORY_SEARCH=false and GITPAGEDOCS_PATH is set
1013
const isLocalMode = !repositorySearchEnabledByEnv && !isGithubPagesBuild;
11-
const localPathRaw = process.env.GITPAGEDOCS_PATH?.trim();
12-
const localBasePath =
13-
isLocalMode && localPathRaw
14-
? "/" + localPathRaw.replace(/^\/+|\/+$/g, "")
15-
: undefined;
1614

17-
// Treat empty string as "not set" so fallback to /repositoryName is used for project sites
15+
// Explicit base path definition taking precedence (interprets "/" and "" as root/undefined)
16+
const explicitBasePath = "GITPAGEDOCS_BASE_PATH" in process.env
17+
? (process.env.GITPAGEDOCS_BASE_PATH === "/" || process.env.GITPAGEDOCS_BASE_PATH === ""
18+
? undefined
19+
: process.env.GITPAGEDOCS_BASE_PATH)
20+
: null;
21+
1822
const basePath =
19-
localBasePath ??
20-
(basePathFromEnv !== undefined && basePathFromEnv !== ""
21-
? basePathFromEnv
23+
explicitBasePath ??
24+
(isLocalMode
25+
? (docsPathSegment ? `/${docsPathSegment}` : undefined)
2226
: emulateGithubPagesRuntime
23-
? `/${repositoryName}`
27+
? (isUserPage
28+
? (docsPathSegment ? `/${docsPathSegment}` : undefined)
29+
: `/${repositoryName}${docsPathSegment ? `/${docsPathSegment}` : ""}`)
2430
: undefined);
2531

2632
const nextConfig: NextConfig = {

0 commit comments

Comments
 (0)