Merge pull request #286 from dfireBird/mdx-support

feat: Implement MDX
This commit is contained in:
Jean-Philippe Sirois
2020-08-26 16:32:47 -04:00
committed by GitHub
18 changed files with 3249 additions and 1964 deletions
+3 -1
View File
@@ -32,9 +32,11 @@ module.exports = {
}, },
`gatsby-plugin-layout`, `gatsby-plugin-layout`,
{ {
resolve: `gatsby-transformer-remark`, resolve: `gatsby-plugin-mdx`,
options: { options: {
extensions: [`.mdx`, `.md`],
plugins: [`gatsby-remark-auto-headers-improved`], plugins: [`gatsby-remark-auto-headers-improved`],
gatsbyRemarkPlugins: [`gatsby-remark-auto-headers-improved`],
}, },
}, },
{ {
+1 -1
View File
@@ -161,7 +161,7 @@ exports.onCreateNode = async ({ node, getNode, actions }) => {
const { createPage, createNodeField } = actions const { createPage, createNodeField } = actions
// TODO: find a better way to avoid handling non-resources // TODO: find a better way to avoid handling non-resources
// or better, attach authors to what-is archives // or better, attach authors to what-is archives
if (node.internal.type === "MarkdownRemark" && node.frontmatter.authors) { if (node.internal.type === "Mdx" && node.frontmatter.authors) {
const { frontmatter } = node const { frontmatter } = node
const isDoc = Boolean(!frontmatter.path) const isDoc = Boolean(!frontmatter.path)
+1700 -1409
View File
File diff suppressed because it is too large Load Diff
+1502 -514
View File
File diff suppressed because it is too large Load Diff
+3 -1
View File
@@ -30,12 +30,15 @@
"test": "echo \"Write tests! -> https://gatsby.dev/unit-testing\"" "test": "echo \"Write tests! -> https://gatsby.dev/unit-testing\""
}, },
"dependencies": { "dependencies": {
"@mdx-js/mdx": "^1.6.6",
"@mdx-js/react": "^1.6.6",
"@reach/router": "^1.3.3", "@reach/router": "^1.3.3",
"classnames": "^2.2.6", "classnames": "^2.2.6",
"gatsby": "^2.22.11", "gatsby": "^2.22.11",
"gatsby-plugin-google-fonts": "^1.0.1", "gatsby-plugin-google-fonts": "^1.0.1",
"gatsby-plugin-layout": "^1.3.2", "gatsby-plugin-layout": "^1.3.2",
"gatsby-plugin-manifest": "^2.4.9", "gatsby-plugin-manifest": "^2.4.9",
"gatsby-plugin-mdx": "^1.2.16",
"gatsby-plugin-polished": "^1.0.4", "gatsby-plugin-polished": "^1.0.4",
"gatsby-plugin-prefetch-google-fonts": "^1.4.3", "gatsby-plugin-prefetch-google-fonts": "^1.4.3",
"gatsby-plugin-react-helmet": "^3.3.2", "gatsby-plugin-react-helmet": "^3.3.2",
@@ -44,7 +47,6 @@
"gatsby-plugin-styled-components": "^3.3.2", "gatsby-plugin-styled-components": "^3.3.2",
"gatsby-remark-auto-headers-improved": "^1.0.4", "gatsby-remark-auto-headers-improved": "^1.0.4",
"gatsby-source-filesystem": "^2.3.8", "gatsby-source-filesystem": "^2.3.8",
"gatsby-transformer-remark": "^2.8.13",
"gatsby-transformer-sharp": "^2.5.3", "gatsby-transformer-sharp": "^2.5.3",
"github-slugger": "^1.3.0", "github-slugger": "^1.3.0",
"lodash": "^4.17.15", "lodash": "^4.17.15",
+4 -2
View File
@@ -14,6 +14,7 @@ import "prismjs/components/prism-python"
import "prismjs/components/prism-yaml" import "prismjs/components/prism-yaml"
import "prismjs/plugins/line-numbers/prism-line-numbers.css" import "prismjs/plugins/line-numbers/prism-line-numbers.css"
import React, { FC, useEffect } from "react" import React, { FC, useEffect } from "react"
import { MDXRenderer } from "gatsby-plugin-mdx"
import * as SC from "./styles" import * as SC from "./styles"
interface IMarkdownProps { interface IMarkdownProps {
@@ -30,8 +31,9 @@ export const Markdown: FC<IMarkdownProps> = ({ content, ...restProps }) => {
}, []) }, [])
return ( return (
<SC.MarkdownWrapper <SC.MarkdownWrapper
dangerouslySetInnerHTML={{ __html: content }}
{...restProps} {...restProps}
/> >
<MDXRenderer>{content}</MDXRenderer>
</SC.MarkdownWrapper>
) )
} }
@@ -6,7 +6,7 @@ import * as SC from "./styles"
interface IResourcesHomeContent extends HTMLAttributes<HTMLDivElement> { interface IResourcesHomeContent extends HTMLAttributes<HTMLDivElement> {
language: string language: string
html: any body: any
} }
export const ResourcesHomeContent: FC<IResourcesHomeContent> = (props) => { export const ResourcesHomeContent: FC<IResourcesHomeContent> = (props) => {
@@ -20,7 +20,7 @@ export const ResourcesHomeContent: FC<IResourcesHomeContent> = (props) => {
<ResourcesList relativeDirectory={props.language} /> <ResourcesList relativeDirectory={props.language} />
<SC.Box> <SC.Box>
<SC.Title>Extra resources</SC.Title> <SC.Title>Extra resources</SC.Title>
<Markdown content={props.html} /> <Markdown content={props.body} />
</SC.Box> </SC.Box>
<Footer /> <Footer />
</> </>
+1 -1
View File
@@ -15,7 +15,7 @@ const ALL_RESOURCES = graphql`
node { node {
relativePath relativePath
relativeDirectory relativeDirectory
childMarkdownRemark { childMdx {
frontmatter { frontmatter {
authors authors
title title
+2 -2
View File
@@ -18,7 +18,7 @@ const ALL_RESOURCES = graphql`
edges { edges {
node { node {
relativePath relativePath
childMarkdownRemark { childMdx {
frontmatter { frontmatter {
authors authors
title title
@@ -31,7 +31,7 @@ const ALL_RESOURCES = graphql`
edges { edges {
node { node {
relativePath relativePath
childMarkdownRemark { childMdx {
frontmatter { frontmatter {
authors authors
title title
+1 -1
View File
@@ -4,7 +4,7 @@ path: /faq
## What are the roles and what do they mean? ## What are the roles and what do they mean?
### Community-Member,<br>Active Contributor,<br>Chatterbox,<br>Super-Talky-Guy,<br>Bepis-Drinker,<br>Conke-Commander,<br>and Patriotic-Procrastinator ### Community-Member,<br />Active Contributor,<br />Chatterbox,<br />Super-Talky-Guy,<br />Bepis-Drinker,<br />Conke-Commander,<br />and Patriotic-Procrastinator
These are the activity roles of the server in the order you will be granted them. Different tiers will grant different perks, such as unlocking hidden channels, voice access, and nicknaming privileges. These roles are assigned automatically as you participate in the server, so don't ask for them. These are the activity roles of the server in the order you will be granted them. Different tiers will grant different perks, such as unlocking hidden channels, voice access, and nicknaming privileges. These roles are assigned automatically as you participate in the server, so don't ask for them.
+5 -5
View File
@@ -1,7 +1,7 @@
import { graphql } from "gatsby" import { graphql } from "gatsby"
import React, { Fragment } from "react" import React, { Fragment } from "react"
import cx from "classnames" import cx from "classnames"
import { MarkdownRemark } from "../../generated/graphql" import { Mdx } from "../../generated/graphql"
import { ComponentQuery } from "../../typings" import { ComponentQuery } from "../../typings"
import { Markdown } from "../components/Markdown" import { Markdown } from "../components/Markdown"
import { SEO } from "../components/SEO" import { SEO } from "../components/SEO"
@@ -9,7 +9,7 @@ import { PageContent } from "../components/PageContent"
import { HeaderBarebone } from "../components/HeaderBarebone" import { HeaderBarebone } from "../components/HeaderBarebone"
import { buildToc } from "../utils" import { buildToc } from "../utils"
function AboutPage({ data }: ComponentQuery<{ md: MarkdownRemark }>) { function AboutPage({ data }: ComponentQuery<{ md: Mdx }>) {
const { md } = data const { md } = data
const toc = buildToc(md.headings!) const toc = buildToc(md.headings!)
@@ -22,15 +22,15 @@ function AboutPage({ data }: ComponentQuery<{ md: MarkdownRemark }>) {
className={cx({ shifted: toc.length })} className={cx({ shifted: toc.length })}
/> />
<PageContent content={<Markdown content={md.html!} />} toc={toc} /> <PageContent content={<Markdown content={md.body!} />} toc={toc} />
</Fragment> </Fragment>
) )
} }
export const query = graphql` export const query = graphql`
query AboutPage { query AboutPage {
md: markdownRemark(frontmatter: { path: { eq: "/about" } }) { md: mdx(frontmatter: { path: { eq: "/about" } }) {
html body
headings { headings {
depth depth
value value
+5 -5
View File
@@ -1,7 +1,7 @@
import { graphql } from "gatsby" import { graphql } from "gatsby"
import React, { Fragment } from "react" import React, { Fragment } from "react"
import cx from "classnames" import cx from "classnames"
import { MarkdownRemark } from "../../generated/graphql" import { Mdx } from "../../generated/graphql"
import { ComponentQuery } from "../../typings" import { ComponentQuery } from "../../typings"
import { Markdown } from "../components/Markdown" import { Markdown } from "../components/Markdown"
import { SEO } from "../components/SEO" import { SEO } from "../components/SEO"
@@ -9,7 +9,7 @@ import { PageContent } from "../components/PageContent"
import { HeaderBarebone } from "../components/HeaderBarebone" import { HeaderBarebone } from "../components/HeaderBarebone"
import { buildToc } from "../utils" import { buildToc } from "../utils"
function FaqPage({ data }: ComponentQuery<{ md: MarkdownRemark }>) { function FaqPage({ data }: ComponentQuery<{ md: Mdx }>) {
const { md } = data const { md } = data
const toc = buildToc(md.headings!) const toc = buildToc(md.headings!)
@@ -22,15 +22,15 @@ function FaqPage({ data }: ComponentQuery<{ md: MarkdownRemark }>) {
className={cx({ shifted: toc.length })} className={cx({ shifted: toc.length })}
/> />
<PageContent content={<Markdown content={md.html!} />} toc={toc} /> <PageContent content={<Markdown content={md.body!} />} toc={toc} />
</Fragment> </Fragment>
) )
} }
export const query = graphql` export const query = graphql`
query FaqPage { query FaqPage {
md: markdownRemark(frontmatter: { path: { eq: "/faq" } }) { md: mdx(frontmatter: { path: { eq: "/faq" } }) {
html body
headings { headings {
depth depth
value value
+5 -5
View File
@@ -1,7 +1,7 @@
import { graphql } from "gatsby" import { graphql } from "gatsby"
import React, { Fragment } from "react" import React, { Fragment } from "react"
import cx from "classnames" import cx from "classnames"
import { MarkdownRemark } from "../../generated/graphql" import { Mdx } from "../../generated/graphql"
import { ComponentQuery } from "../../typings" import { ComponentQuery } from "../../typings"
import { HeaderBarebone } from "../components/HeaderBarebone" import { HeaderBarebone } from "../components/HeaderBarebone"
import { Markdown } from "../components/Markdown" import { Markdown } from "../components/Markdown"
@@ -9,7 +9,7 @@ import { PageContent } from "../components/PageContent"
import { SEO } from "../components/SEO" import { SEO } from "../components/SEO"
import { buildToc } from "../utils" import { buildToc } from "../utils"
function RulesPage({ data }: ComponentQuery<{ md: MarkdownRemark }>) { function RulesPage({ data }: ComponentQuery<{ md: Mdx }>) {
const { md } = data const { md } = data
const toc = buildToc(md.headings!) const toc = buildToc(md.headings!)
@@ -19,15 +19,15 @@ function RulesPage({ data }: ComponentQuery<{ md: MarkdownRemark }>) {
<SEO title="Rules" /> <SEO title="Rules" />
<HeaderBarebone title="Rules" className={cx({ shifted: toc.length })} /> <HeaderBarebone title="Rules" className={cx({ shifted: toc.length })} />
<PageContent content={<Markdown content={md.html!} />} toc={toc} /> <PageContent content={<Markdown content={md.body!} />} toc={toc} />
</Fragment> </Fragment>
) )
} }
export const query = graphql` export const query = graphql`
query RulesPage { query RulesPage {
md: markdownRemark(frontmatter: { path: { eq: "/rules" } }) { md: mdx(frontmatter: { path: { eq: "/rules" } }) {
html body
headings { headings {
depth depth
value value
+4 -4
View File
@@ -9,7 +9,7 @@ import { PageContent } from "../components/PageContent"
// @todo maybe find alternative type for data // @todo maybe find alternative type for data
const Archive: FC<any> = ({ data }) => { const Archive: FC<any> = ({ data }) => {
const { relativePath, ctime } = data.file const { relativePath, ctime } = data.file
const { html, excerpt, timeToRead } = data.file.post const { body, excerpt, timeToRead } = data.file.post
const title = humanize(relativePath) const title = humanize(relativePath)
@@ -24,7 +24,7 @@ const Archive: FC<any> = ({ data }) => {
timeToRead={timeToRead} timeToRead={timeToRead}
shifted={false} shifted={false}
/> />
<PageContent content={<Markdown content={html} />} /> <PageContent content={<Markdown content={body} />} />
</Fragment> </Fragment>
) )
} }
@@ -36,8 +36,8 @@ export const query = graphql`
file(relativePath: { eq: $file }) { file(relativePath: { eq: $file }) {
relativePath relativePath
ctime ctime
post: childMarkdownRemark { post: childMdx {
html body
excerpt excerpt
timeToRead timeToRead
} }
+4 -4
View File
@@ -10,7 +10,7 @@ import useSidebar from "../hooks/useSidebar"
const ResourceHome: FC<any> = ({ data, pageContext }) => { const ResourceHome: FC<any> = ({ data, pageContext }) => {
const { current: language } = useSidebar() const { current: language } = useSidebar()
const { relativePath } = data.file const { relativePath } = data.file
const { html, excerpt, fields, frontmatter, timeToRead } = data.file.post const { body, excerpt, fields, frontmatter, timeToRead } = data.file.post
const shiftLayout = Boolean( const shiftLayout = Boolean(
frontmatter.recommended_reading || frontmatter.external_resources frontmatter.recommended_reading || frontmatter.external_resources
@@ -34,7 +34,7 @@ const ResourceHome: FC<any> = ({ data, pageContext }) => {
/> />
<PageContent <PageContent
content={ content={
<ResourcesHomeContent language={pageContext.language} html={html} /> <ResourcesHomeContent language={pageContext.language} body={body} />
} }
recommendedReading={frontmatter.recommended_reading} recommendedReading={frontmatter.recommended_reading}
externalResources={frontmatter.external_resources} externalResources={frontmatter.external_resources}
@@ -53,8 +53,8 @@ export const query = graphql`
base: { eq: "intro.md" } base: { eq: "intro.md" }
) { ) {
relativePath relativePath
post: childMarkdownRemark { post: childMdx {
html body
excerpt excerpt
fields { fields {
authors { authors {
+4 -4
View File
@@ -14,7 +14,7 @@ const ResourcePage: FC<any> = ({ data }) => {
const { current: language } = useSidebar() const { current: language } = useSidebar()
const { relativePath } = data.file const { relativePath } = data.file
const { const {
html, body,
headings, headings,
excerpt, excerpt,
fields, fields,
@@ -49,7 +49,7 @@ const ResourcePage: FC<any> = ({ data }) => {
<PageContent <PageContent
content={ content={
<> <>
<Markdown content={html} /> <Markdown content={body} />
<Footer /> <Footer />
</> </>
} }
@@ -67,8 +67,8 @@ export const query = graphql`
query ResourcePage($file: String!) { query ResourcePage($file: String!) {
file(relativePath: { eq: $file }) { file(relativePath: { eq: $file }) {
relativePath relativePath
post: childMarkdownRemark { post: childMdx {
html body
headings { headings {
depth depth
value value
+1 -1
View File
@@ -23,7 +23,7 @@ export interface IFileResourceQuery {
node: { node: {
relativePath: string relativePath: string
relativeDirectory: string relativeDirectory: string
childMarkdownRemark: { childMdx: {
frontmatter: { frontmatter: {
author: string author: string
date: string date: string
+2 -2
View File
@@ -5,7 +5,7 @@ import pipe from "ramda/es/pipe"
import sort from "ramda/es/sort" import sort from "ramda/es/sort"
import { IFile, IFileOrFolder, IFolder, ITocItem } from "../types" import { IFile, IFileOrFolder, IFolder, ITocItem } from "../types"
import { MarkdownRemark } from "../../generated/graphql" import { Mdx } from "../../generated/graphql"
const slugger = new GithubSlugger() const slugger = new GithubSlugger()
@@ -141,7 +141,7 @@ export function join([head, ...tail]: IFileOrFolder[]): IFileOrFolder[] {
return [current, ...join(remaining)] return [current, ...join(remaining)]
} }
export function buildToc(headings: MarkdownRemark["headings"]): ITocItem[] { export function buildToc(headings: Mdx["headings"]): ITocItem[] {
if (!headings) { if (!headings) {
return [] return []
} }