Skip to content

Commit

Permalink
feat(web-next): turn noindex to bots for web-next
Browse files Browse the repository at this point in the history
  • Loading branch information
49659410+tx0c committed Aug 14, 2022
1 parent 4393e5e commit dbc5619
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"storybook": "start-storybook -p 6006",
"build-storybook": "build-storybook",
"prepare": "husky install",
"vercel-build": "set -xe; if [[ \"$NEXT_PUBLIC_VERCEL_GIT_COMMIT_REF\" =~ release/* ]] ; then npm run gen:type:prod; cp -va .env.prod .env ; echo 'NEXT_PUBLIC_SITE_DOMAIN=web-next.matters.news' | tee -a .env.local; else npm run gen:type; cp -va .env.dev .env ; echo 'NEXT_PUBLIC_SITE_DOMAIN=web-dev.matters.news' | tee -a .env.local ; fi && npm run build"
"vercel-build": "set -xe; if [[ \"$NEXT_PUBLIC_VERCEL_GIT_COMMIT_REF\" =~ release/* ]] ; then npm run gen:type:prod; cp -va .env.prod .env ; echo -e 'NEXT_PUBLIC_SITE_DOMAIN=web-next.matters.news\nNEXT_PUBLIC_NEXT_ASSET_DOMAIN=web-next.matters.news' | tee -a .env.local; else npm run gen:type; cp -va .env.dev .env ; echo 'NEXT_PUBLIC_SITE_DOMAIN=web-dev.matters.news' | tee -a .env.local ; fi && npm run build"
},
"dependencies": {
"@apollo/react-common": "^3.1.3",
Expand Down
18 changes: 11 additions & 7 deletions src/components/Head/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,13 @@ import IMAGE_FAVICON_32 from '@/public/static/favicon-32x32.png'
import IMAGE_FAVICON_64 from '@/public/static/favicon-64x64.png'
import IMAGE_INTRO from '@/public/static/images/intro.jpg'

const isProd = process.env.NEXT_PUBLIC_RUNTIME_ENV === 'production'
const siteDomain =
process.env.NEXT_PUBLIC_SITE_DOMAIN_CANONICAL || // for web-next, set this different as serving domain; suggested canonical domain ('matters.news') to robots
process.env.NEXT_PUBLIC_SITE_DOMAIN ||
'matters.news'
const isProdServingCanonical =
process.env.NEXT_PUBLIC_RUNTIME_ENV === 'production' &&
process.env.NEXT_PUBLIC_SITE_DOMAIN === 'matters.news' // is serving domain same as canonical domain?

interface HeadProps {
title?: string | TranslateArgs
Expand Down Expand Up @@ -41,10 +47,8 @@ export const Head: React.FC<HeadProps> = (props) => {
? `${props.keywords.join(',')},matters,matters.news,創作有價`
: 'matters,matters.news,創作有價',
url: props.path
? `https://${process.env.NEXT_PUBLIC_SITE_DOMAIN}${props.path}`
: router.asPath
? `https://${process.env.NEXT_PUBLIC_SITE_DOMAIN}${router.asPath}`
: 'https://' + process.env.NEXT_PUBLIC_SITE_DOMAIN,
? `https://${siteDomain}${props.path}`
: `https://${siteDomain}${router.asPath || '/'}`,
image: props.image || IMAGE_INTRO.src,
}
const canonicalUrl = head.url?.split('#')[0].split('?')[0]
Expand Down Expand Up @@ -94,10 +98,10 @@ export const Head: React.FC<HeadProps> = (props) => {
)}

{/* noindex for non-production enviroment */}
{!isProd && (
{!isProdServingCanonical && (
<meta name="robots" content="noindex, nofollow" key="robots" />
)}
{!isProd && (
{!isProdServingCanonical && (
<meta name="googlebot" content="noindex, nofollow" key="googlebot" />
)}

Expand Down

0 comments on commit dbc5619

Please sign in to comment.