import React from 'react' import Head from 'next/head' import { useRouter } from 'next/router' import { SidebarNav } from '@/frame/components/sidebar/SidebarNav' import { Header } from '@/frame/components/page-header/Header' import { LegalFooter } from '@/frame/components/page-footer/LegalFooter' import { ScrollButton } from '@/frame/components/ui/ScrollButton' import { SupportSection } from '@/frame/components/page-footer/SupportSection' import { DeprecationBanner } from '@/versions/components/DeprecationBanner' import { RestBanner } from '@/rest/components/RestBanner' import { useMainContext } from '@/frame/components/context/MainContext' import { useTranslation } from '@/languages/components/useTranslation' import { Breadcrumbs } from '@/frame/components/page-header/Breadcrumbs' import { useLanguages } from '@/languages/components/LanguagesContext' import { ClientSideLanguageRedirect } from './ClientSideLanguageRedirect' import { SearchOverlayContextProvider } from '@/search/components/context/SearchOverlayContext' import styles from './DefaultLayout.module.scss' const MINIMAL_RENDER = Boolean(JSON.parse(process.env.MINIMAL_RENDER || 'false')) type Props = { children?: React.ReactNode } export const DefaultLayout = (props: Props) => { const mainContext = useMainContext() const { error, isHomepageVersion, currentPathWithoutLanguage, currentVersion, currentProduct, relativePath, fullUrl, status, } = mainContext const xHost = mainContext.xHost const page = mainContext.page! const { t } = useTranslation(['meta', 'scroll_button']) const router = useRouter() const { languages } = useLanguages() // This is only true when we do search indexing which renders every page // just to be able to `cheerio` load the main body (and the meta // keywords tag). if (MINIMAL_RENDER) { return (
{page.fullTitle} {/* For local site search indexing */}
{props.children}
) } const metaDescription = page.introPlainText ? page.introPlainText : t('default_description') const SOCIAL_CATEGORIES = new Set(['code-security', 'actions', 'issues', 'copilot']) const SOCIAL_CARD_IMG_BASE_URL = `${xHost ? `https://${xHost}` : ''}/assets/cb-345/images/social-cards` function getCategoryImageUrl(category: string): string { return `${SOCIAL_CARD_IMG_BASE_URL}/${category}.png` } function getSocialCardImage(): string { if (currentProduct && SOCIAL_CATEGORIES.has(currentProduct.id)) { return getCategoryImageUrl(currentProduct.id) } return getCategoryImageUrl('default') } return ( {error === '404' ? ( {t('oops')} ) : (!isHomepageVersion && page.fullTitle) || (currentPathWithoutLanguage.includes('enterprise-server') && page.fullTitle) ? ( {page.fullTitle} ) : null} {/* For Google and Bots */} {page.hidden && } {Object.values(languages) .filter((lang) => lang.code !== router.locale) .map((variant) => { return ( ) })} {/* For local site search indexing */} {page.topics.length > 0 && } {/* For analytics events */} {router.locale && } {currentVersion && } {currentProduct && } {relativePath && ( )} {page.type && } {page.contentType && } {page.documentType && } {status && } {/* OpenGraph data */} {page.fullTitle && ( <> )} {/* Twitter Meta Tags */} {page.introPlainText && } {/* LLM-friendly alternate formats - only for articles */} {page.documentType === 'article' && ( <> )} {/* a11y */} Skip to main content
{isHomepageVersion ? null : } {/* Need to set an explicit height for sticky elements since we also set overflow to auto */}
{props.children}
) }