Migrating from v1 to v2
caution
This migration guide is targeted at Docusaurus users without translation and/or versioning features.
This doc guides you through migrating an existing Docusaurus 1 site to Docusaurus 2. Your Docusaurus 1 site should have the following structure:
Project setup
package.json
Scoped package names
In Docusaurus 2, we use scoped package names:
docusaurus
->@docusaurus/core
This provides a clear distinction between Docusaurus' official packages and community maintained packages. In another words, all Docusaurus' official packages are namespaced under @docusaurus/
.
Meanwhile, the default doc site functionalities provided by Docusaurus 1 are now provided by @docusaurus/preset-classic
. Therefore, we need to add this dependency as well:
tip
Please use the most recent Docusaurus 2 alpha version, which you can check out here (it's tagged next
).
CLI commands
Meanwhile, CLI commands are renamed to docusaurus <command>
(instead of docusaurus-command
).
The "scripts"
section of your package.json
should be updated as follows:
A typical Docusaurus 2 package.json
may look like this:
build
directory
Update references to the In Docusaurus 1, all the build artifacts are located within website/build/<PROJECT_NAME>
. However, in Docusaurus 2, it is now moved to just website/build
. Make sure that you update your deployment configuration to read the generated files from the correct build
directory.
If you are deploying to GitHub pages, make sure to run yarn deploy
instead of yarn publish-gh-pages
script.
.gitignore
The .gitignore
in your website
should contain:
Site configurations
docusaurus.config.js
Rename siteConfig.js
to docusaurus.config.js
. In Docusaurus 2, we split each functionality (blog, docs, pages) into plugins for modularity. Presets are bundles of plugins and for backward compatibility we built a @docusaurus/preset-classic
preset which bundles most of the essential plugins present in Docusaurus 1.
Add the following preset configuration to your docusaurus.config.js
.
We recommend moving the docs
folder into the website
folder and that is also the default directory structure in v2. Now supports Docusaurus project deployments out-of-the-box if the docs
directory is within the website
. It is also generally better for the docs to be within the website so that the docs and the rest of the website code are co-located within one website
directory.
Refer to migration guide below for each field in siteConfig.js
.
Updated fields
baseUrl
, tagline
, title
, url
, favicon
, organizationName
, projectName
, githubHost
, scripts
, stylesheets
No actions needed.
colors
Deprecated. We wrote a custom CSS framework for Docusaurus 2 called Infima which uses CSS variables for theming. The docs are not quite ready yet and we will update here when it is. To overwrite Infima's CSS variables, create your own CSS file (e.g. ./src/css/custom.css
) and import it globally by passing it as an option to @docusaurus/preset-classic
:
Infima uses 7 shades of each color.
We recommend using ColorBox to find the different shades of colors for your chosen primary color.
Alteratively, use the following tool to generate the different shades for your website and copy the variables into src/css/custom.css
.
CSS Variable Name | Hex | Adjustment |
---|---|---|
--ifm-color-primary-lightest | #80aaef | |
--ifm-color-primary-lighter | #5a91ea | |
--ifm-color-primary-light | #4e89e8 | |
--ifm-color-primary | #3578e5 | 0 |
--ifm-color-primary-dark | #1d68e1 | |
--ifm-color-primary-darker | #1b62d4 | |
--ifm-color-primary-darkest | #1751af |
Replace the variables in src/css/custom.css
with these new variables.
footerIcon
, copyright
, ogImage
, twitterImage
, docsSideNavCollapsible
Site meta info such as assets, SEO, copyright info are now handled by themes. To customize them, use the themeConfig
field in your docusaurus.config.js
:
headerIcon
, headerLinks
In Docusaurus 1, header icon and header links were root fields in siteConfig
:
Now, these two fields are both handled by the theme:
algolia
blogSidebarCount
Deprecated. Pass it as a blog option to @docusaurus/preset-classic
instead:
cname
Deprecated. Create a CNAME
file in your static
folder instead with your custom domain. Files in the static
folder will be copied into the root of the build
folder during execution of the build command.
customDocsPath
, docsUrl
, editUrl
, enableUpdateBy
, enableUpdateTime
BREAKING: editUrl
should point to (website) docusaurus project instead of docs
directory.
Deprecated. Pass it as an option to @docusaurus/preset-classic
docs instead:
gaTrackingId
gaGtag
Removed fields
The following fields are all deprecated, you may remove from your configuration file.
blogSidebarTitle
cleanUrl
- Clean URL is used by default now.defaultVersionShown
- Versioning is not ported yet. You'd be unable to migration to Docusaurus 2 if you are using versioning. Stay tuned.disableHeaderTitle
disableTitleTagline
docsSideNavCollapsible
is available atthemeConfig.sidebarCollapsible
, and this is turned on by default now.facebookAppId
facebookComments
facebookPixelId
fonts
highlight
- We now use Prism instead of highlight.js.markdownOptions
- We use MDX in v2 instead of Remarkable. Your markdown options have to be converted to Remark/Rehype plugins.markdownPlugins
- We use MDX in v2 instead of Remarkable. Your markdown plugins have to be converted to Remark/Rehype plugins.manifest
noIndex
onPageNav
- This is turned on by default now.separateCss
- It can imported in the same manner ascustom.css
mentioned above.scrollToTop
scrollToTopOptions
translationRecruitingLink
twitter
twitterUsername
useEnglishUrl
users
usePrism
- We now use Prism instead of highlight.jswrapPagesHTML
We intend to implement many of the deprecated config fields as plugins in future. Help will be appreciated!
Components
Sidebar
In previous version, nested sidebar category is not allowed and sidebar category can only contain doc id. However, v2 allows infinite nested sidebar and we have many types of Sidebar Item other than document.
You'll have to migrate your sidebar if it contains category type. Rename subcategory
to category
and ids
to items
.
Footer
website/core/Footer.js
is no longer needed. If you want to modify the default footer provided by Docusaurus, swizzle it:
- npm
- Yarn
This will copy the current <Footer />
component used by the theme to a src/theme/Footer
directory under the root of your site, you may then edit this component for customization.
Pages
Please refer to creating pages to learn how Docusaurus 2 pages work. After reading that, notice that you have to move pages/en
files in v1 to src/pages
instead.
CompLibrary
is deprecated in v2, so you have to write your own React component or use Infima styles (Docs will be available soon, sorry about that! In the meanwhile, inspect the V2 website or view https://facebookincubator.github.io/infima/ to see what styles are available).
The following code could be helpful for migration of various pages:
- Index page - Flux (recommended), Docusaurus 2, Hermes
- Help/Support page - Docusaurus 2, Flux
Content
Remove AUTOGENERATED_TABLE_OF_CONTENTS
This feature is deprecated. You may read more about it in this issue. If you need the feature, use remark-toc instead and pass it to docs plugin's remarkPlugins
option.
Update Markdown syntax to be MDX-compatible
In Docusaurus 2, the markdown syntax has been changed to MDX. Hence there might be some broken syntax in the existing docs which you would have to update. A common example is self-closing tags like <img>
and <br>
which are valid in HTML would have to be explicitly closed now ( <img/>
and <br/>
). All tags in MDX documents have to be valid JSX.
Tips: You might want to use some online tools like HTML to JSX to make the migration easier.
Language-specific code tabs
Refer to the multi-language support code blocks section.
Front matter
The Docusaurus front matter fields for the blog have been changed from camelCase to snake_case to be consistent with the docs.
The fields authorFBID
and authorTwitter
have been deprecated. They are only used for generating the profile image of the author which can be done via the author_image_url
field.
Test your site
After migration, your folder structure should look like this:
Start the development server and fix any errors:
Example migration PRs
You might want to refer to our migration PRs for Create React App and Flux as examples of how a migration for a basic Docusaurus v1 site can be done.
Support
For any questions, you can ask in the #docusaurus-1-to-2-migration
Discord channel. Feel free to tag @yangshun in any migration PRs if you would like us to have a look.
Versioned Site
caution
The versioning feature is a work in progress! Although we've implemented docs versioning since 2.0.0-alpha.37
, we'd like to test it out for v2 users first before we recommend v1 users to migrate to v2. There are some changes in how v2 versioning works compared to v1. In the future, we might create a script to migrate your versioned docs easier. However, if you are adventurous enough to manually migrate, feel free to do so. Be warned though, the manual migration requires lot of work.
Changes from v1
Read up https://v2.docusaurus.io/blog/2018/09/11/Towards-Docusaurus-2#versioning first for problems in v1's approach.
versioned_docs
front matter
Migrate your Unlike v1, The markdown header for each versioned doc is no longer altered by using version-${version}-${original_id}
as the value for the actual id field. See scenario below for better explanation.
For example, if you have a docs/hello.md
.
When you cut a new version 1.0.0, in Docusaurus v1, website/versioned_docs/version-1.0.0/hello.md
looks like this:
In comparison, Docusaurus 2 website/versioned_docs/version-1.0.0/hello.md
looks like this (exactly same as original)
Since we're going for snapshot and allow people to move (and edit) docs easily inside version. The id
frontmatter is no longer altered and will remain the same. Internally, it is set as version-${version}/${id}
.
Essentially, here are the necessary changes in each versioned_docs file:
versioned_sidebars
Migrate your - Refer to
versioned_docs
id asversion-${version}/${id}
(v2) instead ofversion-${version}-${original_id}
(v1).
Because in v1 there is a good chance someone created a new file with front matter id "version-${version}-${id}"
that can conflict with versioned_docs
id.
For example, Docusaurus 1 can't differentiate docs/xxx.md
vs website/versioned_docs/version-1.0.0/hello.md
Since we don't allow /
in v1 & v2 for frontmatter, conflicts are less likely to occur.
So v1 users need to migrate their versioned_sidebars file
Example versioned_sidebars/version-1.0.0-sidebars.json
:
versioned_sidebars
and versioned_docs
Populate your In v2, we use snapshot approach for documentation versioning. Every versioned docs does not depends on other version. It is possible to have foo.md
in version-1.0.0
but it doesn't exist in version-1.2.0
. This is not possible in previous version due to Docusaurus v1 fallback functionality (https://docusaurus.io/docs/en/versioning#fallback-functionality).
For example, if your versions.json
looks like this in v1
Docusaurus v1 creates versioned docs if and only if the doc content is different. Your docs structure might look like this if the only doc changed from v1.0.0 to v1.1.0 is hello.md
.
In v2, you have to populate the missing versioned_docs
and versioned_sidebars
(with the right frontmatter and id reference too).
Convert style attributes to style objects in MDX
Docusaurus 2 uses JSX for doc files. If you have any style attributes in your Docusaurus 1 docs, convert them to style objects, like this: