We recently launch the site for Octahedroid, the agency I co-founded together with Omar Aguirre and Jorge Valdez. For our agency site we are using Drupal as a Decoupled CMS and Gatsby as frontend strategy.
For my personal blog I decided to simplify this and remove the Drupal backend part and use markdown files but including support for JSX components.
This is not the first time our team work in Gatsby and MDX projects. We did an implementation in the past using this technology for one of our clients Pantheon you can take a look to the following image to see this, and click to it, to visit their documentation pages.
Why MDX
MDX is an authorable format that lets you seamlessly write JSX in your Markdown documents.
As mentioned above we built the company site using Gatsby, but not only that we created the site using the amazing Theme-UI project and implemeting a Gatsby theme containing the React components. Therefore we decided to reuse those components in the MDX blog implementation and only extract and migrate content from Drupal to MDX files.
The main repo was done implementing a monorepo approach and it was organized in the packages and starters directories.
The packages directory
The packages directory contains the presentation theme gatsby-theme-octahedroid with the reusable JSX components, and the data layer themes gatsby-theme-octahedroid-drupal and gatsby-theme-octahedroid-markdown with the Drupal and MDX implementations.
The starters directory
The starters are very basic gatsby projects implementing the data layer themes.
How basic it was the starter implementation?. I will list files and content to ilustrate this.
The package.json file
The gatsby-config.js file
The content directories
The files implementing custom features (Theme Shadowing)
Migrating content from Drupal to Markdown files
The only Drupal task here it was to enable the GraphQL module (yes the site was a few years old and it was still using JSON:API).
The GraphQL query
Since the site has been inactive more than a year ago, it was no Drupal site on production, only an instance running on my local machine. So instead of deploying a Drupal site to production, the decision we took was to install the GraphQL module and execute a GraphQL query to extract the node pages information and copy/paste to a gist file.
The Javascript code
For the file creation process we decided to use this simple Javascript code, instead of PHP to iterate and resolve this task faster.
Wrapping up
Migrating content and implementing the blog using MDX it was easier than we expected because of:
Reusing our previously created JSX components and extending the presentation theme gatsby-theme-octahedroid save us a lot of time.
Using Javascript to generate the MDX files instead of custom PHP code it was faster to code and try.
Copying the GraphQL query result to a gist file instead of deploying the full Drupal site save a lot of time since there was no need to setup or configure anything.
Copying image assets directly to the repository was faster than code an export or import process.
Yes, implementing the simplest solutions for the tasks and reusing what we have done already make us faster, efficient and productive.
Big shout to our youngest Octahedroid team member Carlos Dinarte for taking care and executing all this work.
Ready to embrace the JAMstack revolution?
Build fast and secure sites and apps delivered by pre-rendering files and serving them directly from a CDN, removing the requirement to manage or run web servers, databases and worry about traffic spikes.