Digital Gardening with MDX Magic

A presentation at MDXConf in August 2020 in by Kathleen McMahon

Slide 1

Slide 1

Hi, my name is Kathleen McMahon and I’m here today to talk about Digital Gardening with MDX Magic. Before we begin, let’s get some details out of the way

Slide 2

Slide 2

My slide deck will be posted on Notist, including links to resources I briefly touch upon. The full URL will be available later today on Twitter.

Slide 3

Slide 3

You can follow me at. Resource11 on Twitter, Instagram, and GitHub.
Before we dig into the talk, let’s back up so I can introduce myself better…

Slide 4

Slide 4

I’m a Principal Engineer, and will soon be joining the rad people at CarGurus

Slide 5

Slide 5

And I race bikes… very badly.

Slide 6

Slide 6

Mostly you’ll see me in costume, racing two laps to your six, at the back of the pack, on a singlespeed. Mostly. Unless something happens.

Slide 7

Slide 7

Like a pandemic kicking in our doors. Then your racing season is postponed, and you focus on something else, like…

Slide 8

Slide 8

Maybe reworking my site. Digital garden style.

Slide 9

Slide 9

What is a Digital Garden? So if you haven’t heard of the term, a digital garden is a site that is a collection of pages and posts in various states of completion.

Slide 10

Slide 10

As Joel Hooks says, “The phrase ‘digital garden’ is a metaphor for thinking about writing and creating that focuses less on the resulting “showpiece” and more on the process, care, and craft it takes to get there.”

In other words, it’s a great place to get your thoughts down, and care for it later… or not.

Slide 11

Slide 11

You may ask.. why digital gardening? I’m not sure about any of y’all, but I have more that one personal site that I’ve created over the years, using the technology of the time… Every once in a while, I’d look back at that site and think “wow, you should really update that code, Kathleen.” Or… “those designs look a bit long in the tooth, don’t you think? And then my brain starts going…

Slide 12

Slide 12

Should I refactor the site? Should I refactor all the projects? Will I make questionable choices in the redesign and end up with something like…

Slide 13

Slide 13

…a recipe that combines Jello with shellfish? …and then I wander to…

Slide 14

Slide 14

Should I toss all those sites out and start again? Wait! What about that blog post I wanted to write? How should I structure those blog posts?” Then — right on cue — option paralysis makes an appearance. And nothing. Gets done. Years go by, and the cycle repeats. Off! That’s a lot.

Slide 15

Slide 15

Digital gardening as a way of working really struck a chord with me because it was the perfect blend of what works for me. I could create a site that’s more of a catch-all for my interests, publish what I want, without thinking of the “state of done”, and keep moving. I could make a code reference for future me to remember something I learned at the time. If I want to go back and edit? Cool. If not, no big deal.

Slide 16

Slide 16

How does MDX fit into this?

Slide 17

Slide 17

I think of MDX like my Mom’s garden in the spring. MDX is the soil prepped and ready with a layer of bark mulch, rocks lining all the pathways to give a hint of guidance, providing a solid start to your garden design, yet allowing you the freedom to plant in whatever way suits your mood.

Slide 18

Slide 18

I think of MDX like my Mom’s garden in the spring. MDX is the soil prepped and ready with a layer of bark mulch, rocks lining all the pathways to give a hint of guidance, providing a solid start to your garden design, yet allowing you the freedom to plant in whatever way suits your mood.

Slide 19

Slide 19

I think of MDX like my Mom’s garden in the spring. MDX is the soil prepped and ready with a layer of bark mulch, rocks lining all the pathways to give a hint of guidance, providing a solid start to your garden design, yet allowing you the freedom to plant in whatever way suits your mood.

Slide 20

Slide 20

I think of MDX like my Mom’s garden in the spring. MDX is the soil prepped and ready with a layer of bark mulch, rocks lining all the pathways to give a hint of guidance, providing a solid start to your garden design, yet allowing you the freedom to plant in whatever way suits your mood.

Slide 21

Slide 21

I think of MDX like my Mom’s garden in the spring. MDX is the soil prepped and ready with a layer of bark mulch, rocks lining all the pathways to give a hint of guidance, providing a solid start to your garden design, yet allowing you the freedom to plant in whatever way suits your mood.

Slide 22

Slide 22

