Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

docs: New Cloudflare R2 docs post

Richie McIlroy29206fae0936
diff --git a/.gitignore b/.gitignore
index d1b883741..d538b67ae 100644
--- a/.gitignore
+++ b/.gitignore
@@ -16,6 +16,7 @@ dist-ssr
.env.development
.env.test
target
+.cursorrules
# Editor directories and files
.vscode/*
diff --git a/apps/web/app/docs/[...slug]/page.tsx b/apps/web/app/docs/[...slug]/page.tsx
new file mode 100644
index 000000000..2f3e361f8
--- /dev/null
+++ b/apps/web/app/docs/[...slug]/page.tsx
@@ -0,0 +1,202 @@
+import { notFound } from "next/navigation";
+import Image from "next/image";
+import Link from "next/link";
+import { MDXRemote } from "next-mdx-remote/rsc";
+import { getDocs } from "@/utils/blog";
+import type { Metadata } from "next";
+import type { DocMetadata } from "@/utils/blog";
+
+type Doc = {
+ metadata: DocMetadata;
+ slug: string;
+ content: string;
+};
+
+interface DocProps {
+ params: {
+ slug: string[];
+ };
+}
+
+export async function generateMetadata(
+ props: DocProps
+): Promise<Metadata | undefined> {
+ const { params } = props;
+ if (!params?.slug) return;
+
+ const fullSlug = params.slug.join("/");
+
+ // If it's a category page
+ if (params.slug.length === 1) {
+ const category = params.slug[0];
+ if (!category) return;
+
+ const displayCategory = category
+ .split("-")
+ .map((word) => word.charAt(0).toUpperCase() + word.slice(1))
+ .join(" ");
+
+ return {
+ title: `${displayCategory} Documentation - Cap`,
+ description: `Documentation for ${displayCategory} in Cap`,
+ };
+ }
+
+ // If it's a doc page
+ const allDocs = getDocs() as Doc[];
+ const doc = allDocs.find((doc) => doc.slug === fullSlug);
+ if (!doc) return;
+
+ const { title, summary, image } = doc.metadata;
+ const ogImage = image ? `${process.env.NEXT_PUBLIC_URL}${image}` : undefined;
+ const description = summary || title;
+
+ return {
+ title,
+ description,
+ openGraph: {
+ title,
+ description,
+ type: "article",
+ url: `${process.env.NEXT_PUBLIC_URL}/docs/${fullSlug}`,
+ ...(ogImage && {
+ images: [{ url: ogImage }],
+ }),
+ },
+ twitter: {
+ card: "summary_large_image",
+ title,
+ description,
+ ...(ogImage && { images: [ogImage] }),
+ },
+ };
+}
+
+export default async function DocPage(props: DocProps) {
+ const { params } = props;
+ if (!params?.slug) notFound();
+
+ const fullSlug = params.slug.join("/");
+ const allDocs = getDocs() as Doc[];
+
+ // Handle category pages (e.g., /docs/s3-config)
+ if (params.slug.length === 1) {
+ const category = params.slug[0];
+ if (!category) notFound();
+
+ // Find docs that either:
+ // 1. Have a slug that exactly matches the category, or
+ // 2. Have a slug that starts with category/
+ const categoryDocs = allDocs
+ .filter(
+ (doc) => doc.slug === category || doc.slug.startsWith(`${category}/`)
+ )
+ .sort((a, b) => {
+ // Sort by depth (root level first)
+ const aDepth = a.slug.split("/").length;
+ const bDepth = b.slug.split("/").length;
+ if (aDepth !== bDepth) return aDepth - bDepth;
+
+ // Then by title
+ return a.metadata.title.localeCompare(b.metadata.title);
+ });
+
+ if (categoryDocs.length === 0) {
+ notFound();
+ }
+
+ // Format the category name for display
+ const displayCategory = category
+ .split("-")
+ .map((word) => word.charAt(0).toUpperCase() + word.slice(1))
+ .join(" ");
+
+ // Find the root category doc if it exists
+ const rootDoc = categoryDocs.find((doc) => doc.slug === category);
+
+ return (
+ <div className="py-8 prose mx-auto">
+ <h1>{displayCategory} Documentation</h1>
+
+ {/* Show root category content if it exists */}
+ {rootDoc && (
+ <div className="mb-8">
+ <MDXRemote source={rootDoc.content} />
+ <hr className="my-8" />
+ </div>
+ )}
+
+ {/* Show subcategory docs */}
+ {categoryDocs.length > (rootDoc ? 1 : 0) && (
+ <>
+ <h2 className="mt-0">Available Guides</h2>
+ <div className="grid gap-4">
+ {categoryDocs
+ .filter((doc) => doc.slug !== category) // Filter out the root doc if it exists
+ .map((doc) => (
+ <Link
+ key={doc.slug}
+ href={`/docs/${doc.slug}`}
+ className="no-underline"
+ >
+ <div className="p-4 rounded-lg border hover:border-blue-500 transition-colors">
+ <h3 className="m-0">{doc.metadata.title}</h3>
+ {doc.metadata.summary && (
+ <p className="text-gray-600 dark:text-gray-400 m-0 mt-2">
+ {doc.metadata.summary}
+ </p>
+ )}
+ {doc.metadata.tags && (
+ <div className="flex gap-2 mt-3">
+ {doc.metadata.tags.split(", ").map((tag) => (
+ <span
+ key={tag}
+ className="text-xs px-2 py-1 bg-gray-100 dark:bg-gray-800 rounded-full text-gray-600 dark:text-gray-400"
+ >
+ {tag}
+ </span>
+ ))}
+ </div>
+ )}
+ </div>
+ </Link>
+ ))}
+ </div>
+ </>
+ )}
+ </div>
+ );
+ }
+
+ // Handle individual doc pages
+ const doc = allDocs.find((doc) => doc.slug === fullSlug);
+
+ if (!doc) {
+ notFound();
+ }
+
+ return (
+ <article className="py-8 prose mx-auto">
+ {doc.metadata.image && (
+ <div className="relative mb-12 h-[345px] w-full">
+ <Image
+ className="m-0 w-full rounded-lg object-contain sm:object-cover"
+ src={doc.metadata.image}
+ alt={doc.metadata.title}
+ fill
+ priority
+ sizes="(max-width: 768px) 100vw, (max-width: 1200px) 50vw, 33vw"
+ />
+ </div>
+ )}
+
+ <div className="wrapper">
+ <header>
+ <h1 className="mb-2">{doc.metadata.title}</h1>
+ </header>
+ <hr className="my-6" />
+ <MDXRemote source={doc.content} />
+ </div>
+ </article>
+ );
+}
diff --git a/apps/web/components/pages/DocsPage.tsx b/apps/web/components/pages/DocsPage.tsx
index 243942b59..a40c1417f 100644
--- a/apps/web/components/pages/DocsPage.tsx
+++ b/apps/web/components/pages/DocsPage.tsx
@@ -11,46 +11,44 @@ export const DocsPage = () => {
<h1>Documentation</h1>
</div>
<div className="grid grid-cols-1 md:grid-cols-2 gap-8">
- <div className="space-y-8">
- {allDocs.map((doc) => (
- <article
- key={doc.slug}
- className="w-full rounded-xl overflow-hidden border"
- >
- <Link href={"/docs/" + doc.slug}>
- {doc.metadata.image && (
- <div className="w-full border-b">
- <Image
- src={doc.metadata.image}
- width={900}
- height={400}
- objectFit="cover"
- alt={doc.metadata.title}
- className="w-full h-auto"
- />
- </div>
- )}
- <div className="p-10 space-y-4">
- <h2 className="text-xl md:text-4xl text-gray-500">
- {doc.metadata.title}
- </h2>
- <p className="text-gray-600">{doc.metadata.summary}</p>
- <div className="flex space-x-2">
- {doc.metadata.tags &&
- doc.metadata.tags.split(", ").map((tag) => (
- <p
- key={tag}
- className="rounded-md bg-gray-200 font-medium px-2 py-0.5 text-sm text-gray-500"
- >
- {tag}
- </p>
- ))}
- </div>
+ {allDocs.map((doc) => (
+ <article
+ key={doc.slug}
+ className="w-full rounded-xl overflow-hidden border"
+ >
+ <Link href={"/docs/" + doc.slug}>
+ {doc.metadata.image && (
+ <div className="w-full border-b">
+ <Image
+ src={doc.metadata.image}
+ width={900}
+ height={400}
+ objectFit="cover"
+ alt={doc.metadata.title}
+ className="w-full h-auto"
+ />
</div>
- </Link>
- </article>
- ))}
- </div>
+ )}
+ <div className="p-10 space-y-4">
+ <h2 className="text-xl md:text-4xl text-gray-500">
+ {doc.metadata.title}
+ </h2>
+ <p className="text-gray-600">{doc.metadata.summary}</p>
+ <div className="flex space-x-2">
+ {doc.metadata.tags &&
+ doc.metadata.tags.split(", ").map((tag) => (
+ <p
+ key={tag}
+ className="rounded-md bg-gray-200 font-medium px-2 py-0.5 text-sm text-gray-500"
+ >
+ {tag}
+ </p>
+ ))}
+ </div>
+ </div>
+ </Link>
+ </article>
+ ))}
</div>
</div>
);
diff --git a/apps/web/content/docs/s3-config.mdx b/apps/web/content/docs/s3-config/aws-s3.mdx
similarity index 99%
rename from apps/web/content/docs/s3-config.mdx
rename to apps/web/content/docs/s3-config/aws-s3.mdx
index 5929831f0..63af11b50 100644
--- a/apps/web/content/docs/s3-config.mdx
+++ b/apps/web/content/docs/s3-config/aws-s3.mdx
@@ -2,7 +2,7 @@
title: "Cap Apps: S3 Config (AWS)"
summary: "Connect your own S3 bucket to Cap and maintain 100% ownership over your data."
tags: "Cap Apps"
-image: "/docs/s3-config.jpg"
+image: "/docs/s3-config/aws-s3.jpg"
---
# Connecting Your Amazon S3 Bucket to Cap Desktop
diff --git a/apps/web/content/docs/s3-config/cloudflare-r2.mdx b/apps/web/content/docs/s3-config/cloudflare-r2.mdx
new file mode 100644
index 000000000..575b98f3f
--- /dev/null
+++ b/apps/web/content/docs/s3-config/cloudflare-r2.mdx
@@ -0,0 +1,104 @@
+---
+title: "Cap Apps: S3 Config (Cloudflare R2)"
+summary: "Connect your own Cloudflare R2 bucket to Cap Desktop and maintain 100% ownership over your data."
+tags:
+ [
+ "Cap Apps",
+ "Cloudflare R2",
+ "S3-compatible storage",
+ "Cloud storage configuration",
+ ]
+image: "/docs/s3-config/cloudflare-r2.jpg"
+---
+
+# How to Connect Your Cloudflare R2 Bucket to Cap Desktop
+
+Looking to take full control of your data storage within Cap? Integrating your Cloudflare R2 bucket gives you ownership, flexible scalability, and reduced latency, all while keeping your workflow smooth and secure. In this guide, you'll learn how to quickly set up and configure Cloudflare R2 with Cap Desktop—no complicated steps or robotic instructions, just straightforward guidance.
+
+> **TL;DR**:
+>
+> 1. Open Cap Desktop → Cap Apps → S3 Config → Configure
+> 2. Select Cloudflare R2 → Enter your R2 credentials
+> 3. Adjust bucket permissions and test the connection
+> 4. Save settings and start using your R2 bucket for seamless content delivery.
+
+> **Note**: While this tutorial focuses on Cloudflare R2, Cap Desktop supports any S3-compatible storage service. If you use another provider, just substitute the endpoint and credentials accordingly.
+
+## Step 1: Open Cap Desktop and Access the Cap Apps Tab
+
+1. **Open the Cap Desktop App**: Click the Cap icon on your desktop or launch it from your applications folder.
+2. **Go to Cap Apps**: Once the app is open, look for the "Cap Apps" tab in the Settings menu.
+
+## Step 2: Choose S3 Config and Start Configuration
+
+1. **Click on S3 Config**: Within the Cap Apps section, locate "S3 Config."
+2. **Begin Configuration**: Click "Configure."
+3. **Select Cloudflare R2**: From the list of storage services, pick "Cloudflare R2."
+
+## Step 3: Set Up Your Cloudflare R2 Bucket
+
+Before connecting to Cap, ensure you have a Cloudflare R2 bucket ready:
+
+1. **Create or Access Your R2 Bucket**:
+
+ - Log in to the [Cloudflare Dashboard](https://dash.cloudflare.com).
+ - Navigate to **Storage → R2**.
+ - If you don’t have a bucket yet, click "Create Bucket."
+ - Provide a unique bucket name (e.g., `my-cap-uploads`) and select a region (`auto` or your preferred option).
+ - Click "Create Bucket."
+
+2. **Generate R2 Access Keys**:
+
+ - In the R2 dashboard, find the "Access Keys" section.
+ - Click "Create Access Key" and name it (e.g., `cap-app-user`).
+ - Copy both the **Access Key ID** and **Secret Access Key** immediately. You won’t be able to view the secret key again later.
+
+3. **Configure Bucket Permissions**:
+ By default, Cloudflare R2 keys come with broad permissions. If you need more controlled access:
+
+ - Check Cloudflare’s [R2 documentation](https://developers.cloudflare.com/r2/) for guidance on applying custom access policies.
+ - Ensure that your R2 keys have at least **Read**, **Write**, and **List** permissions for the selected bucket.
+
+4. **Set CORS Rules (Optional)**:
+ If you’re serving content directly from the bucket via a browser (e.g., sharing publicly accessible links):
+ - Go to your R2 bucket’s settings and locate **CORS Rules**.
+ - Add rules that allow `GET`, `HEAD`, and `PUT` from domains like `https://cap.so`, `https://www.cap.so`, `https://cap.link`, and `https://www.cap.link`.
+ - This ensures that assets load smoothly if accessed directly from a browser.
+
+## Step 4: Enter Your Cloudflare R2 Details in Cap Desktop
+
+1. Return to the "R2 Config" section in Cap Desktop.
+2. Fill in the following information:
+ - **Access Key ID**: Paste the key ID from the R2 dashboard.
+ - **Secret Access Key**: Paste the corresponding secret key.
+ - **Endpoint**: Usually follows `https://<accountid>.r2.cloudflarestorage.com`. Find the exact endpoint in your R2 bucket details.
+ - **Bucket Name**: The name of your R2 bucket (e.g., `my-cap-uploads`).
+ - **Region**: R2 often uses `auto`. Check your bucket details to confirm.
+
+## Step 5: Test and Save Your Connection
+
+1. **Test Connection**: Click "Test Connection" in Cap Desktop to verify that it can communicate with your R2 bucket successfully.
+2. **Save Configuration**: Once you see a successful connection message, save your settings.
+
+With these steps completed, Cap Desktop will now use your Cloudflare R2 bucket to store and serve assets, giving you full control over how and where your content is hosted.
+
+---
+
+## Benefits of Using Cloudflare R2 with Cap Desktop
+
+- **Full Data Ownership**: Your files stay under your control, not locked into a third-party platform.
+- **S3-Compatible & Scalable**: R2 is designed to be S3-compatible, making it simple to use with Cap or other tools.
+- **Global Performance**: Cloudflare’s extensive network ensures quick, reliable access to your files worldwide.
+- **Cost-Effective**: R2 often provides competitive pricing compared to traditional cloud storage solutions.
+
+---
+
+## Accessing Your R2 Files in Cap
+
+After setting up Cloudflare R2 in Cap Desktop, any new shareable links you create will be served from your R2 bucket. This means:
+
+- Faster load times for your images and videos.
+- Greater flexibility to scale as you grow.
+- Improved ownership and long-term cost savings.
+
+With your Cloudflare R2 integration complete, you can enjoy seamless, secure, and efficient content delivery directly within Cap Desktop—no extra steps, no compromises.
diff --git a/apps/web/next.config.mjs b/apps/web/next.config.mjs
index dd804a5de..58ef26397 100644
--- a/apps/web/next.config.mjs
+++ b/apps/web/next.config.mjs
@@ -70,6 +70,11 @@ const nextConfig = {
destination: "/blog/:slug",
permanent: true,
},
+ {
+ source: "/docs/s3-config",
+ destination: "/docs",
+ permanent: true,
+ },
];
},
env: {
diff --git a/apps/web/public/docs/s3-config.jpg b/apps/web/public/docs/s3-config.jpg
deleted file mode 100644
index 8954833fa..000000000
Binary files a/apps/web/public/docs/s3-config.jpg and /dev/null differ
diff --git a/apps/web/public/docs/s3-config/aws-s3.jpg b/apps/web/public/docs/s3-config/aws-s3.jpg
new file mode 100644
index 000000000..569deae8d
Binary files /dev/null and b/apps/web/public/docs/s3-config/aws-s3.jpg differ
diff --git a/apps/web/public/docs/s3-config/bunny.jpg b/apps/web/public/docs/s3-config/bunny.jpg
new file mode 100644
index 000000000..6fa977319
Binary files /dev/null and b/apps/web/public/docs/s3-config/bunny.jpg differ
diff --git a/apps/web/public/docs/s3-config/cloudflare-r2.jpg b/apps/web/public/docs/s3-config/cloudflare-r2.jpg
new file mode 100644
index 000000000..e39393f05
Binary files /dev/null and b/apps/web/public/docs/s3-config/cloudflare-r2.jpg differ
diff --git a/apps/web/public/docs/s3-config/minio.jpg b/apps/web/public/docs/s3-config/minio.jpg
new file mode 100644
index 000000000..bda44897a
Binary files /dev/null and b/apps/web/public/docs/s3-config/minio.jpg differ
diff --git a/apps/web/public/docs/s3-config/supabase.jpg b/apps/web/public/docs/s3-config/supabase.jpg
new file mode 100644
index 000000000..5f1ef540d
Binary files /dev/null and b/apps/web/public/docs/s3-config/supabase.jpg differ
diff --git a/apps/web/utils/blog.ts b/apps/web/utils/blog.ts
index a14522cbb..82cf4d187 100644
--- a/apps/web/utils/blog.ts
+++ b/apps/web/utils/blog.ts
@@ -22,23 +22,54 @@ export type DocMetadata = {
function parseFrontmatter(fileContent: string) {
let frontmatterRegex = /---\s*([\s\S]*?)\s*---/;
let match = frontmatterRegex.exec(fileContent);
- let frontMatterBlock = match![1];
+ if (!match || !match[1]) {
+ throw new Error("Invalid or missing frontmatter");
+ }
+
+ let frontMatterBlock = match[1];
let content = fileContent.replace(frontmatterRegex, "").trim();
- let frontMatterLines = frontMatterBlock!.trim().split("\n");
- let metadata: Partial<PostMetadata> = {};
+ let frontMatterLines = frontMatterBlock.trim().split("\n");
+ let metadata: Partial<PostMetadata | DocMetadata> = {};
frontMatterLines.forEach((line) => {
let [key, ...valueArr] = line.split(": ");
+ if (!key) return;
+
let value = valueArr.join(": ").trim();
value = value.replace(/^['"](.*)['"]$/, "$1"); // Remove quotes
- metadata[key!.trim() as keyof PostMetadata] = value;
+ metadata[key.trim() as keyof (PostMetadata | DocMetadata)] = value;
});
- return { metadata: metadata as PostMetadata, content };
+ return {
+ metadata: metadata as (PostMetadata | DocMetadata),
+ content
+ };
}
function getMDXFiles(dir: string) {
- return fs.readdirSync(dir).filter((file) => path.extname(file) === ".mdx");
+ const files: string[] = [];
+
+ function scanDir(currentDir: string) {
+ const entries = fs.readdirSync(currentDir);
+ entries.forEach(entry => {
+ const fullPath = path.join(currentDir, entry);
+ const stat = fs.statSync(fullPath);
+
+ if (stat.isDirectory()) {
+ scanDir(fullPath);
+ } else if (path.extname(entry) === '.mdx') {
+ // Store paths relative to the base dir
+ const relativePath = path.relative(dir, fullPath);
+ console.log('Found MDX file:', { relativePath, fullPath });
+ files.push(relativePath);
+ }
+ });
+ }
+
+ console.log('Scanning directory:', dir);
+ scanDir(dir);
+ console.log('Found files:', files);
+ return files;
}
function readMDXFile(filePath: string) {
@@ -47,10 +78,18 @@ function readMDXFile(filePath: string) {
}
function getMDXData(dir: string) {
+ console.log('Getting MDX data from:', dir);
let mdxFiles = getMDXFiles(dir);
- return mdxFiles.map((file) => {
- let { metadata, content } = readMDXFile(path.join(dir, file));
- let slug = path.basename(file, path.extname(file));
+ return mdxFiles.map((relativePath) => {
+ const fullPath = path.join(dir, relativePath);
+ console.log('Processing file:', { relativePath, fullPath });
+ let { metadata, content } = readMDXFile(fullPath);
+ let slug = relativePath
+ .replace(/\.mdx$/, '') // Remove .mdx extension
+ .split(path.sep) // Split on directory separator
+ .join('/'); // Join with forward slashes for URL
+
+ console.log('Generated slug:', { relativePath, slug });
return {
metadata,
slug,