Use nextjs mdx feature and configure plugins
This commit is contained in:
parent
ce24e488d1
commit
a6df3de06f
@ -1,10 +1,9 @@
|
|||||||
import Layout from '../components/Layout'
|
import Layout from '../components/Layout'
|
||||||
|
|
||||||
import { MDXRemote } from 'next-mdx-remote'
|
|
||||||
import dynamic from 'next/dynamic'
|
|
||||||
import Head from 'next/head'
|
import Head from 'next/head'
|
||||||
import Link from 'next/link'
|
import Excel from '../components/Excel'
|
||||||
|
import Table from '../components/Table'
|
||||||
|
import LineChart from '../components/LineChart'
|
||||||
|
import { MDXProvider } from '@mdx-js/react'
|
||||||
import { Vega, VegaLite } from 'react-vega'
|
import { Vega, VegaLite } from 'react-vega'
|
||||||
|
|
||||||
// Custom components/renderers to pass to MDX.
|
// Custom components/renderers to pass to MDX.
|
||||||
@ -12,32 +11,36 @@ import { Vega, VegaLite } from 'react-vega'
|
|||||||
// to handle import statements. Instead, you must include components in scope
|
// to handle import statements. Instead, you must include components in scope
|
||||||
// here.
|
// here.
|
||||||
const components = {
|
const components = {
|
||||||
Table: dynamic(() => import('../components/Table')),
|
Table,
|
||||||
Excel: dynamic(() => import('../components/Excel')),
|
Excel,
|
||||||
// TODO: try and make these dynamic ...
|
Vega,
|
||||||
Vega: Vega,
|
VegaLite,
|
||||||
VegaLite: VegaLite,
|
LineChart,
|
||||||
LineChart: dynamic(() => import('../components/LineChart')),
|
|
||||||
Head,
|
Head,
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function DataLiterate({ children, source, frontMatter }) {
|
|
||||||
|
export default function DataLiterate({ children }) {
|
||||||
|
const { Component, pageProps } = children
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Layout title={frontMatter.title}>
|
<Layout title={pageProps.title}>
|
||||||
<div className="prose mx-auto">
|
<div className="prose mx-auto">
|
||||||
<header>
|
<header>
|
||||||
<div className="mb-6">
|
<div className="mb-6">
|
||||||
<h1>{frontMatter.title}</h1>
|
<h1>{pageProps.title}</h1>
|
||||||
{frontMatter.author && (
|
{pageProps.author && (
|
||||||
<div className="-mt-6"><p className="opacity-60 pl-1">{frontMatter.author}</p></div>
|
<div className="-mt-6"><p className="opacity-60 pl-1">{pageProps.author}</p></div>
|
||||||
)}
|
)}
|
||||||
{frontMatter.description && (
|
{pageProps.description && (
|
||||||
<p className="description">{frontMatter.description}</p>
|
<p className="description">{pageProps.description}</p>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
</header>
|
</header>
|
||||||
<main>
|
<main>
|
||||||
<MDXRemote {...source} components={components} />
|
<MDXProvider components={components}>
|
||||||
|
<Component {...pageProps} />
|
||||||
|
</MDXProvider>
|
||||||
</main>
|
</main>
|
||||||
</div>
|
</div>
|
||||||
</Layout>
|
</Layout>
|
||||||
|
|||||||
20
examples/data-literate/next.config.js
Normal file
20
examples/data-literate/next.config.js
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
const matter = require('gray-matter')
|
||||||
|
const toc = require('remark-toc')
|
||||||
|
const slug = require('remark-slug')
|
||||||
|
const gfm = require('remark-gfm')
|
||||||
|
const footnotes = require('remark-footnotes')
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
const withMDX = require('@next/mdx')({
|
||||||
|
extension: /\.mdx?$/,
|
||||||
|
options: {
|
||||||
|
remarkPlugins: [gfm, toc, slug, footnotes],
|
||||||
|
rehypePlugins: [],
|
||||||
|
providerImportSource: '@mdx-js/react',
|
||||||
|
},
|
||||||
|
})
|
||||||
|
module.exports = withMDX({
|
||||||
|
// Append the default value with md extensions
|
||||||
|
pageExtensions: ['ts', 'tsx', 'js', 'jsx', 'md', 'mdx'],
|
||||||
|
})
|
||||||
@ -4,19 +4,19 @@
|
|||||||
"private": true,
|
"private": true,
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "next dev",
|
"dev": "next dev",
|
||||||
"build": "next build",
|
|
||||||
"build": "next build && next export",
|
"build": "next build && next export",
|
||||||
"start": "next start"
|
"start": "next start"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@headlessui/react": "^1.3.0",
|
"@headlessui/react": "^1.3.0",
|
||||||
"@heroicons/react": "^1.0.3",
|
"@heroicons/react": "^1.0.3",
|
||||||
"@mdx-js/loader": "^1.6.22",
|
"@mdx-js/loader": "^2.0.0",
|
||||||
|
"@next/mdx": "^12.1.0",
|
||||||
"@tailwindcss/typography": "^0.4.0",
|
"@tailwindcss/typography": "^0.4.0",
|
||||||
"autoprefixer": "^10.0.4",
|
"autoprefixer": "^10.0.4",
|
||||||
"frictionless.js": "^0.13.4",
|
"frictionless.js": "^0.13.4",
|
||||||
"gray-matter": "^4.0.3",
|
"gray-matter": "^4.0.3",
|
||||||
"next": "11.1.3",
|
"next": "12.1.0",
|
||||||
"next-mdx-remote": "^3.0.4",
|
"next-mdx-remote": "^3.0.4",
|
||||||
"papaparse": "^5.3.1",
|
"papaparse": "^5.3.1",
|
||||||
"postcss": "^8.2.10",
|
"postcss": "^8.2.10",
|
||||||
@ -26,6 +26,7 @@
|
|||||||
"react-vega": "^7.4.4",
|
"react-vega": "^7.4.4",
|
||||||
"remark": "^13.0.0",
|
"remark": "^13.0.0",
|
||||||
"remark-footnotes": "^3.0.0",
|
"remark-footnotes": "^3.0.0",
|
||||||
|
"remark-frontmatter": "^4.0.1",
|
||||||
"remark-gfm": "^1.0.0",
|
"remark-gfm": "^1.0.0",
|
||||||
"remark-html": "^13.0.2",
|
"remark-html": "^13.0.2",
|
||||||
"remark-slug": "^6.1.0",
|
"remark-slug": "^6.1.0",
|
||||||
|
|||||||
@ -1,8 +1,12 @@
|
|||||||
import '../styles/globals.css'
|
import '../styles/globals.css'
|
||||||
import '../styles/tailwind.css'
|
import '../styles/tailwind.css'
|
||||||
|
import DataLiterate from '../components/DataLiterate'
|
||||||
|
|
||||||
|
|
||||||
function MyApp({ Component, pageProps }) {
|
function MyApp({ Component, pageProps }) {
|
||||||
return <Component {...pageProps} />
|
return (
|
||||||
|
<DataLiterate children={{ Component, pageProps }}/>
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
export default MyApp
|
export default MyApp
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
Loading…
x
Reference in New Issue
Block a user