import { useState, useEffect } from 'react' import { useRouter } from 'next/router' import dynamic from 'next/dynamic' import { ZapIcon, InfoIcon, ShieldLockIcon } from '@primer/octicons-react' import { Callout } from 'components/ui/Callout' import { Link } from 'components/Link' import { DefaultLayout } from 'components/DefaultLayout' import { ArticleTitle } from 'components/article/ArticleTitle' import { useArticleContext } from 'components/context/ArticleContext' import { useTranslation } from 'components/hooks/useTranslation' import { LearningTrackNav } from './LearningTrackNav' import { MarkdownContent } from 'components/ui/MarkdownContent' import { Lead } from 'components/ui/Lead' import { ArticleGridLayout } from './ArticleGridLayout' import { PlatformPicker } from 'components/article/PlatformPicker' import { ToolPicker } from 'components/article/ToolPicker' import { MiniTocs } from 'components/ui/MiniTocs' const ClientSideHighlightJS = dynamic(() => import('./ClientSideHighlightJS'), { ssr: false }) // Mapping of a "normal" article to it's interactive counterpart const interactiveAlternatives: Record = { '/codespaces/setting-up-your-project-for-codespaces/setting-up-your-nodejs-project-for-codespaces': { href: '/codespaces/setting-up-your-project-for-codespaces/setting-up-your-project-for-codespaces?langId=nodejs', }, '/codespaces/setting-up-your-project-for-codespaces/setting-up-your-dotnet-project-for-codespaces': { href: '/codespaces/setting-up-your-project-for-codespaces/setting-up-your-project-for-codespaces?langId=dotnet', }, '/codespaces/setting-up-your-project-for-codespaces/setting-up-your-java-project-for-codespaces': { href: '/codespaces/setting-up-your-project-for-codespaces/setting-up-your-project-for-codespaces?langId=java', }, '/codespaces/setting-up-your-project-for-codespaces/setting-up-your-python-project-for-codespaces': { href: '/codespaces/setting-up-your-project-for-codespaces/setting-up-your-project-for-codespaces?langId=py', }, } type Props = { children?: React.ReactNode } export const ArticlePage = ({ children }: Props) => { const { asPath } = useRouter() const { title, intro, effectiveDate, renderedPage, contributor, permissions, includesPlatformSpecificContent, includesToolSpecificContent, product, miniTocItems, currentLearningTrack, } = useArticleContext() const { t } = useTranslation('pages') const currentPath = asPath.split('?')[0] // If the page contains `[data-highlight]` blocks, these pages need // syntax highlighting. But not every page needs it, so it's conditionally // lazy-loaded on the client. const [lazyLoadHighlightJS, setLazyLoadHighlightJS] = useState(false) useEffect(() => { // It doesn't need to use querySelector because all we care about is if // there is greater than zero of these in the DOM. // Note! This "core selector", which determines whether to bother // or not, needs to match what's used inside ClientSideHighlightJS.tsx if (document.querySelector('[data-highlight]')) { setLazyLoadHighlightJS(true) } // Important to depend on the current path because the first page you // load, before any client-side navigation, might not need it, but the // consecutive one does. }, [asPath]) return ( {/* Doesn't matter *where* this is included because it will never render anything. It always just return null. */} {lazyLoadHighlightJS && }
{title}} intro={ <> {contributor && (

{t('contributor_callout')} {contributor.name}.

)} {intro && ( {intro} )} {permissions && (
)} {includesPlatformSpecificContent && } {includesToolSpecificContent && } {product && ( )} } toc={ <> {!!interactiveAlternatives[currentPath] && (
Try the new interactive article
)} {miniTocItems.length > 1 && ( )} } >
{children || renderedPage} {effectiveDate && (
Effective as of:{' '}
)}
{currentLearningTrack?.trackName ? (
) : null}
) }