Skip to content

Commit 75bd98d

Browse files
authored
V2: robots.txt, sitemap.xml, image resizing, etc (#2895)
1 parent 9b914d1 commit 75bd98d

File tree

53 files changed

+1331
-971
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+1331
-971
lines changed

packages/gitbook-v2/src/app/sites/dynamic/[mode]/[siteURL]/layout.tsx

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,21 @@
11
import { CustomizationRootLayout } from '@/components/RootLayout';
2-
import { SiteLayout } from '@/components/SiteLayout';
2+
import {
3+
SiteLayout,
4+
generateSiteLayoutMetadata,
5+
generateSiteLayoutViewport,
6+
} from '@/components/SiteLayout';
37
import { type RouteLayoutParams, getDynamicSiteContext } from '@v2/app/utils';
48
import { GITBOOK_DISABLE_TRACKING } from '@v2/lib/env';
59
import { getThemeFromMiddleware } from '@v2/lib/middleware';
610

11+
interface SiteDynamicLayoutProps {
12+
params: Promise<RouteLayoutParams>;
13+
}
14+
715
export default async function SiteDynamicLayout({
816
params,
917
children,
10-
}: {
11-
params: Promise<RouteLayoutParams>;
12-
children: React.ReactNode;
13-
}) {
18+
}: React.PropsWithChildren<SiteDynamicLayoutProps>) {
1419
const context = await getDynamicSiteContext(await params);
1520
const forcedTheme = await getThemeFromMiddleware();
1621

@@ -26,3 +31,13 @@ export default async function SiteDynamicLayout({
2631
</CustomizationRootLayout>
2732
);
2833
}
34+
35+
export async function generateViewport({ params }: SiteDynamicLayoutProps) {
36+
const context = await getDynamicSiteContext(await params);
37+
return generateSiteLayoutViewport(context);
38+
}
39+
40+
export async function generateMetadata({ params }: SiteDynamicLayoutProps) {
41+
const context = await getDynamicSiteContext(await params);
42+
return generateSiteLayoutMetadata(context);
43+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import type { NextRequest } from 'next/server';
2+
3+
import { serveLLMsTxt } from '@/routes/llms';
4+
import { type RouteLayoutParams, getDynamicSiteContext } from '@v2/app/utils';
5+
6+
export async function GET(
7+
_request: NextRequest,
8+
{ params }: { params: Promise<RouteLayoutParams> }
9+
) {
10+
const context = await getDynamicSiteContext(await params);
11+
return serveLLMsTxt(context);
12+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import type { NextRequest } from 'next/server';
2+
3+
import { serveRobotsTxt } from '@/routes/robots';
4+
import { type RouteLayoutParams, getDynamicSiteContext } from '@v2/app/utils';
5+
6+
export async function GET(
7+
_request: NextRequest,
8+
{ params }: { params: Promise<RouteLayoutParams> }
9+
) {
10+
const context = await getDynamicSiteContext(await params);
11+
return serveRobotsTxt(context);
12+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import type { NextRequest } from 'next/server';
2+
3+
import { servePagesSitemap } from '@/routes/sitemap';
4+
import { type RouteLayoutParams, getDynamicSiteContext } from '@v2/app/utils';
5+
6+
export async function GET(
7+
_request: NextRequest,
8+
{ params }: { params: Promise<RouteLayoutParams> }
9+
) {
10+
const context = await getDynamicSiteContext(await params);
11+
return servePagesSitemap(context);
12+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import type { NextRequest } from 'next/server';
2+
3+
import { serveRootSitemap } from '@/routes/sitemap';
4+
import { type RouteLayoutParams, getDynamicSiteContext } from '@v2/app/utils';
5+
6+
export async function GET(
7+
_request: NextRequest,
8+
{ params }: { params: Promise<RouteLayoutParams> }
9+
) {
10+
const context = await getDynamicSiteContext(await params);
11+
return serveRootSitemap(context);
12+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import type { NextRequest } from 'next/server';
2+
3+
import { serveIcon } from '@/routes/icon';
4+
import { type RouteLayoutParams, getDynamicSiteContext } from '@v2/app/utils';
5+
6+
export const dynamic = 'force-static';
7+
8+
export async function GET(
9+
request: NextRequest,
10+
{ params }: { params: Promise<RouteLayoutParams> }
11+
) {
12+
const context = await getDynamicSiteContext(await params);
13+
return serveIcon(context, request);
14+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import type { NextRequest } from 'next/server';
2+
3+
import type { PageIdParams } from '@/components/SitePage';
4+
import { serveOGImage } from '@/routes/ogimage';
5+
import { type RouteLayoutParams, getDynamicSiteContext } from '@v2/app/utils';
6+
7+
export async function GET(
8+
_request: NextRequest,
9+
{ params }: { params: Promise<RouteLayoutParams & PageIdParams> }
10+
) {
11+
const context = await getDynamicSiteContext(await params);
12+
return serveOGImage(context, await params);
13+
}

packages/gitbook-v2/src/app/sites/static/[mode]/[siteURL]/layout.tsx

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,22 @@
11
import { CustomizationRootLayout } from '@/components/RootLayout';
2-
import { SiteLayout } from '@/components/SiteLayout';
2+
import {
3+
SiteLayout,
4+
generateSiteLayoutMetadata,
5+
generateSiteLayoutViewport,
6+
} from '@/components/SiteLayout';
37
import { type RouteLayoutParams, getStaticSiteContext } from '@v2/app/utils';
48
import { getSiteCacheTag } from '@v2/lib/cache';
59
import { GITBOOK_DISABLE_TRACKING } from '@v2/lib/env';
610
import { unstable_cacheTag as cacheTag } from 'next/cache';
711

12+
interface SiteStaticLayoutProps {
13+
params: Promise<RouteLayoutParams>;
14+
}
15+
816
export default async function SiteStaticLayout({
917
params,
1018
children,
11-
}: {
12-
params: Promise<RouteLayoutParams>;
13-
children: React.ReactNode;
14-
}) {
19+
}: React.PropsWithChildren<SiteStaticLayoutProps>) {
1520
'use cache';
1621

1722
const context = await getStaticSiteContext(await params);
@@ -26,3 +31,13 @@ export default async function SiteStaticLayout({
2631
</CustomizationRootLayout>
2732
);
2833
}
34+
35+
export async function generateViewport({ params }: SiteStaticLayoutProps) {
36+
const context = await getStaticSiteContext(await params);
37+
return generateSiteLayoutViewport(context);
38+
}
39+
40+
export async function generateMetadata({ params }: SiteStaticLayoutProps) {
41+
const context = await getStaticSiteContext(await params);
42+
return generateSiteLayoutMetadata(context);
43+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import type { NextRequest } from 'next/server';
2+
3+
import { serveLLMsTxt } from '@/routes/llms';
4+
import { type RouteLayoutParams, getStaticSiteContext } from '@v2/app/utils';
5+
6+
export const dynamic = 'force-static';
7+
8+
export async function GET(
9+
_request: NextRequest,
10+
{ params }: { params: Promise<RouteLayoutParams> }
11+
) {
12+
const context = await getStaticSiteContext(await params);
13+
return serveLLMsTxt(context);
14+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import type { NextRequest } from 'next/server';
2+
3+
import { serveRobotsTxt } from '@/routes/robots';
4+
import { type RouteLayoutParams, getStaticSiteContext } from '@v2/app/utils';
5+
6+
export const dynamic = 'force-static';
7+
8+
export async function GET(
9+
_request: NextRequest,
10+
{ params }: { params: Promise<RouteLayoutParams> }
11+
) {
12+
const context = await getStaticSiteContext(await params);
13+
return serveRobotsTxt(context);
14+
}

0 commit comments

Comments
 (0)