Skip to content

Commit 74de385

Browse files
authored
Merge pull request #134 from code0-tech/revive-docs-preview
Revive docs preview
2 parents f498461 + aa1288f commit 74de385

8 files changed

Lines changed: 64 additions & 10 deletions

File tree

.gitlab-ci.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,18 @@ build:
1414
extends:
1515
- .build
1616
stage: build
17+
variables:
18+
NEXT_PUBLIC_ARTIFACT_VIEWER: "true"
19+
BASE_PATH: /-/development/telescopium/-/jobs/$CI_JOB_ID/artifacts/out
20+
after_script:
21+
- |
22+
echo -e "\e[0Ksection_start:`date +%s`:glpa_summary\r\e[0KHeader of the summary"
23+
echo "Documentation preview available at https://code0-tech.gitlab.io${BASE_PATH}/index.html"
24+
echo -e "\e[0Ksection_end:`date +%s`:glpa_summary\r\e[0K"
25+
artifacts:
26+
expire_in: 7 days
27+
paths:
28+
- out
1729
rules:
1830
- if: ($CI_COMMIT_BRANCH != "build-branch" || $C0_TRIGGER_REF != "refs/heads/main") && $C0_TRIGGER_REF != "refs/heads/main"
1931

app/(home)/layout.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@ import type {ReactNode} from 'react';
33
export default function Layout({children}: { children: ReactNode }) {
44
return (
55
<html lang="en" suppressHydrationWarning>
6-
<head>
7-
<meta httpEquiv={"refresh"} content={"0; URL=code0"}/>
8-
</head>
6+
<head/>
97
<body>
108
{children}
119
</body>

app/(home)/page.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
11
export default function HomePage() {
2-
return <span/>;
2+
return (
3+
<script dangerouslySetInnerHTML={{__html:
4+
`window.location.replace("./code0/${process.env.NEXT_PUBLIC_ARTIFACT_VIEWER === "true" ? "index.html" : ""}")`
5+
}}/>
6+
);
37
}

app/[...slug]/layout.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import '../global.css';
2-
import {RootProvider} from 'fumadocs-ui/provider/next';
2+
import {RootProvider} from '@/app/provider';
33
import {Inter} from 'next/font/google';
44
import type {ReactNode} from 'react';
55
import {source} from "@/lib/source";

app/layout.config.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export const baseOptions: BaseLayoutProps = {
1111
nav: {
1212
title: (
1313
<>
14-
<img src={"/Logo.svg"} alt={"Code0 Logo"} width={16}/>
14+
<img src={`${process.env.BASE_PATH || ""}/Logo.svg`} alt={"Code0 Logo"} width={16}/>
1515
CodeZero
1616
</>
1717
),

app/provider.tsx

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
"use client";
2+
import {type AnchorHTMLAttributes} from "react";
3+
import {FrameworkProvider} from "fumadocs-core/framework";
4+
import type {Framework} from "fumadocs-core/framework";
5+
import {useParams, usePathname, useRouter} from "next/navigation";
6+
import Link from "next/link";
7+
import Image from "next/image";
8+
import {RootProvider as BaseRootProvider, type RootProviderProps} from "fumadocs-ui/provider/base";
9+
10+
const artifactViewer = process.env.NEXT_PUBLIC_ARTIFACT_VIEWER === "true";
11+
12+
function useNormalizedPathname(): string {
13+
const pathname = usePathname();
14+
return pathname.endsWith("/index.html")
15+
? pathname.replace(/\/index\.html$/, "/")
16+
: pathname;
17+
}
18+
19+
function addIndexHtml(href: string): string {
20+
const [path, hash] = href.split("#", 2);
21+
const normalized = path.endsWith("/") ? `${path}index.html` : `${path}/index.html`;
22+
return hash != null ? `${normalized}#${hash}` : normalized;
23+
}
24+
25+
function ArtifactLink({href, prefetch, ...props}: AnchorHTMLAttributes<HTMLAnchorElement> & {prefetch?: boolean}) {
26+
if (!href || href.startsWith("http")) return <a {...props} href={href}/>;
27+
return <Link {...props} href={addIndexHtml(href)}/>;
28+
}
29+
30+
export function RootProvider({children, dir, theme, search, i18n}: RootProviderProps) {
31+
const LinkComponent = artifactViewer ? ArtifactLink : Link;
32+
return (
33+
<FrameworkProvider usePathname={artifactViewer ? useNormalizedPathname : usePathname} useRouter={useRouter} useParams={useParams} Link={LinkComponent as unknown as Framework["Link"]} Image={Image as unknown as Framework["Image"]}>
34+
<BaseRootProvider dir={dir} theme={theme} search={search} i18n={i18n}>
35+
{children}
36+
</BaseRootProvider>
37+
</FrameworkProvider>
38+
);
39+
}

ci-template.gitlab-ci.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ docs:
99
C0_TRIGGER_SHA: $CI_COMMIT_SHA
1010
C0_TRIGGER_REF: $C0_GH_REF
1111

12-
.docs:preview:
12+
docs:preview:
1313
stage: test
1414
image: registry.gitlab.com/gitlab-ci-utils/curl-jq:latest
1515
needs:
@@ -22,11 +22,11 @@ docs:
2222
pipeline(iid: $iid) {
2323
job(name: $bridgeJob) {
2424
downstreamPipeline {
25-
job(name: $downstreamJob) { id }
25+
job(name: $downstreamJob) { id }
26+
}
2627
}
2728
}
2829
}
29-
}
3030
}","variables":{
3131
"fullPath":"'"$CI_PROJECT_PATH"'",
3232
"iid":"'"$CI_PIPELINE_IID"'",
@@ -46,7 +46,7 @@ docs:
4646
- BUILD_JOB_ID=$(echo "$RESPONSE" | jq -r .data.project.pipeline.job.downstreamPipeline.job.id | awk -F '/' '{print $NF}')
4747
- |
4848
echo -e "\e[0Ksection_start:`date +%s`:glpa_summary\r\e[0KHeader of the summary"
49-
echo "Documentation preview available at https://code0-tech.gitlab.io/-/development/telescopium/-/jobs/$BUILD_JOB_ID/artifacts/dist/index.html"
49+
echo "Documentation preview available at https://code0-tech.gitlab.io/-/development/telescopium/-/jobs/$BUILD_JOB_ID/artifacts/out/index.html"
5050
echo -e "\e[0Ksection_end:`date +%s`:glpa_summary\r\e[0K"
5151
rules:
5252
- if: $C0_GH_REF != "refs/heads/main"

next.config.mjs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ const config = {
88
output: 'export',
99
images: { unoptimized: true },
1010
trailingSlash: true,
11+
basePath: process.env.BASE_PATH || '',
1112
};
1213

1314
export default withMDX(config);

0 commit comments

Comments
 (0)