Skip to content
This repository was archived by the owner on Jan 13, 2025. It is now read-only.

Commit d710430

Browse files
authored
Merge pull request #209 from Cloud-Code-AI/208-cloudflare-deployment-fix
fix: updated build for cloudflare pages
2 parents 2705ab3 + 6ebacc9 commit d710430

File tree

16 files changed

+300
-280
lines changed

16 files changed

+300
-280
lines changed

docs/package.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
{
22
"name": "akiradocs",
3-
"version": "1.0.46",
3+
"version": "1.0.47",
44
"private": true,
55
"scripts": {
66
"translate": "npm run compile && node scripts/translate.js",
7-
"compile": "node scripts/compile.js",
7+
"compile": "node scripts/compile.js && npm run generate-manifest",
88
"generate-sitemap": "node scripts/generate-sitemap.mjs",
99
"dev": "npm run compile && set NEXT_PUBLIC_AKIRADOCS_EDIT_MODE=true && next dev",
1010
"build": "npm run compile && npm run generate-sitemap && set NEXT_PUBLIC_AKIRADOCS_EDIT_MODE=false && next build",
1111
"start": "set NEXT_PUBLIC_AKIRADOCS_EDIT_MODE=false && next start",
1212
"lint": "next lint",
13-
"migrate-gitbook": "node scripts/migrations/gitbook.js"
13+
"migrate-gitbook": "node scripts/migrations/gitbook.js",
14+
"generate-manifest": "node scripts/generate-manifest.js"
1415
},
1516
"dependencies": {
1617
"@ai-sdk/anthropic": "^1.0.1",

docs/scripts/generate-manifest.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
const fs = require('fs');
2+
const path = require('path');
3+
4+
function getAllFiles(dirPath, arrayOfFiles = []) {
5+
const files = fs.readdirSync(dirPath);
6+
7+
files.forEach(file => {
8+
const fullPath = path.join(dirPath, file);
9+
if (fs.statSync(fullPath).isDirectory()) {
10+
getAllFiles(fullPath, arrayOfFiles);
11+
} else {
12+
arrayOfFiles.push(
13+
fullPath.replace(path.join(process.cwd(), 'compiled/'), '')
14+
);
15+
}
16+
});
17+
18+
return arrayOfFiles;
19+
}
20+
21+
const manifest = {
22+
files: getAllFiles(path.join(process.cwd(), 'compiled'))
23+
};
24+
25+
fs.writeFileSync(
26+
path.join(process.cwd(), 'compiled/manifest.json'),
27+
JSON.stringify(manifest, null, 2)
28+
);

docs/src/app/[locale]/[type]/[...slug]/page.tsx

Lines changed: 23 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,13 @@ import { PageNavigation } from '@/components/layout/PageNavigation'
1313
import { MainTitle, SubTitle } from '@/components/blocks/HeadingBlock'
1414
import { SEO } from '@/components/layout/SEO'
1515
import { NotFound } from '@/components/layout/NotFound'
16-
import { TextToSpeech } from '@/components/tts/TextToSpeech'
1716
import { getAkiradocsConfig } from "@/lib/getAkiradocsConfig";
1817
import { getTranslation } from '@/lib/staticTranslation';
1918
import { ClientSideControls } from '@/components/layout/ClientSideControl';
2019
import { Metadata } from 'next'
2120

22-
// export const runtime = 'edge'
23-
export const dynamic = 'force-static';
21+
export const runtime = 'edge'
22+
// export const dynamic = 'force-static';
2423

2524
const PostContainer = ({ children }: { children: React.ReactNode }) => (
2625
<div className="flex-1 min-w-0 px-8 py-6 mx-4 font-sans leading-relaxed relative">
@@ -36,33 +35,33 @@ type Props = {
3635
}>;
3736
}
3837

39-
export async function generateStaticParams() {
40-
const locales = ['en', 'es', 'fr'];
41-
const types = ['docs', 'api', 'articles'];
42-
const allSlugs: { locale: string, type: string, slug: string[] }[] = [];
38+
// export async function generateStaticParams() {
39+
// const locales = ['en', 'es', 'fr'];
40+
// const types = ['docs', 'api', 'articles'];
41+
// const allSlugs: { locale: string, type: string, slug: string[] }[] = [];
4342

44-
locales.forEach(locale => {
45-
types.forEach(type => {
46-
const navigationItems = getContentNavigation({}, locale, type);
47-
if (Array.isArray(navigationItems)) {
48-
navigationItems.forEach(item => {
49-
if (item.slug) {
50-
allSlugs.push({ locale, type, slug: item.slug.split('/') });
51-
}
52-
});
53-
}
54-
});
55-
});
43+
// locales.forEach(locale => {
44+
// types.forEach(type => {
45+
// const navigationItems = getContentNavigation({}, locale, type);
46+
// if (Array.isArray(navigationItems)) {
47+
// navigationItems.forEach(item => {
48+
// if (item.slug) {
49+
// allSlugs.push({ locale, type, slug: item.slug.split('/') });
50+
// }
51+
// });
52+
// }
53+
// });
54+
// });
5655

57-
return allSlugs;
58-
}
56+
// return allSlugs;
57+
// }
5958

6059
export async function generateMetadata({ params }: Props): Promise<Metadata> {
6160
const resolvedParams = await Promise.resolve(params);
6261
const { locale, type, slug: slugArray } = resolvedParams;
6362

6463
const slug = slugArray.length ? slugArray.join('/') : '';
65-
const post = getContentBySlug(locale, type, slug);
64+
const post = await getContentBySlug(locale, type, slug);
6665
const t = getTranslation(locale as 'en' | 'es' | 'fr');
6766
const akiradocsConfig = getAkiradocsConfig();
6867

@@ -94,15 +93,14 @@ export default async function ContentPage({ params }: Props) {
9493
const t = getTranslation(locale as 'en' | 'es' | 'de');
9594

9695
const slug = slugArray.length ? slugArray.join('/') : '';
97-
const post = getContentBySlug(locale, type, slug);
98-
96+
const post = await getContentBySlug(locale, type, slug);
9997
if (!post) {
10098
return <NotFound redirectUrl={`/${locale}/${type}`} />;
10199
}
102100
const akiradocsConfig = getAkiradocsConfig();
103101
const headerConfig = getHeaderConfig();
104102
const footerConfig = getFooterConfig();
105-
const navigationItems = getContentNavigation({}, locale, type);
103+
const navigationItems = await getContentNavigation({}, locale, type);
106104
const { prev, next } = getNextPrevPages(navigationItems, `/${type}/${slug}`);
107105
const pageTitle = t(post.title) || t('common.documentation');
108106
const pageDescription = t(post.description) || t('common.documentationContent');

docs/src/app/[locale]/[type]/page.tsx

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,18 +49,33 @@ export async function generateMetadata({ params }: Props): Promise<Metadata> {
4949
}
5050
}
5151

52+
function formatRedirectUrl(locale: string, type: string, slug: string): string {
53+
// Remove leading/trailing slashes
54+
const cleanSlug = slug.replace(/^\/+|\/+$/g, '');
55+
56+
// Check if slug already contains locale and/or type
57+
const parts = cleanSlug.split('/');
58+
const slugWithoutLocaleAndType = parts
59+
.filter(part => part !== locale && part !== type)
60+
.join('/');
61+
62+
return `/${locale}/${type}/${slugWithoutLocaleAndType}`;
63+
}
64+
5265
export default async function Page({ params }: Props) {
5366
const resolvedParams = await Promise.resolve(params);
5467
const { locale, type } = resolvedParams;
5568

5669
// Get the first/default content for this type
57-
const recentContent = getRecentContent(`${locale}/${type}`);
70+
const recentContent = await getRecentContent(`${locale}/${type}`);
5871

5972
if (recentContent) {
60-
const redirectUrl = `/${locale}/${type}/${recentContent.slug.replace(`${type}/`, '')}`;
73+
const redirectUrl = formatRedirectUrl(locale, type, recentContent.slug);
6174
redirect(redirectUrl);
6275
}
6376

6477
// Fallback redirect if no content found
78+
console.log("redirecting to", `/${locale}`);
6579
redirect(`/${locale}`);
6680
}
81+

docs/src/app/page.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export async function generateMetadata() {
1919
export default async function DocPage() {
2020
const config = getAkiradocsConfig()
2121
const defaultLocale = config.localization.defaultLocale
22-
const recentContent = getRecentContent(`${defaultLocale}/docs`)
22+
const recentContent = await getRecentContent(`${defaultLocale}/docs`)
2323

2424
if (recentContent) {
2525
const redirectUrl = `/${defaultLocale}/docs/${recentContent.slug.replace('docs/', '')}`

docs/src/components/layout/Navigation.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,8 +133,8 @@ const NavItem = React.memo(({ locale, item, pathname, depth = 0 }: NavItemProps)
133133

134134
NavItem.displayName = 'NavItem'
135135

136-
export function ApiSidebar() {
137-
const navigation = getApiNavigation();
136+
export async function ApiSidebar() {
137+
const navigation = await getApiNavigation();
138138

139139
return (
140140
<ErrorBoundary FallbackComponent={ErrorFallback}>

0 commit comments

Comments
 (0)