Skip to content

Commit

Permalink
SSR: Add meta description tag on the Signup section (#95013)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
yuliyan authored Sep 30, 2024
1 parent 728b882 commit 1e94793
Showing 1 changed file with 42 additions and 5 deletions.
47 changes: 42 additions & 5 deletions client/signup/index.node.js
Original file line number Diff line number Diff line change
@@ -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';

Expand All @@ -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();
}

0 comments on commit 1e94793

Please sign in to comment.