/** * Copyright (c) 2013-present, Facebook, Inc. * * @emails react-core * @flow */ import Container from 'components/Container'; import Flex from 'components/Flex'; import MarkdownHeader from 'components/MarkdownHeader'; import NavigationFooter from 'templates/components/NavigationFooter'; import React from 'react'; import StickyResponsiveSidebar from 'components/StickyResponsiveSidebar'; import TitleAndMetaTags from 'components/TitleAndMetaTags'; import findSectionForPath from 'utils/findSectionForPath'; import toCommaSeparatedList from 'utils/toCommaSeparatedList'; import {sharedStyles} from 'theme'; import createOgUrl from 'utils/createOgUrl'; import type {Node} from 'types'; type Props = { authors: Array, createLink: Function, // TODO: Add better flow type once we Flow-type createLink date?: string, enableScrollSync?: boolean, ogDescription: string, location: Location, markdownRemark: Node, sectionList: Array, // TODO: Add better flow type once we have the Section component titlePostfix: string, }; const getPageById = (sectionList: Array, templateFile: ?string) => { if (!templateFile) { return null; } const sectionItems = sectionList.map(section => section.items); const flattenedSectionItems = [].concat.apply([], sectionItems); const linkId = templateFile.replace('.html', ''); return flattenedSectionItems.find(item => item.id === linkId); }; const MarkdownPage = ({ authors = [], createLink, date, enableScrollSync, ogDescription, location, markdownRemark, sectionList, titlePostfix = '', }: Props) => { const hasAuthors = authors.length > 0; const titlePrefix = markdownRemark.frontmatter.title || ''; const prev = getPageById(sectionList, markdownRemark.frontmatter.prev); const next = getPageById(sectionList, markdownRemark.frontmatter.next); return (
{(date || hasAuthors) && (
{date}{' '} {hasAuthors && ( by{' '} {toCommaSeparatedList(authors, author => ( {author.frontmatter.name} ))} )}
)}
{markdownRemark.fields.path && ( )}
{(next || prev) && ( )} ); }; export default MarkdownPage;