A presentation at React Alicante 2023 in in Alicante, Spain by Kathleen McMahon
● Welcome everyone! I’m Kathleen McMahon and I’m here today to talk about Bye-bye Weeds! Digital Gardening with Astro and MDX.
● Before we begin, let’s get some details out of the way.
First, I want to give a huge thank you to Victoria and Nacho, the speakers, the event production crew, the volunteers, and everyone who worked so hard to create an excellent event!
My presentation will be posted on Notist, that’s https://noti.st/resource11, after my talk. I’ll also post the full URL on Twitter sometime after my presentation
● You can follow me at. Resource11 on Twitter, GitHub, and Instagram.
● Let’s back up so I can introduce myself a bit better…
So I’m an engineer and a designer and I like to speak about things…
I’m an occasional cyclocross racer,
In costume of course.
Lover of lights
Beach goer.
Sand dollar collector
Lover of my cats Thor
…and Otis.
I’m a Crystal collector
And I photograph them, but Otis…
…interferes often
…with opinions…
…about my attention. Thanks, Otis
Thor does the same…
He’s very satisfied with himself.
Who could resist them?
I am also a senior Design Systems engineer at Northwestern Mutual.
And I love Design Systems! it’s exciting work! Especially if you like…
…herding kittens. Always fun, with many moving parts. Part of Design System work includes trying out different software stacks and choosing the best tool for your system, like Gatsby.
Speaking of Gatsby and MDX, they’re what I chose to build my Digital Garden site…
kathleenmcmahon.dev back in 2020…
So… what is a digital garden?
this blog post by Joel Hooks, and this phrase makes sense to me: “What makes a garden is interesting. It’s personal. Things are organized and orderly, but with a touch of chaos around the edges.”
● I latched on to the idea of creating a digital garden and using Gatsby and MDX as my stack for a few reasons…
● One because I tend to love trying…
All the things! All the latest software, but at the same time…
I struggle with making progress over seeking perfection, and if I’m not careful, lean towards making…
● “Big Lexus bows” vs. “Tiny kitten bows”. Wow can I hyper-focus on the details, make that perfectly crafted piece of software before shipping. That’s heck on velocity, though.
● The digital garden format keeps me in the kitten bow mindset. This way, progress happens, and blog posts get written. New things get shipped.
● Fast forward a few years and… a few talk listing and package updates later… I noticed that my Digital Garden got… weedy. And Gatsby had versioned up to 5.3, while my site was on 2.3
● I considering an upgrade and asked an industry colleague familiar with Gatsby how painful this upgrade would be. Of course I already knew the answer. 3 major versions. Ouch. But! After asking, and hearing the expected — yes it’ll be a pain — the advice leaned towards the obvious.
● “If it’s using JavaScript, it requires regular maintenance” (OK…) which turned into a suggestion to use Squarespace, since it didn’t require maintenance.
[image]: UnSplash — masaaki-komori—0M1TKzvr3Y-unsplash
And that kinda sounded like JavaScript’s hard… and maybe you’re out of your league…
“…maybe you should create a Squarespace site?”
Did you just say something was hard? Hello… spite driven development. By golly I would upgrade this app three versions up. Squarespace my butt.
Still shaking my head about that Squarespace suggestion.
● Ten hours later, after a Netflix binge and upgrade session…I come up for air. I’ve fixed all the new GraphQL changes and was wrestling with the Gatsby image API, and now I’m questioning life choices…
● I was Just like combining jello with shellfish deciding to go all in was not a great decision.
I thought “I have a four-page static site. Why am I using a JavaScript framework to render four static pages in a blog, and…
● why am I using JSX to create HTML when I could just use HTML?”
● Granted, I work on Design Systems. I love creating component APIs, and love using React, so I’m the last person to say just throw it all out, but there are times where you need a four-page site without throwing all this JavaScript at it just to render something that’s small, lean, performant, and just doesn’t need to be a SPA, it needs to be a multi-page app.
And the Gatsby of 2020 isn’t the same as it is today. That hot static site generator everyone wanted to use has evolved into this suite of industrial farming equipment.
[image] UnSplash — darla-hueske-SD18qQeXEg8
I don’t need a combine machine when a hoe and rake will do for my needs.
[image] UnSplash — diana-light-342WASC0aSQ
● It was time to weed out the complexity, and choose a new framework
● One that will compile right down to HTML CSS and only serve the minimal amount of JavaScript if I need it.
[image] UnSplash — ales-krivec-6UtxyuTdpQU
So I looked around — and because there’s a bunch out there and… oh hai Astro… let’s take a look at you.
● Why did I choose Astro?
● SolidJS Support
● I can try out different UI frameworks in Astro without going all-in
● I can bring in components from my other app and convert them one at a time without have to completely convert every component over at a time (some here are React, some are Solid, I’m using pragmas)
● Content-focused - fetch from a CMS or work locally with type-safe Markdown or MDX (which is the reason I want it)
● Content collections
● Type safety
● Why did I choose Astro?
● Astro was designed for building content-rich websites. And I zeroed in on blogs, portfolios… I don’t need a logged-in dashboard, or complex native app interactions that NextJS would give me, so this seems like a safe bet.
MDX support. I can add my MDX pages and move on.
It supports PostCSS by default, so my current CSS setup will port over without much fuss.
Astro Islands. These are interactive UI components on the page that render in isolation using partial/selective hydration
So I can import my React components from my Gatsby project. I can choose to convert them to Astro components over time, or leave them as React components.
● I can try out different frameworks, like SolidJS, Vue without having to fully commit to a framework.
● And share state between them.
That’s pretty cool. Astro also uses MPA and server-side rendering vs a client-side Single-page app, so it’s performant.
And the configs are much leaner. Check this out.
Here the Gatsby’s config on the left versus Astros config on the right
In the Astro config we have the site deploy url, markdown, integrations, image and build configs. All in a small list….
And the Gatsby config has all these PostCSS imports… configs… site metadata…
Plugins…
More plugins…
MORE plugins…
…to resolve…
The config keeps going…
And… Going.
And. Going.
And. Going.
Here’s the Gatsby.node file for creating nodes because I didn’t want to have my blog posts under the source folder, so I could be really fancy and smart.
● Look and me go… and add unnecessary complexity!
● I had to create all these nodes and do GraphQL queries to make the absolute paths to create the posts. YAY,,,
And a Gatsby browser file with this WrapRoot element so I could wrap styled components and pass them into MDX all at once for usage
Once I ported my components over to an Astro project there were some differences
[image] UnSplash — jonathan-kemper-f6RoUmj4iiM
● Here the Gatsby layout page on the left versus the Astro layout page on the right.
● In the layout.js file, we’re importing React components and a CSS modules file
● In the Layout.astro file, the components are now astro components, and we’re using a CSS file and the Astro pageTitle prop.
In the Gatsby layout, we’d use classnames and the useExtraClasses utility for style concatenation
And in the Gatsby layout we use the children prop, where in the Astro layout we now use slot
Now that the layout is set, time to mulch some content.
[image] UnSplash —gabriel-jimenez-jin4W1HqgL
● First, ditch those GraphQL queries, and add in Astro’s Content Collections
● Content collections are the best way to manage and author content in any Astro project. Collections help to organize your documents, validate your frontmatter, and provide automatic TypeScript type-safety for all of your content.
In Gatsby, I had this one query to grab images from a local folder. Literally 6 images.
This other one to grab images for my about page
Queries for my write page, and a query for my MDX posts to parse all the data into readable format. That’s a lot for a small site.
● In comparison, Astro’s Content Collections Added in: astro@2.0.0 is much simpler.
● It allows you to organize your documents, validate frontmatter, and provide content schema type-safety.
Along with content collections, you can dynamically generate routes…
● By creating this […slug].astro file and use the getCollection function from astro:content
and getStaticPaths functions to parse your data and pop it in your pages/posts folder.
● The getCollection function will grab your blog data, combined with the getStaticPaths function will map data for each of your posts.
● No more finagling post files. no more Gatsby CreatePage nonsense.
The other great thing about content collections is Type safety in your MDX with Zod
So what is Zod anyway?
The official definition is: TypeScript-first schema validation with static type inference. What that means is: Zod uses TS to create schemas to help you validate your data.
Now that your content is defined and validated, time to plant new starters. We need to pull in some Images.
Let’s use the new Images API
New Image assets was released as stable in Astro 3.0 replaces the original @astrojs/image integration
This API the allows you to import any any image from the src/assets folder, and if when you pop it in the source and add the required alt attribute… yay a11y!…
Astro generates this optimized images with the following attributes in the DOM for you
Oh boy… icons. This was fun… And time-consuming
First there was the whole Gatsby link conundrum
● I had a Link component, and wanted to leverage React Font Awesome for the a11y svg icon benefits, and got stuck for a week
● No matter what, Icon would break, couldn’t integrate the component
● Ended up refactoring to Link astro component and using astro-iconify and customizing icon svg imports, optimizing for a11y
To wrap up… here’s what I’ve learned from converting my site to Astro
Naturally there was tension between Big Lexus bows and kitten bows as I migrated my site to Astro
● _[…slug].css files load first because
● Markdown layout files load first because
● Base.css files load because
● We’re so clever with our main.css file yo and
● Now we’re overwriting something in our base styles
● Because we’re every-layout clever
https://every-layout.dev/layouts/stack/
● Also, astro files don’t like CSS modules
Netlify will pick up any stray YAML files during your build and if they don’t follow your schema… uh oh
Demo ViewTransition
Everything Everywhere at once… whew it was a challenge.
Complex card
Custom MDX components… in particular…
react-live doesn’t play well with custom components… yet
I want to give a huge shout out to a few people of the Astro core team and community that worked with me through my site conversion. Thank you, you are amazing!
Has your once-thriving digital garden become overgrown with weeds? Has your framework of choice changed from a suite of landscaping tools to a warehouse of industrial farming equipment? What if you’re three versions behind? Do you upgrade and continue with complexity, or choose a new stack that meets your static site needs?
This talk will teach you to weed out site complexity with Astro, SolidJS, and MDX. Pair this with accessibility best practices, and breathe new life into your digital garden.
The following resources were mentioned during the presentation or are useful additional information.
Here’s what was said about this presentation on social media.
Has your once-thriving digital garden become overgrown with weeds? Has your framework of choice changed from a suite of landscaping tools to a warehouse of industrial farming equipment? What if you're three versions behind? @resource11 will answer to all this and much more! 🙌😀
— ReactAlicante ⚛️🌞🥘 (@ReactAlicante) April 18, 2023
A quick trip through Madrid.., and now… @ReactAlicante! pic.twitter.com/bepHwsD82B
— Kathleen McMahon @ ReactAlicante 🇪🇸 (@resource11) September 29, 2023
Desde swag dulce hasta vista increíble, @ReactAlicante es mágico.
— Kathleen McMahon @ ReactAlicante 🇪🇸 (@resource11) September 29, 2023
From sweet swag to incredible views. React Alicante is magic. pic.twitter.com/1QyQnS7iz1
Cada vez que @debs_obrien presenta una charla sobre @playwrightweb, cada asiento ocupado. @ReactAlicante lo demuestra.
— Kathleen McMahon @ ReactAlicante 🇪🇸 (@resource11) September 29, 2023
Every time Deb O’Brien gives a talk on Playwright, it’s a full house. React Alicante proves this. pic.twitter.com/Y4vUY1N1KE
Es un día maravilloso para un charla @ReactAlicante, y la vista del Mediterráneo está tan bonito.
— Kathleen McMahon @ ReactAlicante 🇪🇸 (@resource11) September 30, 2023
It’s a marvelous day for a talk at React Alicante, and the Mediterranean views are so pretty. pic.twitter.com/cHa0UXqMRg
@resource11 talk about upgrading a blog theree major versions feels so personal.
— Neciu Dan (@neciudan) September 30, 2023
I am glad for @astrodotbuild making breaking changes almost painless. Went from v1 to v3 without many tears. pic.twitter.com/VqjCY2nsSE
@resource11 @ReactAlicante #reactalicante pic.twitter.com/Uvtzvp5Gf0
— Panayiotis Georgiou 🇪🇸 React Alicante (@panay_georgiou) September 30, 2023
@resource11 @ReactAlicante #reactalicante pic.twitter.com/1FGhk05iPz
— Panayiotis Georgiou 🇪🇸 React Alicante (@panay_georgiou) September 30, 2023
This! by @resource11 at @ReactAlicante pic.twitter.com/TF7LgGLTWP
— Dan Tamas (@dan_tamas) September 30, 2023
Love to see @resource11 showing some @astrodotbuild love at @ReactAlicante pic.twitter.com/ABTwJ3j7Sq
— Daniel Afonso (@danieljcafonso) September 30, 2023
Nice talk by @resource11 about how she updated her digital garden using @astrodotbuild @ReactAlicante pic.twitter.com/5zv6L8wMg3
— Facundo Giuliani (@facundozurdo) September 30, 2023
The only rhink I’d like to say after the @resource11 speech at @ReactAlicante is - thank you to get my mind in the right order 💜
— Sabina Psuj (@SabinaPsuj) September 30, 2023
The speech was awesome and you rock! #react #reactalicante pic.twitter.com/JZgVVpfxJo
Nothing is better post @ReactAlicante celebration than getting a shoutout by a speaker who you admire.
— Kathleen McMahon @ ReactAlicante 🇪🇸 (@resource11) September 30, 2023
Thanks, @facundozurdo! https://t.co/efKsfPPIL1
Día 2 y la audiencia está llena para las Charlas Relámpago en @ReactAlicante
— Kathleen McMahon @ ReactAlicante 🇪🇸 (@resource11) September 30, 2023
Day 2 and the audience is full for the Lightning Talks at React Alicante pic.twitter.com/TFnUcxCgAi
Offscreen: Kathleen seeks her backpack. Missing yet another speaker group photo. 🤣
— Kathleen McMahon @ ReactAlicante 🇪🇸 (@resource11) October 2, 2023
.@erikras presente no sólo habla de SolidJS, vive la Reactividad!
— Kathleen McMahon @ ReactAlicante 🇪🇸 (@resource11) October 2, 2023
Erik doesn’t just talk about SolidJD, he lives Reactivity!@ReactAlicante pic.twitter.com/3Tib9iQL6T
Summary 🇪🇸Part 3/4:
— Hatimeria (@hatimeria) October 2, 2023
We were treated to amazing speakers like Kathleen McMahon @resource11, Kevin Maes @kvmaes, @TejasKumar_, and Shivay Lamba @HowDevelop. Women debutants Adina Stoica @adinutzyc21 & Joana Santos @joanamcsa were fantastic! 👏#ReactAlicante pic.twitter.com/Izwh3ikN36
Mientras ordeno mis pensamientos sobre @ReactAlicante, ¡es hora de viajar de regreso a Madrid!
— Kathleen McMahon @ ReactAlicante 🇪🇸 (@resource11) October 3, 2023
As I gather my thoughts anout React Alicante, it’s time to travel back to Madrid! pic.twitter.com/F0yvl1nmbd