2018-11-30 22:54:49 +03:00
|
|
|
import React from 'react'
|
|
|
|
import App, {Container} from 'next/app'
|
|
|
|
import {MDXProvider} from '@mdx-js/tag'
|
|
|
|
import Head from 'next/head'
|
|
|
|
import {withMDXLive} from 'mdx-live'
|
|
|
|
import getConfig from 'next/config'
|
2018-12-01 03:20:19 +03:00
|
|
|
import Octicon, {Pencil} from '@githubprimer/octicons-react'
|
2018-12-04 02:53:47 +03:00
|
|
|
import {basename, join} from 'path'
|
2018-11-30 22:54:49 +03:00
|
|
|
import * as docComponents from './doc-components'
|
|
|
|
import * as primerComponents from '@primer/components'
|
|
|
|
|
|
|
|
const {BaseStyles, Box, Flex, Link, Text, theme} = primerComponents
|
|
|
|
const {SideNav, Header, IndexHero} = docComponents
|
|
|
|
|
|
|
|
const DocLink = props => <Link nounderline {...props} />
|
2018-12-04 02:53:47 +03:00
|
|
|
|
|
|
|
const ext = /\.mdx?$/
|
|
|
|
const context = require.context('.', true, /\.mdx?$/)
|
|
|
|
const pathMap = context.keys().reduce((map, key) => {
|
|
|
|
const base = key.replace(ext, '').replace(/\/index$/, '')
|
|
|
|
const path = base.substr(1) // strip the leading "."
|
|
|
|
map[path] = key
|
|
|
|
return map
|
|
|
|
}, {})
|
2018-11-30 22:54:49 +03:00
|
|
|
|
|
|
|
const components = {
|
|
|
|
...docComponents,
|
|
|
|
...primerComponents,
|
|
|
|
Octicon,
|
|
|
|
// render links with our component
|
|
|
|
a: DocLink,
|
|
|
|
code: withMDXLive('pre'),
|
|
|
|
pre: props => props.children
|
|
|
|
}
|
|
|
|
|
|
|
|
export default class MyApp extends App {
|
|
|
|
static async getInitialProps({Component, ctx}) {
|
|
|
|
let page = {}
|
|
|
|
|
|
|
|
if (Component.getInitialProps) {
|
|
|
|
page = await Component.getInitialProps(ctx)
|
|
|
|
}
|
|
|
|
|
|
|
|
return {page}
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
const {pathname} = this.props.router
|
2018-12-04 02:53:47 +03:00
|
|
|
const filename = pathMap[pathname]
|
2018-11-30 22:54:49 +03:00
|
|
|
const {Component, page} = this.props
|
|
|
|
const hasHero = ['/css', '/css/'].includes(pathname)
|
|
|
|
|
2018-12-04 02:53:47 +03:00
|
|
|
const meta = {}
|
|
|
|
if (filename) {
|
|
|
|
Object.assign(meta, context(filename).meta)
|
|
|
|
}
|
|
|
|
|
2018-11-30 22:54:49 +03:00
|
|
|
return (
|
|
|
|
<BaseStyles style={{fontFamily: theme.fonts.normal}}>
|
|
|
|
<Container>
|
|
|
|
<Head>
|
2018-12-04 02:53:47 +03:00
|
|
|
<title>Primer CSS{meta.title ? ` / ${meta.title}` : null}</title>
|
2018-11-30 22:54:49 +03:00
|
|
|
</Head>
|
|
|
|
<Header />
|
|
|
|
<Flex display={['block', 'block', 'flex', 'flex']} flexDirection="row-reverse">
|
|
|
|
<Box width="100%">
|
|
|
|
{hasHero && <IndexHero />}
|
|
|
|
<Box color="gray.9" maxWidth={1012} width={'100%'} my={6} mx={'auto'} px={6} className="markdown-body">
|
2018-12-04 08:19:14 +03:00
|
|
|
{meta.title ? <h1>{meta.title}</h1> : null}
|
2018-11-30 22:54:49 +03:00
|
|
|
<MDXProvider components={components}>
|
|
|
|
<Component {...page} />
|
2018-12-04 02:53:47 +03:00
|
|
|
<pre>meta: {JSON.stringify(meta, null, 2)}</pre>
|
2018-11-30 22:54:49 +03:00
|
|
|
</MDXProvider>
|
2018-12-04 02:53:47 +03:00
|
|
|
{/* TODO: bring back edit link! */}
|
2018-11-30 22:54:49 +03:00
|
|
|
</Box>
|
|
|
|
</Box>
|
|
|
|
<SideNav />
|
|
|
|
</Flex>
|
|
|
|
</Container>
|
|
|
|
</BaseStyles>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|