I think of MDX like my Mom’s garden in the spring. MDX is the soil prepped and ready with a layer of bark mulch, rocks lining all the pathways to give a hint of guidance, providing a solid start to your garden design, yet allowing you the freedom to plant in whatever way suits your mood.

Slide 23

Slide 23

I think of MDX like my Mom’s garden in the spring. MDX is the soil prepped and ready with a layer of bark mulch, rocks lining all the pathways to give a hint of guidance, providing a solid start to your garden design, yet allowing you the freedom to plant in whatever way suits your mood.

Slide 24

Slide 24

I think of MDX like my Mom’s garden in the spring. MDX is the soil prepped and ready with a layer of bark mulch, rocks lining all the pathways to give a hint of guidance, providing a solid start to your garden design, yet allowing you the freedom to plant in whatever way suits your mood.

Slide 25

Slide 25

MDX also reminds me of coloring books. Especially the Magic series of illustrations by Johanna Basford.

Slide 26

Slide 26

Her illustrations are wonderful on their own, yet they give a good basis to show off your own creativity. You can enhance — or cultivate — the illustrations to whatever state of done-ness, re-work, or level of detail that makes sense for you — and the end product looks great.

Slide 27

Slide 27

Her illustrations are wonderful on their own, yet they give a good basis to show off your own creativity. You can enhance — or cultivate — the illustrations to whatever state of done-ness, re-work, or level of detail that makes sense for you — and the end product looks great.

Slide 28

Slide 28

Her illustrations are wonderful on their own, yet they give a good basis to show off your own creativity. You can enhance — or cultivate — the illustrations to whatever state of done-ness, re-work, or level of detail that makes sense for you — and the end product looks great.

Slide 29

Slide 29

Her illustrations are wonderful on their own, yet they give a good basis to show off your own creativity. You can enhance — or cultivate — the illustrations to whatever state of done-ness, re-work, or level of detail that makes sense for you — and the end product looks great.

Slide 30

Slide 30

Her illustrations are wonderful on their own, yet they give a good basis to show off your own creativity. You can enhance — or cultivate — the illustrations to whatever state of done-ness, re-work, or level of detail that makes sense for you — and the end product looks great.

Slide 31

Slide 31

Her illustrations are wonderful on their own, yet they give a good basis to show off your own creativity. You can enhance — or cultivate — the illustrations to whatever state of done-ness, re-work, or level of detail that makes sense for you — and the end product looks great.

Slide 32

Slide 32

Her illustrations are wonderful on their own, yet they give a good basis to show off your own creativity. You can enhance — or cultivate — the illustrations to whatever state of done-ness, re-work, or level of detail that makes sense for you — and the end product looks great.

Slide 33

Slide 33

Her illustrations are wonderful on their own, yet they give a good basis to show off your own creativity. You can enhance — or cultivate — the illustrations to whatever state of done-ness, re-work, or level of detail that makes sense for you — and the end product looks great.

Slide 34

Slide 34

Her illustrations are wonderful on their own, yet they give a good basis to show off your own creativity. You can enhance — or cultivate — the illustrations to whatever state of done-ness, re-work, or level of detail that makes sense for you — and the end product looks great.

Slide 35

Slide 35

Her illustrations are wonderful on their own, yet they give a good basis to show off your own creativity. You can enhance — or cultivate — the illustrations to whatever state of done-ness, re-work, or level of detail that makes sense for you — and the end product looks great.

Slide 36

Slide 36

Her illustrations are wonderful on their own, yet they give a good basis to show off your own creativity. You can enhance — or cultivate — the illustrations to whatever state of done-ness, re-work, or level of detail that makes sense for you — and the end product looks great.

Slide 37

Slide 37

Her illustrations are wonderful on their own, yet they give a good basis to show off your own creativity. You can enhance — or cultivate — the illustrations to whatever state of done-ness, re-work, or level of detail that makes sense for you — and the end product looks great.

Slide 38

Slide 38

I think of MDX as the Magic that makes a garden great, in whatever form it is created.

Slide 39

Slide 39

Why MDX? There are many benefits of MDX. You can write a blog post using Markdown and import React components right in the file. Even better, MDX will compile down into… Semantic HTML. Which in, gives your site… Improved accessibility. Better support for your users that rely on assistive technology to access your blog. You can use frontmatter as props to control what you display on a page You can import your own components, or components from another library Shortcodes. With MDX, you can override the styling of a Markdown tag and make it available globally on your site.

Slide 40

