From 1e947932164ad42b18e1bd5a9535450e331cb188 Mon Sep 17 00:00:00 2001 From: Yuliyan Slavchev Date: Mon, 30 Sep 2024 19:14:08 +0300 Subject: [PATCH] SSR: Add meta description tag on the Signup section (#95013) * SSR: Add meta description tag on the Signup section * Remove previous description and robots meta tags * Setup locale data only for English and Mag-16 locales * Pass required params to ssrSetupLocale * Fix indexing the localized main pages for Mag-16 locales * Improve comment * Update the noindex comment * Use `isMagnificentLocale` utility --- client/signup/index.node.js | 47 +++++++++++++++++++++++++++++++++---- 1 file changed, 42 insertions(+), 5 deletions(-) diff --git a/client/signup/index.node.js b/client/signup/index.node.js index a76d4b22ffc70..1b416cbaae723 100644 --- a/client/signup/index.node.js +++ b/client/signup/index.node.js @@ -1,4 +1,11 @@ -import { getLanguage, getLanguageRouteParam } from '@automattic/i18n-utils'; +import { + getLanguage, + getLanguageRouteParam, + isDefaultLocale, + isMagnificentLocale, +} from '@automattic/i18n-utils'; +import defaultI18n from 'i18n-calypso'; +import { ssrSetupLocale } from 'calypso/controller'; import { setDocumentHeadMeta } from 'calypso/state/document-head/actions'; import { getDocumentHeadMeta } from 'calypso/state/document-head/selectors'; @@ -24,19 +31,49 @@ function setUpLocale( context, next ) { context.lang = context.params.lang; } + const shouldSetupLocaleData = + isDefaultLocale( context.lang ) || isMagnificentLocale( context.lang ); + + if ( shouldSetupLocaleData ) { + return ssrSetupLocale( context, next ); + } + next(); } // Set up meta tags. function setupMetaTags( context, next ) { - // All `/start/*` sub-pages should be noindex. See 3065-gh-Automattic/martech. - if ( ! /^\/start\/?$/.test( context.pathname ) ) { - const meta = getDocumentHeadMeta( context.store.getState() ).concat( { + const i18n = context.i18n || defaultI18n; + const translate = i18n.translate.bind( i18n ); + + /** + * Get the meta tags, excluding `description` and `robots` meta items, to prevent duplications. + */ + const meta = getDocumentHeadMeta( context.store.getState() ).filter( + ( { name } ) => name !== 'description' && name !== 'robots' + ); + + meta.push( { + name: 'description', + content: translate( + 'Sign up for a free WordPress.com account to start building your new website. Get access to powerful tools and customizable designs to bring your ideas to life.' + ), + } ); + + const pathSegments = context.pathname.replace( /^[/]|[/]$/g, '' ).split( '/' ); + const hasQueryString = Object.keys( context.query ).length > 0; + const hasMag16LocaleParam = isMagnificentLocale( context.params?.lang ); + + /** + * Only the main `/start` and `/start/[mag-16-locale]` pages should be indexed. See 3065-gh-Automattic/martech. + */ + if ( hasQueryString || pathSegments.length > ( hasMag16LocaleParam ? 2 : 1 ) ) { + meta.push( { name: 'robots', content: 'noindex', } ); - context.store.dispatch( setDocumentHeadMeta( meta ) ); } + context.store.dispatch( setDocumentHeadMeta( meta ) ); next(); }