diff --git a/package.json b/package.json index a934147aec..e37aae6158 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/components/Head/index.tsx b/src/components/Head/index.tsx index 43f95b00e4..845d2c1815 100644 --- a/src/components/Head/index.tsx +++ b/src/components/Head/index.tsx @@ -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 @@ -41,10 +47,8 @@ export const Head: React.FC = (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] @@ -94,10 +98,10 @@ export const Head: React.FC = (props) => { )} {/* noindex for non-production enviroment */} - {!isProd && ( + {!isProdServingCanonical && ( )} - {!isProd && ( + {!isProdServingCanonical && ( )}