Slide 40

When I originally created my digital garden, I chose to use Gatsby, which supports MDX — and provides a Webpack and Babel config similar to create-react-app, so I could start with a scaffolded project, and extend as needed.

Slide 41

Slide 41

The default setup for Gatsby is great, however, I made some adjustments so Gatsby works for my needs.

Slide 42

Slide 42

In the gatsby-config file… I added gatsby-plugin-postcss to support PostCSS… gatsby-plugin-mdx, so our site will recognize MDX files.. gatsby-source-filesystem … to point Gatsby to the folder where all our component MDX files live.

Slide 43

Slide 43

In the gatsby-node file… I added a GraphQL query to find the post MDX content And a createPage action to generate routes and pages for the component docs.

Slide 44

Slide 44

…into the gatsby-browser file, since this file is used to make changes at the site-wide level. I added global CSS styles to make baseline typography styles available and the wrap-root-element component. I’ll talk about that one later.

Slide 45

Slide 45

I had to do one extra thing for the blog post template, though.

Slide 46

Slide 46

Since my blog post MDX files are located outside of the src/pages folder, MDXRenderer needs to wrap the contents of the blog post layout template, so the content will render as expected in the browser.

Now that this is all set up, let’s dig into some cool things you can do with MDX.

Slide 47

Slide 47

You can use frontmatter to control what you display on a page use frontmatter as props. You create nodes from frontmatter, query with graphQL You can use custom slugs. You can show/hide items on a page depending on frontmatter props.

Slide 48

Slide 48

You can import your own components, or components from another library.

Slide 49

Slide 49

For example, gatsby-embed-mdx by Paul Scanlone is awesome!

Slide 50

Slide 50

Shortcodes. With MDX, you can swap in React components for markdown tags.

Slide 51

Slide 51

This wrap-root-element component will act as a wrapper around our site’s root element…

Slide 52

Slide 52

…And imports MDXProvider. This, way the entire site will recognize MDX content. This is a great place to add shortcodes to make them available throughout your site, considering the wrap-root-element file is added in the gatsby-browser file

Slide 53

Slide 53

Grommet

Slide 54

Slide 54

Code blocks. Markdown has great code block support. MDX makes those even more powerful. You can override the styling of a code block in an MDX file with a custom code block, or even display different types of code blocks.

Slide 55

Slide 55

You could use prism-react-renderer in a custom CodeBlock component and import a theme with good color contrast … wrap your code block and theme it… Import that into your wrap-root-element along with the preToCodeBlock util And override the default pre styling at the app level by passing it in as a component to the wrapRootElement.

So now when you write a code block in MDX Fun fact: you can pass in a prop to that code block and do really cool things if you use custom code blocks!

Slide 56

Slide 56

Import that into your wrap-root-element along with the preToCodeBlock util.

Slide 57

Slide 57

You can add a react-live option in our component.

Slide 58

Slide 58

… So if we write something like this… jsx react-live <Button size="large">Click me</Button>jsx <Button size="large">Click me</Button>jsx displaybox <Button size="large">Click me</Button> this is what you see in the app.

Slide 59

Slide 59

So to wrap up…

Slide 60

Slide 60

MDX is powerful. And is getting better and better. Pair it with the freedom — and creativity — of the digital garden philosophy — and you can cultivate some serious. Magic.

Slide 61

Slide 61

MDX is powerful. And is getting better and better. Pair it with the freedom — and creativity — of the digital garden philosophy — and you can cultivate some serious. Magic.

Slide 62

Slide 62

MDX is powerful. And is getting better and better. Pair it with the freedom — and creativity — of the digital garden philosophy — and you can cultivate some serious. Magic.

Slide 63

Slide 63

MDX is powerful. And is getting better and better. Pair it with the freedom — and creativity — of the digital garden philosophy — and you can cultivate some serious. Magic.

Slide 64

Slide 64

MDX is powerful. And is getting better and better. Pair it with the freedom — and creativity — of the digital garden philosophy — and you can cultivate some serious. Magic.

Slide 65

Slide 65

MDX is powerful. And is getting better and better. Pair it with the freedom — and creativity — of the digital garden philosophy — and you can cultivate some serious. Magic.

Slide 66

Slide 66

Thank you.

Slide 67

Slide 67

@resource11 https://noti.st/resource11 Slide deck posted after the talk @resource11 Twitter | Instagram | GitHub