Skip to content

armgit / kaneo

Public Imported from GitHub
0

⚡ Project management that doesn't become the project. Boards, Gantt charts, and GitHub integration. Self-host it or use Kaneo Cloud.

feat: add sitemap generation and Open Graph image support

Andrej0ba4fb09eca1
diff --git a/apps/docs/app/docs-og/[...slug]/route.ts b/apps/docs/app/docs-og/[...slug]/route.ts
new file mode 100644
index 000000000..3ee6e5fe6
--- /dev/null
+++ b/apps/docs/app/docs-og/[...slug]/route.ts
@@ -0,0 +1,25 @@
+import { source } from "@/lib/source";
+import { generateOGImage } from "fumadocs-ui/og";
+import { notFound } from "next/navigation";
+
+export async function GET(
+ _req: Request,
+ { params }: { params: Promise<{ slug: string[] }> },
+) {
+ const { slug } = await params;
+ const page = source.getPage(slug.slice(0, -1));
+ if (!page) notFound();
+
+ return generateOGImage({
+ title: page.data.title,
+ description: page.data.description,
+ site: "My App",
+ });
+}
+
+export function generateStaticParams() {
+ return source.generateParams().map((page) => ({
+ ...page,
+ slug: [...page.slug, "image.png"],
+ }));
+}
diff --git a/apps/docs/app/docs/[[...slug]]/page.tsx b/apps/docs/app/docs/[[...slug]]/page.tsx
index 2a10ce5af..68fcc1a79 100644
--- a/apps/docs/app/docs/[[...slug]]/page.tsx
+++ b/apps/docs/app/docs/[[...slug]]/page.tsx
@@ -2,6 +2,7 @@ import { source } from "@/lib/source";
import { getMDXComponents } from "@/mdx-components";
import { createRelativeLink } from "fumadocs-ui/mdx";
import { DocsBody, DocsPage, DocsTitle } from "fumadocs-ui/page";
+import type { Metadata } from "next";
import { notFound } from "next/navigation";
export default async function Page(props: {
@@ -11,13 +12,13 @@ export default async function Page(props: {
const page = source.getPage(params.slug);
if (!page) notFound();
- const MDXContent = page.data.body;
+ const MDX = page.data.body;
return (
<DocsPage toc={page.data.toc} full={page.data.full}>
<DocsTitle>{page.data.title}</DocsTitle>
<DocsBody>
- <MDXContent
+ <MDX
components={getMDXComponents({
a: createRelativeLink(source, page),
})}
@@ -31,15 +32,35 @@ export async function generateStaticParams() {
return source.generateParams();
}
-export async function generateMetadata(props: {
+export async function generateMetadata({
+ params,
+}: {
params: Promise<{ slug?: string[] }>;
}) {
- const params = await props.params;
- const page = source.getPage(params.slug);
+ const { slug = [] } = await params;
+ const page = source.getPage(slug);
if (!page) notFound();
+ const image = ["/docs-og", ...slug, "image.png"].join("/");
return {
title: page.data.title,
description: page.data.description,
- };
+ openGraph: {
+ images: image,
+ title: page.data.title,
+ description: page.data.description,
+ url: `/docs/${page.slugs.join("/")}`,
+ siteName: "Kaneo",
+ locale: "en_US",
+ type: "website",
+ },
+ twitter: {
+ card: "summary_large_image",
+ images: image,
+ title: page.data.title,
+ description: page.data.description,
+ creator: "@aacevski",
+ site: "https://kaneo.app",
+ },
+ } satisfies Metadata;
}
diff --git a/apps/docs/app/sitemap.ts b/apps/docs/app/sitemap.ts
new file mode 100644
index 000000000..450ae6a21
--- /dev/null
+++ b/apps/docs/app/sitemap.ts
@@ -0,0 +1,34 @@
+import { source } from "@/lib/source";
+import type { MetadataRoute } from "next";
+
+export const revalidate = false;
+
+export default async function sitemap(): Promise<MetadataRoute.Sitemap> {
+ const url = (path: string): string =>
+ new URL(path, "https://kaneo.app").toString();
+
+ return [
+ {
+ url: url("/"),
+ changeFrequency: "daily",
+ priority: 1,
+ },
+ {
+ url: url("/docs"),
+ changeFrequency: "daily",
+ priority: 0.8,
+ },
+ ...(await Promise.all(
+ source.getPages().map((page) => {
+ const { lastModified } = page.data;
+
+ return {
+ url: url(page.url),
+ lastModified: lastModified ? new Date(lastModified) : undefined,
+ changeFrequency: "daily",
+ priority: 0.5,
+ } as MetadataRoute.Sitemap[number];
+ }),
+ )),
+ ];
+}
diff --git a/apps/docs/public/robots.txt b/apps/docs/public/robots.txt
new file mode 100644
index 000000000..90ed6f62c
--- /dev/null
+++ b/apps/docs/public/robots.txt
@@ -0,0 +1,6 @@
+User-agent: *
+Allow: /
+
+Host: https://kaneo.app
+
+Sitemap: https://kaneo.app/sitemap.xml
diff --git a/biome.json b/biome.json
index 29a07a6d1..41c56025e 100644
--- a/biome.json
+++ b/biome.json
@@ -15,7 +15,8 @@
"*.css",
"package.json",
".turbo",
- ".source"
+ ".source",
+ ".next"
]
},
"formatter": {