import { parse } from 'path'; import config from '@automattic/calypso-config'; import { WordPressLogo } from '@automattic/components'; import { isLocaleRtl } from '@automattic/i18n-utils'; import { Step } from '@automattic/onboarding'; import clsx from 'clsx'; import { Component } from 'react'; import A4ALogo from 'calypso/a8c-for-agencies/components/a4a-logo'; import EnvironmentBadge, { Branch, AccountSettingsHelper, AuthHelper, DevDocsLink, PreferencesHelper, FeaturesHelper, ReactQueryDevtoolsHelper, StoreSandboxHelper, } from 'calypso/components/environment-badge'; import Head from 'calypso/components/head'; import JetpackLogo from 'calypso/components/jetpack-logo'; import Loading from 'calypso/components/loading'; import WooCommerceLogo from 'calypso/components/woocommerce-logo'; import isA8CForAgencies from 'calypso/lib/a8c-for-agencies/is-a8c-for-agencies'; import { isGravPoweredOAuth2Client, isWooOAuth2Client } from 'calypso/lib/oauth2-clients'; import { jsonStringifyForHtml } from 'calypso/server/sanitize'; import { initialClientsData, gravatarClientData } from 'calypso/state/oauth2-clients/reducer'; import { isBilmurEnabled, getBilmurUrl } from './utils/bilmur'; import { chunkCssLinks } from './utils/chunk'; class Document extends Component { render() { const { accountSettingsHelper, app, authHelper, badge, branchName, buildTimestamp, chunkFiles, clientData, commitChecksum, commitSha, devDocs, devDocsURL, entrypoint, env, featuresHelper, feedbackURL, head, i18nLocaleScript, initialQueryState, initialReduxState, inlineScriptNonce, isSupportSession, isSSP, lang, languageRevisions, manifests, params, preferencesHelper, query, reactQueryDevtoolsHelper, renderedLayout, sectionGroup, sectionName, storeSandboxHelper, target, user, useTranslationChunks, showStepContainerV2Loader, } = this.props; const installedChunks = entrypoint.js .concat( chunkFiles.js ) .map( ( chunk ) => parse( chunk ).name ); const inlineScript = `var COMMIT_SHA = ${ jsonStringifyForHtml( commitSha ) };\n` + `var BUILD_TIMESTAMP = ${ jsonStringifyForHtml( buildTimestamp ) };\n` + `var BUILD_TARGET = ${ jsonStringifyForHtml( target ) };\n` + ( user ? `var currentUser = ${ jsonStringifyForHtml( user ) };\n` : '' ) + ( isSupportSession ? 'var isSupportSession = true;\n' : '' ) + ( isSSP ? 'var isSSP = true;\n' : '' ) + ( app ? `var app = ${ jsonStringifyForHtml( app ) };\n` : '' ) + ( initialReduxState ? `var initialReduxState = ${ jsonStringifyForHtml( initialReduxState ) };\n` : '' ) + ( initialQueryState ? `var initialQueryState = ${ jsonStringifyForHtml( initialQueryState ) };\n` : '' ) + ( clientData ? `var configData = ${ jsonStringifyForHtml( clientData ) };\n` : '' ) + ( languageRevisions ? `var languageRevisions = ${ jsonStringifyForHtml( languageRevisions ) };\n` : '' ) + `var installedChunks = ${ jsonStringifyForHtml( installedChunks ) };\n` + // Inject the locale if we can get it from the route via `getLanguageRouteParam` ( params && params.hasOwnProperty( 'lang' ) ? `var localeFromRoute = ${ jsonStringifyForHtml( params.lang ?? '' ) };\n` : '' ); const theme = config( 'theme' ); const isRTL = isLocaleRtl( lang ); let headTitle = head.title; let headFaviconUrl; let isWCCOM = false; // To customize the page title and favicon for Gravatar-related login pages. if ( sectionName === 'login' && typeof query?.redirect_to === 'string' ) { const searchParams = new URLSearchParams( query.redirect_to.split( '?' )[ 1 ] ); // To cover the case where the `client_id` is not provided, e.g. /log-in/link/use const oauth2Client = initialClientsData[ searchParams.get( 'client_id' ) ] || {}; switch ( true ) { case isGravPoweredOAuth2Client( oauth2Client ): headTitle = oauth2Client.title; headFaviconUrl = oauth2Client.favicon; break; case query?.gravatar_flow: // Use Gravatar's favicon + title for the Gravatar-related OAuth2 clients in SSR. headTitle = gravatarClientData.title; headFaviconUrl = gravatarClientData.favicon; break; case isWooOAuth2Client( oauth2Client ): isWCCOM = true; headTitle = oauth2Client.title; headFaviconUrl = oauth2Client.favicon; break; } } return (
{ head.metas.map( ( props, index ) => ( ) ) } { head.links.map( ( props, index ) => ( ) ) } { chunkCssLinks( entrypoint, isRTL ) } { chunkCssLinks( chunkFiles, isRTL ) } { chunkFiles.js.map( ( chunk ) => ( ) ) } { /* eslint-disable wpcalypso/jsx-classname-namespace, react/no-danger */ } { renderedLayout ? ( ) : (