Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

feat: Robots.txt changes

Richie McIlroyb1bba1d17fc8
diff --git a/apps/web/app/robots.ts b/apps/web/app/robots.ts
index 6317bf7d1..20a17f92c 100644
--- a/apps/web/app/robots.ts
+++ b/apps/web/app/robots.ts
@@ -11,6 +11,8 @@ export default function robots(): MetadataRoute.Robots {
const referrer = headersList.get("x-referrer") || "";
const userAgent = headersList.get("x-user-agent") || "";
+ console.log('ROBOTS.TXT - User Agent:', userAgent);
+
const allowedReferrers = [
"x.com",
"facebook.com",
@@ -25,19 +27,22 @@ export default function robots(): MetadataRoute.Robots {
];
const allowedBots = [
- "Twitterbot"
+ "twitterbot"
];
const isAllowedReferrer = allowedReferrers.some(domain =>
referrer.includes(domain)
);
+ const userAgentLower = userAgent.toLowerCase();
const isAllowedBot = allowedBots.some(bot =>
- userAgent.includes(bot)
+ userAgentLower.includes(bot.toLowerCase())
);
const shouldAllowCrawling = isAllowedReferrer || isAllowedBot;
+ const isTwitterBot = userAgentLower.includes('twitterbot');
+
const disallowPaths = [
"/dashboard",
"/login",
@@ -47,6 +52,25 @@ export default function robots(): MetadataRoute.Robots {
"/home",
];
+ if (isTwitterBot) {
+ console.log('ROBOTS.TXT - Twitter bot detected, allowing /s/*');
+ return {
+ rules: [
+ {
+ userAgent: "*",
+ allow: [
+ "/",
+ "/blog/",
+ ...seoPageSlugs.map((slug) => `/${slug}`),
+ "/s/*",
+ ],
+ disallow: disallowPaths,
+ },
+ ],
+ sitemap: "https://cap.so/sitemap.xml",
+ };
+ }
+
if (!shouldAllowCrawling) {
disallowPaths.push("/s/*");
}
diff --git a/apps/web/app/s/[videoId]/page.tsx b/apps/web/app/s/[videoId]/page.tsx
index 721dd8b86..501752caa 100644
--- a/apps/web/app/s/[videoId]/page.tsx
+++ b/apps/web/app/s/[videoId]/page.tsx
@@ -66,12 +66,12 @@ export async function generateMetadata(
return notFound();
}
- // Get the headers from the middleware
const headersList = headers();
const referrer = headersList.get("x-referrer") || "";
const userAgent = headersList.get("x-user-agent") || "";
- // Check if referrer is from allowed platforms
+ console.log("[generateMetadata] User Agent:", userAgent);
+
const allowedReferrers = [
"x.com",
"facebook.com",
@@ -85,30 +85,29 @@ export async function generateMetadata(
"t.co",
];
- // Check if user agent is from an allowed bot
- const allowedBots = [
- "Twitterbot",
- "facebookexternalhit",
- "LinkedInBot",
- "Slackbot",
- "redditbot",
- "Googlebot",
- ];
+ const allowedBots = ["twitterbot"];
const isAllowedReferrer = allowedReferrers.some((domain) =>
referrer.includes(domain)
);
- const isAllowedBot = allowedBots.some((bot) => userAgent.includes(bot));
+ const userAgentLower = userAgent.toLowerCase();
+ const isAllowedBot = allowedBots.some((bot) =>
+ userAgentLower.includes(bot.toLowerCase())
+ );
+
+ const isTwitterBot = userAgentLower.includes("twitterbot");
- // Allow indexing if either the referrer or user agent is allowed
- const shouldAllowIndexing = isAllowedReferrer || isAllowedBot;
+ const shouldAllowIndexing = isAllowedReferrer || isAllowedBot || isTwitterBot;
- // Set robots metadata based on whether we should allow indexing
const robotsDirective = shouldAllowIndexing
? "index, follow"
: "noindex, nofollow";
+ if (isTwitterBot) {
+ console.log("[generateMetadata] Twitter bot detected, allowing indexing");
+ }
+
if (video.public === false) {
return {
title: "Cap: This video is private",
@@ -147,7 +146,7 @@ export async function generateMetadata(
).toString(),
],
},
- robots: "noindex, nofollow",
+ robots: isTwitterBot ? "index, follow" : "noindex, nofollow",
};
}