Skip to content

Commit aa3b157

Browse files
committed
refactor: seo indexing flag
1 parent a58fb83 commit aa3b157

11 files changed

Lines changed: 19 additions & 24 deletions

File tree

.env.example

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,6 @@ NEXT_PUBLIC_SUPABASE_ANON_KEY=your_supabase_anon_key
3939
### ZeroBounce API key for email validation
4040
# ZEROBOUNCE_API_KEY=
4141

42-
### Set to 1 to enable no-indexing
43-
### This will take precautions to prevent search engines from indexing the site
44-
# NO_INDEX=0
45-
4642
### =================================
4743
### OPTIONAL CLIENT ENVIRONMENT VARIABLES
4844
### =================================

src/app/(rewrites)/[[...slug]]/route.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { ERROR_CODES } from '@/configs/logs'
66
import { NextRequest } from 'next/server'
77
import sitemap from '@/app/sitemap'
88
import { BASE_URL } from '@/configs/urls'
9-
import { NO_INDEX } from '@/lib/utils/flags'
9+
import { ALLOW_SEO_INDEXING } from '@/configs/flags'
1010
import { logError } from '@/lib/clients/logger'
1111
import { ROUTE_REWRITE_CONFIG } from '@/configs/rewrites'
1212

@@ -71,7 +71,7 @@ export async function GET(request: NextRequest): Promise<Response> {
7171
html = rewriteContentPagesHtml(html, {
7272
seo: {
7373
pathname: url.pathname,
74-
isNoIndex: NO_INDEX,
74+
allowIndexing: ALLOW_SEO_INDEXING,
7575
},
7676
hrefPrefixes: [rewrittenPrefix, 'https://e2b.dev'],
7777
})

src/app/layout.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import { Toaster } from '@/ui/primitives/toaster'
1212
import Head from 'next/head'
1313
import { GTMHead } from '@/features/google-tag-manager'
1414
import { Analytics } from '@vercel/analytics/next'
15-
import { NO_INDEX } from '@/lib/utils/flags'
15+
import { ALLOW_SEO_INDEXING } from '@/configs/flags'
1616

1717
export const metadata: Metadata = {
1818
metadataBase: new URL(BASE_URL),
@@ -29,7 +29,7 @@ export const metadata: Metadata = {
2929
title: METADATA.title,
3030
description: METADATA.description,
3131
},
32-
robots: NO_INDEX ? 'noindex, nofollow' : 'index, follow',
32+
robots: ALLOW_SEO_INDEXING ? 'index, follow' : 'noindex, nofollow',
3333
}
3434

3535
export default function RootLayout({

src/app/robots.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import type { MetadataRoute } from 'next'
2-
import { NO_INDEX } from '@/lib/utils/flags'
2+
import { ALLOW_SEO_INDEXING } from '@/configs/flags'
33

44
export default function robots(): MetadataRoute.Robots {
5-
if (NO_INDEX) {
5+
if (!ALLOW_SEO_INDEXING) {
66
// We serve an empty robots.txt for a 200 status code
77
return {
88
rules: {},

src/app/sitemap.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import {
1515
ROUTE_REWRITE_CONFIG,
1616
} from '@/configs/rewrites'
1717
import { DomainConfig } from '@/types/rewrites.types'
18-
import { NO_INDEX } from '@/lib/utils/flags'
18+
import { ALLOW_SEO_INDEXING } from '@/configs/flags'
1919

2020
// Cache the sitemap for 15 minutes (in seconds)
2121
const SITEMAP_CACHE_TIME = 15 * 60
@@ -229,8 +229,8 @@ async function getSitemap(site: Site): Promise<MetadataRoute.Sitemap> {
229229
* @returns Complete sitemap for the E2B website
230230
*/
231231
export default async function sitemap(): Promise<MetadataRoute.Sitemap> {
232-
// Return empty sitemap if NO_INDEX is set
233-
if (NO_INDEX) {
232+
// Return empty sitemap if SEO indexing is not allowed
233+
if (!ALLOW_SEO_INDEXING) {
234234
return []
235235
}
236236

src/configs/flags.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,5 @@
1+
export const ALLOW_SEO_INDEXING = process.env.ALLOW_SEO_INDEXING === '1'
2+
export const VERBOSE =
3+
process.env.NODE_ENV === 'development' ||
4+
process.env.NEXT_PUBLIC_VERBOSE === '1'
15
export const INCLUDE_BILLING = process.env.NEXT_PUBLIC_INCLUDE_BILLING === '1'

src/lib/clients/action.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { z } from 'zod'
44
import { UnknownError } from '@/types/errors'
55
import { logDebug, logError, logSuccess } from './logger'
66
import { ActionError } from '../utils/action'
7-
import { VERBOSE } from '../utils/flags'
7+
import { VERBOSE } from '../../configs/flags'
88

99
// keys that should not be logged for security/privacy reasons
1010
const BLACKLISTED_INPUT_KEYS = [

src/lib/env.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import { z } from 'zod'
33
export const serverSchema = z.object({
44
SUPABASE_SERVICE_ROLE_KEY: z.string().min(1),
55
INFRA_API_URL: z.string().url(),
6-
NO_INDEX: z.string().optional(),
76
KV_REST_API_TOKEN: z.string().min(1),
87
KV_REST_API_URL: z.string().url(),
98

src/lib/utils/flags.ts

Lines changed: 0 additions & 4 deletions
This file was deleted.

src/lib/utils/rewrites.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ function getRewriteForPath(
4646

4747
interface SeoTagOptions {
4848
pathname: string
49-
isNoIndex: boolean
49+
allowIndexing: boolean
5050
}
5151

5252
/**
@@ -58,12 +58,12 @@ interface SeoTagOptions {
5858
* @param options Configuration options including the pathname and NO_INDEX flag.
5959
*/
6060
function rewriteSeoTags($: cheerio.CheerioAPI, options: SeoTagOptions): void {
61-
const { pathname, isNoIndex } = options
61+
const { pathname, allowIndexing } = options
6262

6363
$('meta[name="robots"]').remove()
6464
$('link[rel="canonical"]').remove()
6565

66-
const robotsContent = isNoIndex ? 'noindex,nofollow' : 'index,follow'
66+
const robotsContent = allowIndexing ? 'index,follow' : 'noindex,nofollow'
6767

6868
const formattedPathname = pathname.startsWith('/') ? pathname : `/${pathname}`
6969
const canonicalUrl = `https://e2b.dev${formattedPathname}`

0 commit comments

Comments
 (0)