Docusaurus Versioning
Tags: versioning, documentation, devrel, docusaurus
Published: 2023-03-03 22:30:05

 [For reasons](https://dev.to/vanigami/from-docsify-to-docusaurus-21o5), I’m switching GraphGrid’s docs site from Docsify to Docusaurus. During this process I’m taking the opportunity to improve the site architecture. After getting the v1.4 docs building with Docusaurus, I had to start thinking about how I was going to pull in v2.0. I was anxious to implement the Docusaurus versioning CLI, because it relieves pain-points on both the development and user side. 

GG has two versions 1.4 and 2.0. With the old site (the Docsify one), I maintained two separate branches (1.4 and 2.0). You can imagine that these separate branches often got out of sync, and when they were finally merged, there’s a conflict list longer than a CVS receipt. From an architectural standpoint, the old site did not provide an intuitive way to switch between versions. For example, to switch from the 1.4 to the 2.0 docs, the user had to edit the version path in the URL. Users also didn’t have any clear indication of what version of the docs they were on.  

  With Docusaurus versioning, we’re not able to maintain the docs version under 1 branch by combining the two versions (1.4 and 2.0).  Now each version is updated synchronously, no more getting behind or merge conflicts! Docusaurus allows you to configure the versioning behavior.  

## Getting around default current docs version directory 

  By default, Docusaurus creates a directory for your project’s current version. For my use case it didn’t make sense to use the current version because we don’t publish pre-release docs.

![docusaurus_versioning_table](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/lrtr8z2kqzs71lts7du0.png)


![docusaurus_tip](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/tbgyx530y2qwyah3szmt.png)

  Because the current version is baked in, I had to figure out how to _un-bake_ it (_unbaking_ is a term I just made up that means deconstructing a feature in order to construct another).  This has been the most custom config I’ve had to do thus far because of a Docusaurus feature. I’m not complaining but  R.I.P. github issue #1243.  
If you’re trying to use Docusaurus versioning without `/doc /next/` (“current version” or pre-release docs), you’re going to have to do some configuring.    

  Docusaurus suggests two versioning behavior patterns. You should use the 1st pattern if you want to publish prerelease docs. I used pattern 2 which outlines the necessary plugin options to use to achieve _unbakening_. 

## Unbake  🍪 

  Within the docs-plugin preset config I used `lastVersion` and set it to `current`. This combines the current version and the major version (this includes all default routes). This is the recipe to follow for those looking to not include the default current docs versioning template. No more “Next” in the dropdown, and no more routing nightmares!

## Presentation 
  
  Now that we baked the site how WE want it, it's time to make it pretty. In the same configuration, I defined the label for the now combined current and major release version. This value will be used in the UI components like the navBar items. I set the path as root because I want this version to (2.0) to be the main docs. 

```
docs {
	lastVersion: 'current',
	versions: {
		current: {
			label: '2.0',
			path: '/',
			badge: true
		}
	}
}
```

  I added a version number badge, which isn't necessary but I like having a clear version indicator to prevent confusion.

## Version NavBar

    Next I added navbar items to improve the user experience. I added an item called `docsVersionDropdown` which adds a version drop down.


![version_dropdown](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6c9pv6s01to8eeinkebs.png)

```
{
	type: 'docsVersionDropdown',
	position: 'left',
	dropdownActiveClassDisabled: true,
}
```
For more info and configuration options check out Docusaurus’s versioning docs! 

Checkout out [my blog](https://vpuzakulics.myportfolio.com/docusaurus-versioning) for a demo video!