Building a Developer-friendly Documentation Portal with Next.js and MDX
My goal was to create a documentation portal that's easy to maintain and update, with documentation files kept closely to the code base and versionable for merge-request lifecycles. Seamless integration was a must-have for me, which is why I made sure our documentation portal supports source files from different repositories using GitLab API. And of course, I needed to make sure plain Markdown was correctly displayed on both GitLab and GitHub.
But I didn't stop there. I also wanted to provide support for specific functionalities and features that we discussed in preparation stage.
So how did I do it? In this blog post, I'll walk you through how I used Next.js and Next MDX Remote to build the evitadb.io documentation portal that met all of these requirements.
Why I've chosen Next.JS + MDX
One of the features of Next.js is the way it renders on the server side and client side. That’s crucial for the single page applications (SPAs) it builds, and how it helps those SPAs have much-improved success in terms of SEO (search engine optimization).
On top of that we knew that Next.js has other positives like:
- Excellent performance in terms of load times
- Load times helped with “lazy loading” and automatic code splitting
- Great support for developers
- Fantastic user-experience
- Faster time to market
- Great SEO
Gitlab/Github API
Later, decision has been made to move repository where all documentation files are located to Github and adjusting to that was only matter of tweeking the actual request according to Github API guide.
Here is an example of URL outsourcing the data from Gitlab:
Important attributes for us were:
- id - option to switch between repositories if necessary.
- file_path - URL-encoded full path to the file, such as lib%2Fclass%2test.md.
- raw - we needed RAW content.
- ref - branch to source from.
And here is the example of helper function I've used to get my hands on the file content.
With data available I could now start processing them.
Navigating through Documentation
So, at the heart of our documentation portal, the structure is similar to this:
Custom Components
I knew that basic Markdown just wouldn't cut it. With added support for Custom Components in our documentation files, the possibilities were endless. As developers started plugging in more content, we couldn't help but come up with features to enhance the reader's experience.
There are many libraries packed with components to suit our needs, and with many, we took inspiration from elsewhere and tweaked them as necessary. However, some features and components were built from the ground up to suit our needs.
In the next post, I will sum up the core functionalities of some more advanced features we used on our Developers Portal. For example, how we optimised our Components to be "transient" with plain Markdown, Gitlab/Github routing and display.