feat(seo): enforce noindex robots.txt in nginx for stage host and dynamically apply noindex metadata in blog/shop pages
This commit is contained in:
1 parent
d6a2136c70
commit
7f8e89e448
3 files changed
+68
-22
No files matched your search
@@ -81,6 +81,13 @@ export async function generateMetadata({ params }: { params: Promise<{ slug: str
|
||||
const ogTitle = blog.ogTitle || title;
|
||||
const ogDesc = blog.ogDescription || description;
|
||||
|
||||
const isStaging =
|
||||
process.env.NEXT_PUBLIC_APP_ENV === 'staging' ||
|
||||
process.env.NODE_ENV !== 'production' ||
|
||||
siteUrl.includes('stage') ||
|
||||
siteUrl.includes('test') ||
|
||||
siteUrl.includes('dev');
|
||||
|
||||
const authorName = blog.author
|
||||
? `${blog.author.firstName || ''} ${blog.author.lastName || ''}`.trim() || 'نویسنده کنینا'
|
||||
: 'نویسنده و پژوهشگر کنینا';
|
||||
@@ -101,17 +108,28 @@ export async function generateMetadata({ params }: { params: Promise<{ slug: str
|
||||
alternates: {
|
||||
canonical: canonicalUrl,
|
||||
},
|
||||
robots: {
|
||||
index: !blog.noIndex,
|
||||
follow: !blog.noFollow,
|
||||
googleBot: {
|
||||
index: !blog.noIndex,
|
||||
follow: !blog.noFollow,
|
||||
'max-image-preview': 'large',
|
||||
'max-snippet': -1,
|
||||
'max-video-preview': -1,
|
||||
},
|
||||
},
|
||||
robots: isStaging
|
||||
? {
|
||||
index: false,
|
||||
follow: false,
|
||||
nocache: true,
|
||||
googleBot: {
|
||||
index: false,
|
||||
follow: false,
|
||||
noimageindex: true,
|
||||
},
|
||||
}
|
||||
: {
|
||||
index: !blog.noIndex,
|
||||
follow: !blog.noFollow,
|
||||
googleBot: {
|
||||
index: !blog.noIndex,
|
||||
follow: !blog.noFollow,
|
||||
'max-image-preview': 'large',
|
||||
'max-snippet': -1,
|
||||
'max-video-preview': -1,
|
||||
},
|
||||
},
|
||||
openGraph: {
|
||||
title: ogTitle,
|
||||
description: ogDesc,
|
||||
|
||||
@@ -49,6 +49,13 @@ export async function generateMetadata(
|
||||
const primaryImage = product.ogImage || product.image || config.ogImageUrl;
|
||||
const imageAlt = product.featuredImageAlt || nameFa;
|
||||
|
||||
const isStaging =
|
||||
process.env.NEXT_PUBLIC_APP_ENV === 'staging' ||
|
||||
process.env.NODE_ENV !== 'production' ||
|
||||
siteUrl.includes('stage') ||
|
||||
siteUrl.includes('test') ||
|
||||
siteUrl.includes('dev');
|
||||
|
||||
const galleryImages = [
|
||||
{
|
||||
url: primaryImage,
|
||||
@@ -70,17 +77,28 @@ export async function generateMetadata(
|
||||
title,
|
||||
description,
|
||||
keywords,
|
||||
robots: {
|
||||
index: !product.noIndex,
|
||||
follow: !product.noFollow,
|
||||
googleBot: {
|
||||
index: !product.noIndex,
|
||||
follow: !product.noFollow,
|
||||
'max-video-preview': -1,
|
||||
'max-image-preview': 'large',
|
||||
'max-snippet': -1,
|
||||
},
|
||||
},
|
||||
robots: isStaging
|
||||
? {
|
||||
index: false,
|
||||
follow: false,
|
||||
nocache: true,
|
||||
googleBot: {
|
||||
index: false,
|
||||
follow: false,
|
||||
noimageindex: true,
|
||||
},
|
||||
}
|
||||
: {
|
||||
index: !product.noIndex,
|
||||
follow: !product.noFollow,
|
||||
googleBot: {
|
||||
index: !product.noIndex,
|
||||
follow: !product.noFollow,
|
||||
'max-video-preview': -1,
|
||||
'max-image-preview': 'large',
|
||||
'max-snippet': -1,
|
||||
},
|
||||
},
|
||||
openGraph: {
|
||||
title: ogTitle,
|
||||
description,
|
||||
|
||||
+10
@@ -9,6 +9,16 @@ server {
|
||||
add_header X-Content-Type-Options "nosniff" always;
|
||||
add_header Referrer-Policy "no-referrer-when-downgrade" always;
|
||||
|
||||
# Force robots.txt block for staging domains
|
||||
location = /robots.txt {
|
||||
if ($host ~* 'stage') {
|
||||
return 200 "User-agent: *\nDisallow: /\n";
|
||||
}
|
||||
proxy_pass http://127.0.0.1:3000;
|
||||
proxy_http_version 1.1;
|
||||
proxy_set_header Host $host;
|
||||
}
|
||||
|
||||
# Main Application (Next.js)
|
||||
location / {
|
||||
proxy_pass http://127.0.0.1:3000;
|
||||
|
||||
Reference in new issue
Block a user