/* * Copyright 2020 Adobe. All rights reserved. * This file is licensed to you under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. You may obtain a copy * of the License at http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software distributed under * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS * OF ANY KIND, either express or implied. See the License for the specific language * governing permissions and limitations under the License. */ import ChevronRight from '@spectrum-icons/workflow/ChevronRight'; import clsx from 'clsx'; import {Divider} from '@react-spectrum/divider'; import docStyles from './docs.css'; import {getAnchorProps} from './utils'; import heroImageAria from 'url:../pages/assets/ReactAriaOpenGraph.webp'; import heroImageHome from 'url:../pages/assets/ReactSpectrumHome_976x445_2x.png'; import heroImageInternationalized from 'url:../pages/assets/internationalized@2x.png?as=webp&width=1952'; import heroImageSpectrum from 'url:../pages/assets/ReactSpectrum_976x445_2x.png'; import heroImageStately from 'url:../pages/assets/ReactStately_976x445_2x.png'; import highlightCss from './syntax-highlight.css'; import {ImageContext} from './Image'; import {LinkProvider} from './types'; import linkStyle from '@adobe/spectrum-css-temp/components/link/vars.css'; import {MDXProvider} from '@mdx-js/react'; import {MigrationBanner} from './MigrationBanner'; import pageStyles from '@adobe/spectrum-css-temp/components/page/vars.css'; import path from 'path'; import React from 'react'; import ruleStyles from '@adobe/spectrum-css-temp/components/rule/vars.css'; import sideNavStyles from '@adobe/spectrum-css-temp/components/sidenav/vars.css'; import {SlotProvider} from '@react-spectrum/utils'; import {theme} from '@react-spectrum/theme-default'; import {ToC} from './ToC'; import typographyStyles from '@adobe/spectrum-css-temp/components/typography/vars.css'; import {VersionBadge} from './VersionBadge'; const ENABLE_PAGE_TYPES = true; const INDEX_RE = /^(?:[^/]+\/)?index\.html$/; const TLD = process.env.DOCS_ENV === 'production' ? 'react-spectrum.adobe.com' : 'reactspectrum.blob.core.windows.net'; const HERO = { 'react-spectrum': heroImageSpectrum, 'react-aria': heroImageAria, 'react-stately': heroImageStately, internationalized: heroImageInternationalized }; const mdxComponents = { h1: ({children, ...props}) => (
{children}
), ul: ({children, ...props}) => (
{children}
),
inlineCode: ({children, ...props}) => (
{children}
),
a: ({children, ...props}) => (
{children}
)
};
const sectionTitles = {
blog: 'React Spectrum Blog',
releases: 'React Spectrum Releases'
};
function dirToTitle(dir) {
return dir
.split('/')[0]
.split('-')
.map(w => w.charAt(0).toUpperCase() + w.slice(1))
.join(' ');
}
function stripMarkdown(description) {
return (description || '').replace(/\[(.*?)\]\(.*?\)/g, '$1');
}
function isBlogSection(section) {
return section === 'blog';
}
function Page({children, currentPage, publicUrl, styles, scripts, pathToPage}) {
let parts = currentPage.name.split('/');
let isBlog = isBlogSection(parts[0]);
let isSubpage = parts.length > 1 && !INDEX_RE.test(currentPage.name);
let pageSection = isSubpage ? dirToTitle(currentPage.name) : 'React Spectrum';
if (isBlog && isSubpage) {
pageSection = sectionTitles[parts[0]];
}
let keywords = [
...new Set(
currentPage.keywords
.concat([currentPage.category, currentPage.title, pageSection])
.filter(k => !!k)
)
];
let description =
stripMarkdown(currentPage.description) ||
`Documentation for ${currentPage.title} in the ${pageSection} package.`;
let title =
currentPage.title + (!INDEX_RE.test(currentPage.name) || isBlog ? ` – ${pageSection}` : '');
let hero = (parts.length > 1 ? HERO[parts[0]] : '') || heroImageHome;
let heroUrl = `https://${TLD}${currentPage.image || publicUrl + path.basename(hero)}`;
let githubLink = pathToPage;
if (githubLink.startsWith('/tmp/')) {
githubLink = githubLink.slice(5);
githubLink = githubLink.substring(githubLink.indexOf('/') + 1);
githubLink = githubLink.replace(/docs/, 'packages');
}
return (