<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/"
    xmlns:atom="http://www.w3.org/2005/Atom" xmlns:media="http://search.yahoo.com/mrss/" version="2.0">
    <channel>
        
        <title>
            <![CDATA[ docusaurus - freeCodeCamp.org ]]>
        </title>
        <description>
            <![CDATA[ Browse thousands of programming tutorials written by experts. Learn Web Development, Data Science, DevOps, Security, and get developer career advice. ]]>
        </description>
        <link>https://www.freecodecamp.org/news/</link>
        <image>
            <url>https://cdn.freecodecamp.org/universal/favicons/favicon.png</url>
            <title>
                <![CDATA[ docusaurus - freeCodeCamp.org ]]>
            </title>
            <link>https://www.freecodecamp.org/news/</link>
        </image>
        <generator>Eleventy</generator>
        <lastBuildDate>Tue, 05 May 2026 19:58:37 +0000</lastBuildDate>
        <atom:link href="https://www.freecodecamp.org/news/tag/docusaurus/rss.xml" rel="self" type="application/rss+xml" />
        <ttl>60</ttl>
        
            <item>
                <title>
                    <![CDATA[ How to Set Up Documentation as Code with Docusaurus and GitHub Actions ]]>
                </title>
                <description>
                    <![CDATA[ For technical writers, keeping documentation up to date manually can be really frustrating. Issues like outdated guides, broken links, and missing updates are a pain, and they can make writers less productive. These issues can also make it harder for... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/set-up-docs-as-code-with-docusaurus-and-github-actions/</link>
                <guid isPermaLink="false">67a39f467e716749ae8c7b7e</guid>
                
                    <category>
                        <![CDATA[ documentation ]]>
                    </category>
                
                    <category>
                        <![CDATA[ docs-as-code ]]>
                    </category>
                
                    <category>
                        <![CDATA[ docusaurus ]]>
                    </category>
                
                    <category>
                        <![CDATA[ GitHub ]]>
                    </category>
                
                    <category>
                        <![CDATA[ github-actions ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ EZINNE ANNE EMILIA ]]>
                </dc:creator>
                <pubDate>Wed, 05 Feb 2025 17:26:30 +0000</pubDate>
                <media:content url="https://cdn.hashnode.com/res/hashnode/image/upload/v1738248926082/9a2a6855-00d4-4e25-a8bd-c1d645f21de5.png" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>For technical writers, keeping documentation up to date manually can be really frustrating. Issues like outdated guides, broken links, and missing updates are a pain, and they can make writers less productive. These issues can also make it harder for people to effectively use the docs and get correct information.</p>
<p>Documentation as code, or docs as code, is an approach to managing documentation that treats the docs like a codebase. It lets you version, automatically update, and review your docs just like you would do in a codebase. Docs as code helps you make sure that your docs are up to date and that users can gain access to accurate information.</p>
<p>This tutorial will show you how to:</p>
<ul>
<li><p>Create a documentation website using Docusaurus.</p>
</li>
<li><p>Track changes with Git and GitHub.</p>
</li>
<li><p>Build and deploy it to a hosting platform.</p>
</li>
<li><p>Set up a workflow to perform grammatical reviews using GitHub Actions before you merge your changes.</p>
</li>
</ul>
<h2 id="heading-prerequisites">Prerequisites</h2>
<p>This tutorial is beginner-friendly, but there are some tools you’ll need to have or know in order to follow along:</p>
<ul>
<li><p><a target="_blank" href="https://code.visualstudio.com/download">VSCode IDE (or other IDE of your choice)</a>.</p>
</li>
<li><p><a target="_blank" href="https://docs.npmjs.com/downloading-and-installing-node-js-and-npm">Node.js and npm installed.</a></p>
</li>
<li><p><a target="_blank" href="https://github.com/">A GitHub account.</a></p>
</li>
<li><p><a target="_blank" href="https://www.freecodecamp.org/news/gitting-things-done-book/">A reasonable knowledge of how to use Git and GitHub.</a></p>
</li>
</ul>
<h2 id="heading-why-do-technical-writers-use-docs-as-code">Why Do Technical Writers Use Docs as Code?</h2>
<p>Before we dive in, let’s quickly talk about what "docs as code" is and why it matters. Back in 2015, two technical writers at Google came up with the idea to make it easier for developers to contribute to documentation and to better organize their company documents. There were times when they needed to write about an application they were working on, but things were really disorganized. So they came up with this process. Since then, many companies have adopted the approach.</p>
<p>Docs as code is now a popular approach to managing documentation, and it’s supported by many tools that are designed to treat documentation like code. Tom Johnson explains this concept in more detail in <a target="_blank" href="https://idratherbewriting.com/learnapidoc/pubapis_docs_as_code.html">his article on docs as code</a>.</p>
<p>Traditional documentation relies on Word documents and PDFs, where changes are tracked manually or through document revision history. Writers must update and publish content manually, with no way to automate routine tasks.</p>
<p>On the other hand, docs as code borrows principles and tools from software development to make documentation more structured, versioned, and automated. The documentation is stored in version control (like Git), written in lightweight markup languages, and gets updated alongside the code.</p>
<p>This approach ensures that documentation evolves alongside the software, maintains high quality, and allows for efficient collaboration, just like writing code.</p>
<h3 id="heading-tools-well-use-in-this-tutorial">Tools We’ll Use in This Tutorial</h3>
<p>Let’s review the main tools we’ll be using for this tutorial:</p>
<ol>
<li><p>Docusaurus is a tool created by Facebook for creating documentation websites. It supports markdown and mdx. It also supports versioning and custom themes, making it easy to create user-friendly and professional docs.</p>
</li>
<li><p>Vale is a customizable style and grammar checker for writers. It ensures consistent language, tone, and style across technical documents. There are other good linters you could use for review apart from Vale, but that’s what we’ll be using here.</p>
</li>
<li><p>GitHub Actions: A CI/CD tool for automating workflows directly in GitHub. It helps you test, build, and deploy code with ease.</p>
</li>
</ol>
<h2 id="heading-step-1-install-docusaurus">Step 1: Install Docusaurus</h2>
<p>Open your command line terminal and enter the following:</p>
<pre><code class="lang-javascript">npx create-docusaurus@latest docs-<span class="hljs-keyword">as</span>-code-tutorial classic
</code></pre>
<p><code>docs-as-code-tutorial</code> is the name I am using for the site. You can replace it with any other site name if you wish. Select JavaScript as the language you want to use. This will begin to create a new Docusaurus site. After running the code, you’ll see the <code>docs-as-code-tutorial</code> folder in your VSCode workspace. Navigate to the folder.</p>
<p>Next, start the development server so you can see your docs.</p>
<pre><code class="lang-javascript">cd docs-<span class="hljs-keyword">as</span>-code-tutorial
npm start
</code></pre>
<p>With this, the site will start running at <code>localhost:3000</code>.</p>
<p>When you view the site, you’ll see pre-generated content. So, in the next step, you’ll to create a repository and link the local folder to your remote repository.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1737868185569/0cf96b6c-770a-4965-b017-1fe54796c673.png" alt="the docusaurus homepage" class="image--center mx-auto" width="600" height="400" loading="lazy"></p>
<h2 id="heading-step-2-create-a-repository">Step 2: Create a Repository</h2>
<p>Now, you need to create a repository for the <code>docs-as-code-tutorial</code>. So go to your GitHub account and create a new repository.</p>
<p>After creating the repository, you’ll need to link the repository to the folder in your VSCode workspace.</p>
<p>Open a new terminal and run these commands:</p>
<pre><code class="lang-javascript">git init
git add .
git commit -m <span class="hljs-string">"first commit"</span>
git branch -M main
git remote add origin https:<span class="hljs-comment">//github.com/myname/docs-as-code-tutorial.git</span>
git push -u origin main
</code></pre>
<p>With that, you have linked the repository, and Git will start tracking your changes.</p>
<h2 id="heading-step-3-customize-your-docs-in-the-docusaurusconfig-file">Step 3: Customize your Docs in the <code>docusaurus.config</code> File</h2>
<p>Before you begin customizing, create a branch where you can make your changes as you push it to the main branch.</p>
<pre><code class="lang-powershell">git checkout <span class="hljs-literal">-b</span> <span class="hljs-string">"new_branch"</span>
</code></pre>
<p>The <code>docusaurus.config.js</code> file is where you can make most of the edits to your site. Change the <code>title</code> property to <code>Docs as code</code>.</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">const</span> config = {
  <span class="hljs-attr">title</span>: <span class="hljs-string">'Docs as code'</span>,
  <span class="hljs-attr">tagline</span>: <span class="hljs-string">'Documentation as code'</span>,
<span class="hljs-comment">//rest of your code</span>
   <span class="hljs-attr">navbar</span>: {
        <span class="hljs-attr">title</span>: <span class="hljs-string">'Docs as code'</span>,
<span class="hljs-comment">//rest of your code</span>
  }
}
</code></pre>
<p>That will show as the new title when you preview the docs. This is simply an illustration to display how Docusaurus works. You can further customize the site to your desired style, but we won’t go into more detail on that here (as the main purpose of this tutorial is to show how to set up your docs as code).</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1737869529640/c4dab104-9f8b-4dad-a3a5-250d15d4552d.png" alt="c4dab104-9f8b-4dad-a3a5-250d15d4552d" class="image--center mx-auto" width="600" height="400" loading="lazy"></p>
<p>After making the changes, the site should look a bit different.</p>
<p>You can push the changes now.</p>
<pre><code class="lang-powershell">git commit <span class="hljs-literal">-am</span> <span class="hljs-string">"first commit"</span>
git push -<span class="hljs-literal">-set</span><span class="hljs-literal">-upstream</span> origin new_branch
</code></pre>
<h2 id="heading-step-4-edit-your-docs">Step 4: Edit Your Docs</h2>
<p>For this tutorial, I’ll be making edits in the <code>docs</code> section. Go to <code>intro.md</code> and replace the markdown text with this writeup:</p>
<pre><code class="lang-markdown"><span class="hljs-section"># How to set up docs-as-code</span>

Documentation-as-code is a great means to push changes made in your local machine to your docs live site. To accomplish this, you need an IDE, a static site generator, a Git repository, CI/CD to set up workflows, and a hosting platform. 

<span class="hljs-section">## Why do technical writers do docs-as-code?</span>

Documentation-as-code is a great means to push changes made in your local machine to your docs live site. To accomplish this, you need an IDE, a static site generator, a Git repository, CI/CD to set up workflows, and a hosting platform.
</code></pre>
<p>After making the edits, preview your docs.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1737870301247/dba83233-a11c-4ec0-aeaf-b11e525ca090.png" alt="intro.md displaying the writeup " class="image--center mx-auto" width="600" height="400" loading="lazy"></p>
<h2 id="heading-step-5-add-the-linting-feature">Step 5: Add the Linting Feature</h2>
<p>Add the Vale linter to your docs to review errors. To do that, install the Vale CLI with any of these commands.</p>
<ul>
<li><p>Run <code>choco install vale</code> for Windows</p>
</li>
<li><p><code>brew install vale</code> for MacOs, or</p>
</li>
<li><p><code>snap install vale</code> for Linux</p>
</li>
</ul>
<h3 id="heading-how-to-set-up-vale"><strong>How to set up Vale</strong></h3>
<p>As I mentioned earlier, Vale is a customizable style and grammer checking tool. This means you can set it up to review your docs exactly how you want.</p>
<p>Vale uses the Vale style guide when performing reviews to spot errors and make suggestions. But you can add your company’s style guide or any other style guide to it if you prefer. There are public style guides you can use like the Google style guide, Microsoft style guide, and so on. For this tutorial, we’ll be using the Microsoft style guide.</p>
<p>If you don’t already have it, you’ll need to <a target="_blank" href="https://github.com/errata-ai/Microsoft/releases/download/v0.7.0/Microsoft.zip">get the Microsoft style guide</a>, download it, and unzip it. Create a styles folder and move the Microsoft folder to the styles folder.</p>
<p>This should be your file path:</p>
<pre><code class="lang-javascript">- docs-<span class="hljs-keyword">as</span>-code-tutorial
  <span class="hljs-comment">//other folders</span>
  - styles
    - Microsoft
  <span class="hljs-comment">//other folders</span>
</code></pre>
<p>In your docs, create a <code>.vale.ini</code> file and add it to your root. </p>
<p>Add this code in it:</p>
<pre><code class="lang-plaintext">StylesPath = styles

MinAlertLevel = suggestion

[*.md]

BasedOnStyles = Vale, Microsoft
</code></pre>
<p>Let’s understand what’s going on here:</p>
<ul>
<li><p>The <code>StylesPath</code> is set to the styles folder where you added the Microsoft style guide you downloaded. The MinAlertLevel sets Vale alerts to <code>suggestion</code> – this means that Vale will highlight suggestions, warnings, and errors found in your docs. If the MinAlertLevel is set to errors, then Vale will highlight errors only. If set to warnings, then it’ll highlight warnings and errors (and so on).</p>
</li>
<li><p><code>[*.md]</code> tells Vale to go through <code>.md</code> files only.</p>
</li>
<li><p><code>BasedOnStyles</code> indicates which style guide you are using for the linting. In this case, it’s the Microsoft style guide and Vale style guide. So when the linter is running, it will highlight suggestions, warnings, and errors using the specified style guides.</p>
</li>
</ul>
<p>To test your docs, run <code>vale intro.md</code> (assuming you still have the <code>intro.md</code> file).</p>
<p>This should be the output:</p>
<pre><code class="lang-plaintext">✔ 0 errors, 0 warnings and 0 suggestions in stdin.
</code></pre>
<h2 id="heading-step-6-build-the-site">Step 6: Build the Site</h2>
<p>To do this, run <code>npm run build</code>. After that, you can preview the build with <code>npm run serve</code>.</p>
<h2 id="heading-step-7-deploy-the-site">Step 7: Deploy the Site</h2>
<p>There are different hosting platforms where you can host your live site. This tutorial covers two hosting options: GitHub Pages and Netlify.</p>
<h3 id="heading-deploy-with-github-pages"><strong>Deploy with GitHub Pages</strong></h3>
<p>To deploy to GitHub Pages, you’ll need to set your repository name and GitHub username/organization name in the <code>docusauraus.config.js</code> file.</p>
<pre><code class="lang-javascript"><span class="hljs-comment">// Set the production url of your site here</span>

  <span class="hljs-attr">url</span>: <span class="hljs-string">'https://ezinneanne.github.io/'</span>,

  <span class="hljs-comment">// Set the /&lt;baseUrl&gt;/ pathname under which your site is served</span>

  <span class="hljs-comment">// For GitHub pages deployment, it is often '/&lt;projectName&gt;/'</span>

  <span class="hljs-attr">baseUrl</span>: <span class="hljs-string">'/docs-as-code-tutorial/'</span>,

  <span class="hljs-comment">// GitHub pages deployment config.</span>

  <span class="hljs-comment">// If you aren't using GitHub pages, you don't need these.</span>

  <span class="hljs-attr">organizationName</span>: <span class="hljs-string">'ezinneanne'</span>, <span class="hljs-comment">// Usually your GitHub org/user name.</span>

  <span class="hljs-attr">projectName</span>: <span class="hljs-string">'docs-as-code-tutorial'</span>, <span class="hljs-comment">// Usually your repo name.</span>
</code></pre>
<p>You can deploy the site to GitHub Pages in the following ways:</p>
<ul>
<li><p>Using the Powershell terminal with this command:</p>
<p>  <code>cmd /C 'set "GIT_USER=&lt;GITHUB_USERNAME&gt;" &amp;&amp; yarn deploy'</code> </p>
</li>
<li><p>Using the Windows Command line terminal with this command:</p>
<p>  <code>cmd /C "set "GIT_USER=&lt;GITHUB_USERNAME&gt;" &amp;&amp; yarn deploy"</code></p>
</li>
<li><p>Using Bash with this command:<br>  <code>GIT_USER=&lt;GITHUB_USERNAME&gt; yarn deploy</code></p>
</li>
</ul>
<p>Just make sure you replace <code>&lt;GITHUB_USERNAME&gt;</code> with your username on GitHub.</p>
<p>Voilà! The site is deployed at <a target="_blank" href="https://ezinneanne.github.io/docs-as-code-tutorial/">https://ezinneanne.github.io/docs-as-code-tutorial/</a>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1737918709225/3eb12747-4a13-4c17-a7ad-ab6ee84b64ff.png" alt="the docs-as-code homepage deployed on Github Pages" class="image--center mx-auto" width="600" height="400" loading="lazy"></p>
<h3 id="heading-deploy-with-netlify"><strong>Deploy with Netlify</strong></h3>
<p>To deploy to Netlify, you only need the production URL and base URL:</p>
<pre><code class="lang-javascript"><span class="hljs-comment">// Set the production url of your site here</span>

  <span class="hljs-attr">url</span>: <span class="hljs-string">'https://docs-as-code-tutorial.netlify.app'</span>,

  <span class="hljs-attr">baseUrl</span>: <span class="hljs-string">'/'</span>,
</code></pre>
<ol>
<li><p>Go to your <a target="_blank" href="https://www.netlify.com/">Netlify account</a> and link your repository.</p>
</li>
<li><p>Click on <code>Add new site</code>.</p>
</li>
<li><p>Click on <code>import an existing project</code>.</p>
</li>
<li><p>Connect to your GitHub account and select the <code>docs-as-code-tutorial</code> repository.</p>
</li>
<li><p>Give your site a name, it should be the same as the URL in your <code>docusaurus.config.js</code>.</p>
</li>
<li><p>Add the publish directory which is <code>build</code> and the build command which is <code>npm run build</code>. Then Netlify will deploy to your default branch <code>main</code>, unless you specify otherwise.</p>
</li>
<li><p>Finally, deploy!</p>
</li>
</ol>
<p>You should see the site running at <a target="_blank" href="https://docs-as-code-tutorial.netlify.app/">https://docs-as-code-tutorial.netlify.app/</a>.</p>
<p>For other deployment options, <a target="_blank" href="https://docs-as-code-tutorial.netlify.app/">you can</a> <a target="_blank" href="https://docusaurus.io/docs/deployment">check out the Docusauraus documentation</a>.</p>
<h2 id="heading-step-8-set-up-a-documentation-workflow-using-github-actions">Step 8: Set Up a Documentation Workflow Using GitHub Actions</h2>
<p>Now we’ll set up a workflow for the documentation. In GitHub, when you deploy to GitHub Pages, it sets up a default workflow for you at <code>pages-build-deployments</code>.</p>
<p>Netlify also automates deployments but does not create a workflow file in your repository. Instead, it manages the process through its platform, monitoring your repository for changes and running builds based on your settings. In this tutorial, we will set up a workflow with GitHub Actions that automates Vale running linting checks through the docs.</p>
<p>Create a <code>.github/workflows</code> directory and add a <code>vale-linter.yml</code> file in it. </p>
<p>Add this code in it:</p>
<pre><code class="lang-yaml"><span class="hljs-attr">name:</span> <span class="hljs-string">Vale</span> <span class="hljs-string">Lint</span> <span class="hljs-string">Checker</span>

<span class="hljs-comment"># Trigger the workflow on specific events.</span>
<span class="hljs-attr">on:</span>
  <span class="hljs-attr">push:</span> <span class="hljs-comment"># Run on every push to the main branch.</span>
    <span class="hljs-attr">branches:</span>
      <span class="hljs-bullet">-</span> <span class="hljs-string">main</span>
  <span class="hljs-attr">pull_request:</span> <span class="hljs-comment"># Run on pull requests targeting any branch.</span>
    <span class="hljs-attr">branches:</span>
      <span class="hljs-bullet">-</span> <span class="hljs-string">'*'</span>
  <span class="hljs-attr">workflow_dispatch:</span> <span class="hljs-comment"># Allow manual triggering from the Actions tab.</span>

<span class="hljs-attr">jobs:</span>
  <span class="hljs-attr">prose:</span>
    <span class="hljs-attr">runs-on:</span> <span class="hljs-string">ubuntu-latest</span>
    <span class="hljs-attr">steps:</span>
      <span class="hljs-comment"># Step 1: Check out the repository code.</span>
      <span class="hljs-bullet">-</span> <span class="hljs-attr">name:</span> <span class="hljs-string">Checkout</span> <span class="hljs-string">Code</span>
        <span class="hljs-attr">uses:</span> <span class="hljs-string">actions/checkout@v3</span> 

      <span class="hljs-comment"># Step 2: Set up Node.js</span>
      <span class="hljs-bullet">-</span> <span class="hljs-attr">name:</span> <span class="hljs-string">Setup</span> <span class="hljs-string">Node.js</span>
        <span class="hljs-attr">uses:</span> <span class="hljs-string">actions/setup-node@v3</span>
        <span class="hljs-attr">with:</span>
          <span class="hljs-attr">node-version:</span> <span class="hljs-number">16</span> <span class="hljs-comment"># Use Node.js 16 or higher</span>

      <span class="hljs-comment"># Step 3: Run Vale lint checks.</span>
      <span class="hljs-bullet">-</span> <span class="hljs-attr">name:</span> <span class="hljs-string">Vale</span> <span class="hljs-string">Lint</span>
        <span class="hljs-attr">uses:</span> <span class="hljs-string">errata-ai/vale-action@reviewdog</span>
        <span class="hljs-attr">with:</span>
          <span class="hljs-attr">files:</span> <span class="hljs-string">.</span>
        <span class="hljs-attr">env:</span>
          <span class="hljs-attr">GITHUB_TOKEN:</span> <span class="hljs-string">${{</span> <span class="hljs-string">secrets.GITHUB_TOKEN</span> <span class="hljs-string">}}</span>
</code></pre>
<p>After making these changes, run the following commands:</p>
<pre><code class="lang-powershell">git add .
git commit <span class="hljs-literal">-m</span> “changes”
</code></pre>
<p>Finally push to the repository with <code>git push</code>.</p>
<p>Go to the <code>Actions</code> tab on your repository. You should see the workflow running:</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1737521586319/3d554246-f8e6-4885-bac5-2cead1b3dd56.png" alt="The github repository page with focus on the Actions tab showing the vale workflow" class="image--center mx-auto" width="600" height="400" loading="lazy"></p>
<p>Click on the <code>changes</code> button and click on the job <code>prose</code>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1737970927236/632e2753-5d2e-474b-a05e-74a9affa634d.png" alt="A brief preview of the lint output from vale in the prose job run" class="image--center mx-auto" width="600" height="400" loading="lazy"></p>
<p>Now, you should see all the lines in your <code>.md</code> files highlighted by Vale.</p>
<p>With this, your docs are set up to run like a codebase! You can make changes, and when you push, review, and merge, it will sync automatically.</p>
<p>Keep in mind that this is for Netlify. For GitHub Pages, you’ll need to set up a workflow for automatic deployment.</p>
<h2 id="heading-summary">Summary</h2>
<p>In this tutorial, you have learned how to set up documentation as code using Docusaurus. You also saw how to deploy your documentation to a live site, and automate the linting workflow with Vale and GitHub Actions.</p>
<p><a target="_blank" href="https://docs.github.com/en/actions/use-cases-and-examples/creating-an-example-workflow">There are other workflows</a> you can set up to ease the workload in managing your doc site. Remember, the main point is to organize and structure your docs while automating regular documentation practices using software development tools. This lets you focus on the most important thing which is creating quality content for your readers.</p>
 ]]>
                </content:encoded>
            </item>
        
            <item>
                <title>
                    <![CDATA[ How to Build a Documentation Site using React and Docusaraus ]]>
                </title>
                <description>
                    <![CDATA[ Having a properly designed and comprehensive documentation site is important for any project. But creating good documentation can be challenging, and problems like poor user onboarding experience and increased support tickets can become daily hassles... ]]>
                </description>
                <link>https://www.freecodecamp.org/news/build-a-documentation-site-using-react-and-docusaraus/</link>
                <guid isPermaLink="false">6706b5ae1446e5644b75b252</guid>
                
                    <category>
                        <![CDATA[ docusaurus ]]>
                    </category>
                
                    <category>
                        <![CDATA[ documentation ]]>
                    </category>
                
                    <category>
                        <![CDATA[ Technical writing  ]]>
                    </category>
                
                    <category>
                        <![CDATA[ React ]]>
                    </category>
                
                <dc:creator>
                    <![CDATA[ Chisom Uma ]]>
                </dc:creator>
                <pubDate>Wed, 09 Oct 2024 16:56:14 +0000</pubDate>
                <media:content url="https://cdn.hashnode.com/res/hashnode/image/upload/v1728407506914/49f6f7cd-af92-405e-ac89-d71bd74e3f18.avif" medium="image" />
                <content:encoded>
                    <![CDATA[ <p>Having a properly designed and comprehensive documentation site is important for any project. But creating good documentation can be challenging, and problems like poor user onboarding experience and increased support tickets can become daily hassles for a team.</p>
<p>This is why documentation tools like Docusaurus are great for helping you create visually stunning documentation sites in abo 5 minutes.</p>
<p>In this tutorial, I'll show you how to build a documentation site using React and Docusaurus.</p>
<p>If you are new to Docusaurus, you are probably wondering, “why React?, why not any other framework like Next.js?”, Don’t worry – I’ll also answer this question in this guide.</p>
<h2 id="heading-table-of-contents">Table of Contents</h2>
<ul>
<li><p><a class="post-section-overview" href="#heading-prerequisites">Prerequisites</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-what-is-docusaurus">What is Docusaurus?</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-getting-started-and-installation">Getting Started and Installation</a></p>
<ul>
<li><a class="post-section-overview" href="#heading-project-structure">Project structure</a></li>
</ul>
</li>
<li><p><a class="post-section-overview" href="#heading-how-to-start-your-docusaurus-website">How to Start Your Docusaurus Website</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-how-to-create-documentation-overview">How to Create Documentation (Overview)</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-mdx-and-react-components">MDX and React Components</a></p>
<ul>
<li><p><a class="post-section-overview" href="#heading-tabs">Tabs</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-alerts-or-admonitions">Alerts or Admonitions</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-code-blocks">Code blocks</a></p>
</li>
</ul>
</li>
<li><p><a class="post-section-overview" href="#heading-docusaurus-blog">Docusaurus Blog</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-custom-pages">Custom Pages</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-styling-in-docusaurus">Styling in Docusaurus</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-deployment">Deployment</a></p>
</li>
<li><p><a class="post-section-overview" href="#heading-conclusion">Conclusion</a></p>
</li>
</ul>
<h2 id="heading-prerequisites">Prerequisites</h2>
<p>To follow along with this guide, you should have:</p>
<ul>
<li><p><strong>Node.js</strong> version 18.0 or above installed</p>
</li>
<li><p>Basic knowledge of React and Markdown</p>
</li>
<li><p>IDE (preferably VSCode)</p>
</li>
</ul>
<h2 id="heading-what-is-docusaurus">What is Docusaurus?</h2>
<p><a target="_blank" href="https://docusaurus.io/">Docusaurus</a> was released by the Meta Open Source team in 2017 to help devs build, deploy, and maintain documentation websites easily and quickly. The project’s other goal was to improve the speed of both developers and end users using the <a target="_blank" href="https://web.dev/articles/apply-instant-loading-with-prpl">PRPL</a> pattern.</p>
<p>Some of its cool features include search and localization, powered by <a target="_blank" href="https://www.algolia.com/">Algolia</a> (search) and <a target="_blank" href="https://crowdin.com/">Crowdin</a> (language support and internationalization).</p>
<p>Now, let’s talk about why we’re using React for this tutorial. Well, Docusaurus is built on top of React, which makes it easy to customize the website. Also, Docusaurus supports Markdown and MDX (which lets you use React JSX in your markdown content).</p>
<p>As a technical writer myself, I love that this tool supports Markdown, which I'm quite familiar with. It allows me to focus on creating helpful documentation without worrying about converting the text to other text formats.</p>
<h2 id="heading-getting-started-and-installation">Getting Started and Installation</h2>
<p>Getting started with Docusaraus is pretty straightforward. The first thing you need to do is head over to your terminal and run the command below:</p>
<pre><code class="lang-plaintext">npx create-docusaurus@latest my-website classic
</code></pre>
<p><strong>Note:</strong> The Docusaurus team recommends the <code>classic</code> template because it is easier to get started with fast. It also contains <code>@docusaurus/preset-classic</code> – which includes standard documentation, a blog, custom pages, and a CSS framework (with dark mode support).</p>
<h3 id="heading-project-structure">Project structure</h3>
<p>After installation, this is what your newly created Docusaurus project structure should look like:</p>
<pre><code class="lang-plaintext">📦my-website
┣ 📂blog
┃ ┣ 📂2021-08-26-welcome
┃ ┃ ┣ 📜docusaurus-plushie-banner.jpeg
┃ ┃ ┗ 📜index.md
┃ ┣ 📜2019-05-28-first-blog-post.md
┃ ┣ 📜2019-05-29-long-blog-post.md
┃ ┣ 📜2021-08-01-mdx-blog-post.mdx
┃ ┣ 📜authors.yml
┃ ┗ 📜tags.yml
┣ 📂docs
┃ ┣ 📂tutorial-basics
┃ ┃ ┣ 📜congratulations.md
┃ ┃ ┣ 📜create-a-blog-post.md
┃ ┃ ┣ 📜create-a-document.md
┃ ┃ ┣ 📜create-a-page.md
┃ ┃ ┣ 📜deploy-your-site.md
┃ ┃ ┣ 📜markdown-features.mdx
┃ ┃ ┗ 📜_category_.json
┃ ┣ 📂tutorial-extras
┃ ┃ ┣ 📂img
┃ ┃ ┃ ┣ 📜docsVersionDropdown.png
┃ ┃ ┃ ┗ 📜localeDropdown.png
┃ ┃ ┣ 📜manage-docs-versions.md
┃ ┃ ┣ 📜translate-your-site.md
┃ ┃ ┗ 📜_category_.json
┃ ┗ 📜intro.md
┣ 📂src
┃ ┣ 📂components
┃ ┃ ┗ 📂HomepageFeatures
┃ ┃ ┃ ┣ 📜index.js
┃ ┃ ┃ ┗ 📜styles.module.css
┃ ┣ 📂css
┃ ┃ ┗ 📜custom.css
┃ ┗ 📂pages
┃ ┃ ┣ 📜index.js
┃ ┃ ┣ 📜index.module.css
┃ ┃ ┗ 📜markdown-page.md
┣ 📂static
┃ ┣ 📂img
┃ ┃ ┣ 📜docusaurus-social-card.jpg
┃ ┃ ┣ 📜docusaurus.png
┃ ┃ ┣ 📜favicon.ico
┃ ┃ ┣ 📜logo.svg
┃ ┃ ┣ 📜undraw_docusaurus_mountain.svg
┃ ┃ ┣ 📜undraw_docusaurus_react.svg
┃ ┃ ┗ 📜undraw_docusaurus_tree.svg
┃ ┗ 📜.nojekyll
┣ 📜.gitignore
┣ 📜babel.config.js
┣ 📜docusaurus.config.js
┣ 📜package.json
┣ 📜README.md
┗ 📜sidebars.js
</code></pre>
<p>Now, let’s explore some of the main directories:</p>
<ul>
<li><p><code>blog/</code>: This is where you store your blog posts</p>
</li>
<li><p><code>docs/</code>: As the name implies, this is where your documentation projects are kept</p>
</li>
<li><p><code>src/</code>: This directory allows you to customize your website further using React code.</p>
</li>
<li><p><code>static</code>: Here, you store static files like images, logos, favicons, and so on.</p>
</li>
</ul>
<p>A very important file is the <code>docusaurus.config.js</code> file, which acts as the main configuration file for your website.</p>
<h2 id="heading-how-to-start-your-docusaurus-website">How to Start Your Docusaurus Website</h2>
<p>To run your website locally, first open a new terminal on your IDE and run the following command below to start the development server:</p>
<pre><code class="lang-plaintext">cd my-website

npm i

npx docusaurus start
</code></pre>
<p>After running the above command, the browser compiles the React and Markdown files and starts a local development server at <a target="_blank" href="http://localhost:3000/">http://localhost:3000/</a>. Docusaurus enables hot reload, so you can see changes made to your React, Markdown, and MDX files automatically – without reloading your entire app.</p>
<p>Here is what the site looks like on your browser:</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1728389930307/b0bd7810-dea2-458b-85a1-e10b9a7b3028.png" alt="Bootstrapped Docusaurus site" class="image--center mx-auto" width="600" height="400" loading="lazy"></p>
<p>In the image above, you are first welcomed to an intuitive and easily navigable website. At the top left corner of the website, you will see the “<strong>Tutorial</strong>” and “<strong>Blog</strong>” sections.</p>
<ul>
<li><p><strong>Tutorial:</strong> This is where users can see the live version of your documentation.</p>
</li>
<li><p><strong>Blog:</strong> This is where users can see the live version of your blog.</p>
</li>
</ul>
<p>The link to the Docusaurus Open Source GitHub repo and the icon for toggling your website between light and dark modes are at the top-right corner of the site.</p>
<p>Alternatively, you can use <a target="_blank" href="https://docusaurus.io/docs/playground">docusaurus.new</a> to test Docusaurus quickly in a playground without having to go through the installation process. Here, you have an option to choose between <a target="_blank" href="https://codesandbox.io/">CodeSandbox</a> and <a target="_blank" href="https://stackblitz.com/">StackBlitz</a>.</p>
<h2 id="heading-how-to-create-documentation-overview">How to Create Documentation (Overview)</h2>
<p>Let’s take a closer look at our <code>docs</code> folder. If we head back to our local site and click on “<strong>Tutorial</strong>,” we will see some pre-built doc pages, as shown below:</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1728390116953/ec281a01-5b0c-413a-83b9-36d0352f3e03.png" alt="Documentation overview on the site" class="image--center mx-auto" width="600" height="400" loading="lazy"></p>
<p>These documentation pages are reflected in the <code>docs</code> folder located in your IDE. When we open the <code>category.json</code> page, we can adjust the name or position of each page. This means you don’t have to name the folders the same as the page name, since the name of the file will be the URL of the page.</p>
<p>To create our new documentation, let’s use the following steps:</p>
<ol>
<li><p>Delete all the files in the docs folder. Your browser and terminal will typically display an error after this.</p>
<p> <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1728390294195/5a59bdc4-7a79-4b17-9e85-630867c6c3ec.png" alt="Error from deleted files" class="image--center mx-auto" width="600" height="400" loading="lazy"></p>
<p> This is because we need at least one page in the docs folder.</p>
</li>
<li><p>Create a new file inside the docs folder, which can be named anything you prefer, but in our case, I named it <a target="_blank" href="http://single-page.md">single-page.md</a>. You should see this change immediately reflected when you go to your local website. This is what you will see in the documentation pages section:</p>
<p> <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1728390512797/90b86f29-8b03-414b-acff-18842cd4c462.png" alt="Single page " class="image--center mx-auto" width="600" height="400" loading="lazy"></p>
</li>
</ol>
<p>Inside this newly created file, you can create your documentation seamlessly. The image above shows the little Markdown content I created saying “Single Page” in an H1 and “This is a single page” in plain text.</p>
<p>Let’s say you want to create a more organized content structure, but you don’t know how to get started. Here are a few simple steps on how to do that:</p>
<ol>
<li><p>Create a new folder inside the <code>docs</code> folder, named “Getting Started”</p>
</li>
<li><p>Create new Markdown files inside the “Getting started” folder, and name them whatever you like. For the sake of this tutorial, let’s name it <a target="_blank" href="http://API-docs.md"><code>API-docs.md</code></a> and <a target="_blank" href="http://Session-replay.md"><code>Session-replay.md</code></a>.</p>
</li>
<li><p>Write your documentation in Markdown</p>
</li>
</ol>
<p>This is how the file structure should look like on your IDE:</p>
<pre><code class="lang-plaintext">📦docs
┣ 📂Getting started
┃ ┣ 📜Open-replay.md
┃ ┗ 📜Session-replay.md
┗ 📜single-page.md
</code></pre>
<p>Here is a simple GIF to demonstrate how this works on the local documentation website.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1728390784981/9eed8cbf-c6dc-4508-9d75-401d87673cf7.gif" alt="GIF showing local documentation site" class="image--center mx-auto" width="600" height="400" loading="lazy"></p>
<p>Now, let’s try to create a separate page in the <code>doc</code> folder. To do this, let’s create a  <code>category.json</code> page in the <code>Getting started</code> folder. Inside the  <code>category.json</code>  file, we will include the following JSON text:</p>
<pre><code class="lang-json">{
  <span class="hljs-attr">"label"</span>: <span class="hljs-string">"Custom Title"</span>,
  <span class="hljs-attr">"position"</span>: <span class="hljs-number">2</span>,
  <span class="hljs-attr">"link"</span>: {
    <span class="hljs-attr">"type"</span>: <span class="hljs-string">"generated-index"</span>,
    <span class="hljs-attr">"description"</span>: <span class="hljs-string">"This is a custom description"</span>
  }
}
</code></pre>
<ul>
<li><p>The <code>link</code> object creates a separate page for the folder.</p>
</li>
<li><p>The <code>type</code> property is set to generated-index, which means it will generate the pages with all the sub-pages.</p>
</li>
<li><p>The <code>description</code> property is a description of the page that will show up beneath the title.</p>
</li>
</ul>
<p>When you check out your local hosted documentation site, you will see that the label has changed, and a separate page has been created for the folder.</p>
<p>In this section, I will show you an example of how headings and tables of content work in Docusaurus.</p>
<p>The first thing I did was create a <a target="_blank" href="http://markdown.md"><code>markdown.md</code></a> file. Then I pasted a couple of headings in Markdown text format right inside the file, like this:</p>
<pre><code class="lang-markdown">---
title: Basic Markdown
<span class="hljs-section">sidebar<span class="hljs-emphasis">_position: 1
---

# Heading 1

## Heading 2

### Heading 3

#### Heading 4

##### Heading 5

###### Heading 6</span></span>
</code></pre>
<p>When we head back to our website, we can see that only headings level 2 and 3 are automatically added, just as shown below:</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1728391234366/1ba2a824-3d31-4fd2-bd3e-8fcb9547e073.png" alt="Image showing headers" class="image--center mx-auto" width="600" height="400" loading="lazy"></p>
<p>We can edit to ensure that all the headings show up. To do this, first create a <a target="_blank" href="http://table-of-contents.md"><code>table-of-contents.md</code></a>, then paste in the following Markdown:</p>
<pre><code class="lang-markdown">---
title: Table of Contents
sidebar<span class="hljs-emphasis">_position: 2
toc_</span>min<span class="hljs-emphasis">_heading_</span>level: 2
<span class="hljs-section">toc<span class="hljs-emphasis">_max_</span>heading<span class="hljs-emphasis">_level: 6
---

import TOCInline from '@theme/TOCInline';

<span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">TOCInline</span> <span class="hljs-attr">toc</span>=<span class="hljs-string">{toc}</span> <span class="hljs-attr">minHeadingLevel</span>=<span class="hljs-string">{2}</span> <span class="hljs-attr">maxHeadingLevel</span>=<span class="hljs-string">{6}</span> /&gt;</span></span>

## Heading 2

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed non risus. Suspendisse lectus tortor, dignissim sit amet, adipiscing nec, ultricies sed, dolor.

### Heading 3

Some content here.

#### Heading 4

Some content here.

##### Heading 5

Some content here.

###### Heading 6

Some content here.

## Heading 2

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed non risus. Suspendisse lectus tortor, dignissim sit amet, adipiscing nec, ultricies sed, dolor.

### Heading 3

Some content here.

#### Heading 4

Some content here.

##### Heading 5

Some content here.

###### Heading 6

Some content here.

## Heading 2

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed non risus. Suspendisse lectus tortor, dignissim sit amet, adipiscing nec, ultricies sed, dolor.

### Heading 3

Some content here.

#### Heading 4

Some content here.

##### Heading 5

Some content here.

###### Heading 6

Some content here.</span></span>
</code></pre>
<p>I added a TOC property and set the minimum and maximum heading levels with <code>toc_min_heading_level: 2</code> and <code>toc_max_heading_level: 6</code>. We also added an inline table of contents by first importing <code>TOCInline</code> from <code>@theme/TOCInline</code>. Then, we created a TOCInline component (which can be put anywhere you want your TOC to show up).</p>
<p>Now, all the headings show up in the table of contents part of the website:</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1728398728652/37595594-3dbc-42bc-853c-f5b5ba9714c4.png" alt="Image showing table of content and headers" class="image--center mx-auto" width="600" height="400" loading="lazy"></p>
<p>Beautiful right?</p>
<h2 id="heading-mdx-and-react-components">MDX and React Components</h2>
<p>Now, let’s talk about one of the most exciting features of Docusaurus: MDX and React components.</p>
<p>You might ask – how can Docusaurus use <code>TOC</code> or <code>import</code> in the Markdown file? Well, that’s because Docusaurus uses MDX, which is basically Markdown with JSX.</p>
<p>To demonstrate this, let’s create a new Markdown file inside our <code>Getting started</code> folder titled  <a target="_blank" href="http://MDX.md"><code>MDX.md</code></a> , then we create a separate file inside the <code>src</code> &gt; <code>components</code> folder and name the file <code>Tag.js</code> . Then we paste in the following code:</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">import</span> React <span class="hljs-keyword">from</span> <span class="hljs-string">'react'</span>;

<span class="hljs-keyword">export</span> <span class="hljs-keyword">default</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">Tag</span>(<span class="hljs-params">{ children, color }</span>) </span>{
  <span class="hljs-keyword">return</span> (
    <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">span</span>
      <span class="hljs-attr">style</span>=<span class="hljs-string">{{</span>
        <span class="hljs-attr">backgroundColor:</span> <span class="hljs-attr">color</span>,
        <span class="hljs-attr">borderRadius:</span> '<span class="hljs-attr">4px</span>',
        <span class="hljs-attr">color:</span> '#<span class="hljs-attr">fff</span>',
        <span class="hljs-attr">padding:</span> '<span class="hljs-attr">0.2rem</span> <span class="hljs-attr">0.5rem</span>',
        <span class="hljs-attr">fontWeight:</span> '<span class="hljs-attr">bold</span>',
      }}
    &gt;</span>
      {children}
    <span class="hljs-tag">&lt;/<span class="hljs-name">span</span>&gt;</span></span>
  );
}
</code></pre>
<p>Here, we first imported the core React library, and then we defined a functional component called Tag, which takes in two props as input: <code>children</code> and <code>color</code>. In our return statement, we included our CSS styles for the <code>span</code> element.</p>
<p>Inside the <a target="_blank" href="http://MDX.md">MDX.md</a> file, paste in the below code:</p>
<pre><code class="lang-markdown">---
title: MDX
<span class="hljs-section">sidebar<span class="hljs-emphasis">_position: 3
---

import Tag from '@site/src/components/Tag';

<span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">Tag</span> <span class="hljs-attr">color</span>=<span class="hljs-string">"#FF5733"</span>&gt;</span></span>Important<span class="xml"><span class="hljs-tag">&lt;/<span class="hljs-name">Tag</span>&gt;</span></span> information: This is an <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">Tag</span> <span class="hljs-attr">color</span>=<span class="hljs-string">"#3399FF"</span>&gt;</span></span>Exciting<span class="xml"><span class="hljs-tag">&lt;/<span class="hljs-name">Tag</span>&gt;</span></span> example of custom components!

I can write <span class="hljs-strong">**Markdown**</span> alongside my _</span>JSX<span class="hljs-emphasis">_!</span></span>
</code></pre>
<p>Here, we import <code>Tag</code> from our components folder. This is what it looks like:</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1728398996580/a826b80c-1862-46f4-b111-dc6366dd13db.png" alt="Image showing how MDX works" class="image--center mx-auto" width="600" height="400" loading="lazy"></p>
<p><strong>Note:</strong> Because we use MDX, Docusaurus comes with pre-built components like Tabs, alerts, code blocks, and more. Let’s check them out in the following subsections.</p>
<h3 id="heading-tabs">Tabs</h3>
<p>In this subsection, we’ll talk about tabs as a pre-built component in Docusaurus. Let’s dive right in!</p>
<p>For a start, let’s create a new Markdown file called <a target="_blank" href="http://tabs.md"><code>tabs.md</code></a> and paste in the following code:</p>
<pre><code class="lang-markdown">---
title: Tabs in Markdown
<span class="hljs-section">sidebar<span class="hljs-emphasis">_position: 4
---

import Tabs from '@theme/Tabs';
import TabItem from '@theme/TabItem';

<span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">Tabs</span>&gt;</span></span>
  <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">TabItem</span> <span class="hljs-attr">value</span>=<span class="hljs-string">"book"</span> <span class="hljs-attr">label</span>=<span class="hljs-string">"Book"</span> <span class="hljs-attr">default</span>&gt;</span></span>
    Dive into the world of knowledge with a captivating book 📚
  <span class="xml"><span class="hljs-tag">&lt;/<span class="hljs-name">TabItem</span>&gt;</span></span>
  <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">TabItem</span> <span class="hljs-attr">value</span>=<span class="hljs-string">"painting"</span> <span class="hljs-attr">label</span>=<span class="hljs-string">"Painting"</span>&gt;</span></span>
    Admire the strokes of artistry on a beautiful painting 🖼️
  <span class="xml"><span class="hljs-tag">&lt;/<span class="hljs-name">TabItem</span>&gt;</span></span>
  <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">TabItem</span> <span class="hljs-attr">value</span>=<span class="hljs-string">"music"</span> <span class="hljs-attr">label</span>=<span class="hljs-string">"Music"</span>&gt;</span></span>
    Let the soothing melodies of music transport you 🎶
  <span class="xml"><span class="hljs-tag">&lt;/<span class="hljs-name">TabItem</span>&gt;</span></span>
<span class="xml"><span class="hljs-tag">&lt;/<span class="hljs-name">Tabs</span>&gt;</span></span>

I'm a text that doesn't belong to any tab. So I'm always visible.</span></span>
</code></pre>
<p>We imported <code>Tabs</code> from <code>@theme/Tabs</code> and <code>TabItem</code> from <code>@theme/TabItem</code>. Then, we created a Tabs component, which is the container, and the <code>TabItem</code> component is the tab itself. The <code>value</code> property is the value of the tab, while the <code>label</code> property is the label of the tab. The default property defines which tab is open by default – in this case, the “Book” tab.</p>
<p>This is how it looks:</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1728399214390/edece46f-3357-4b96-8672-a462a8a8916b.png" alt="Image showing how tabs work" class="image--center mx-auto" width="600" height="400" loading="lazy"></p>
<p>Each tab is clickable and transitions smoothly.</p>
<h3 id="heading-alerts-or-admonitions">Alerts or Admonitions</h3>
<p>Docusaurus comes with pre-built alerts or admonitions. To create an alert, you simply wrap the text with three colons and follow it with the type of alert you want the reader to have in mind.</p>
<p>Let’s create a new Markdown file called <a target="_blank" href="http://alerts.md">alerts.md</a> and paste in the following Markdown:</p>
<pre><code class="lang-markdown">---
title: Alerts or Admonitions
<span class="hljs-section">sidebar<span class="hljs-emphasis">_position: 5
---

:::note

Here's some <span class="hljs-strong">**information**</span> with _</span>Markdown<span class="hljs-emphasis">_ styling.

:::

:::tip

Here's a <span class="hljs-strong">**helpful tip**</span> with _</span>formatted text<span class="hljs-emphasis">_.

:::

:::info

Here's some <span class="hljs-strong">**useful info**</span> presented in a clear way.

:::

:::caution

Please take <span class="hljs-strong">**extra caution**</span> with this important note.

:::

:::danger

This is a <span class="hljs-strong">**dangerous situation**</span> you need to be aware of.

:::

:::note This is a _</span>custom title<span class="hljs-emphasis">_

And you can add images as well.

![<span class="hljs-string">alt text</span>](<span class="hljs-link">https://picsum.photos/600/400</span>)

:::</span></span>
</code></pre>
<p>The various types of alerts, as shown in the Markdown above, are:</p>
<ul>
<li><p><code>note</code></p>
</li>
<li><p><code>tip</code></p>
</li>
<li><p><code>info</code></p>
</li>
<li><p><code>caution</code></p>
</li>
<li><p><code>danger</code></p>
</li>
</ul>
<p>Here’s what it looks like on the website:</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1728402667575/cc10af2d-e417-4426-985b-4aad81a082db.png" alt="Image showing how alerts and admonitions work" class="image--center mx-auto" width="600" height="400" loading="lazy"></p>
<p>Alerts and admonitions are pretty common in documentation sites. So, if you have ever wondered how it’s been done, well, this is it! It’s quite straightforward.</p>
<h3 id="heading-code-blocks">Code blocks</h3>
<p>As we already know by now, Docusaurus supports MDX, which allows us to include code blocks in our files. Code blocks are text blocks wrapped around by strings of three backticks. You can add the name of the language after the last of the three backticks.</p>
<p>Let’s create a <a target="_blank" href="http://codeblocks.md"><code>codeblocks.md</code></a> file and paste the following JSX code:</p>
<pre><code class="lang-javascript">---
title: Codeblocks
<span class="hljs-attr">sidebar_position</span>: <span class="hljs-number">6</span>
---

<span class="hljs-string">``</span><span class="hljs-string">`jsx title="Codeblock"
function Greeting(props) {
  return &lt;p&gt;Welcome, {props.userName}!&lt;/p&gt;;
}

export default Greeting;
`</span><span class="hljs-string">``</span>

<span class="hljs-string">``</span><span class="hljs-string">`jsx title="Highlight Lines"
function HighlightText(highlight) {
  if (highlight) {
    // highlight-next-line
    return 'This text is highlighted!';
  }
  return 'Nothing highlighted';
}

function HighlightMoreText(highlight) {
  // highlight-start
  if (highlight) {
    return 'This range is highlighted!';
  }
  // highlight-end
  return 'Nothing highlighted';
}
`</span><span class="hljs-string">``</span>

<span class="hljs-string">``</span><span class="hljs-string">`jsx title="Line Numbers" showLineNumbers
import React from 'react';

function UserProfile(props) {
  const { username, email, isAdmin } = props;

  return (
    &lt;div&gt;
      &lt;h1&gt;User Profile&lt;/h1&gt;
      &lt;p&gt;Username: {username}&lt;/p&gt;
      &lt;p&gt;Email: {email}&lt;/p&gt;
      {isAdmin &amp;&amp; &lt;p&gt;Admin User&lt;/p&gt;}
    &lt;/div&gt;
  );
}

export default UserProfile;
`</span><span class="hljs-string">``</span>

<span class="hljs-string">``</span><span class="hljs-string">`jsx title="Line Numbers with Highlight" {4,9-11} showLineNumbers
import React from 'react';

function UserProfile(props) {
  const { username, email, isAdmin } = props;

  return (
    &lt;div&gt;
      &lt;h1&gt;User Profile&lt;/h1&gt;
      &lt;p&gt;Username: {username}&lt;/p&gt;
      &lt;p&gt;Email: {email}&lt;/p&gt;
      {isAdmin &amp;&amp; &lt;p&gt;Admin User&lt;/p&gt;}
    &lt;/div&gt;
  );
}

export default UserProfile;</span>
</code></pre>
<p>This is what the code blocks look like:</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1728402852316/4873fccd-d4b7-45d7-8d4f-49fea5a3da49.png" alt="Image showing how codeblocks work" class="image--center mx-auto" width="600" height="400" loading="lazy"></p>
<p>You can easily copy the code by hovering your cursor over the code blocks and clicking on the copy icon on the top-right side of the code block.</p>
<p><strong>Note:</strong> By default, Docusaurus uses <code>Prism</code> for syntax highlighting.</p>
<p>If you also want to highlight some lines of code, you can do that by adding a comment like this:</p>
<pre><code class="lang-javascript">    <span class="hljs-comment">// highlight-next-line</span>
    <span class="hljs-keyword">return</span> <span class="hljs-string">'This text is highlighted!'</span>;
  }
  <span class="hljs-keyword">return</span> <span class="hljs-string">'Nothing highlighted'</span>;
}

<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">HighlightMoreText</span>(<span class="hljs-params">highlight</span>) </span>{
  <span class="hljs-comment">// highlight-start</span>
  <span class="hljs-keyword">if</span> (highlight) {
    <span class="hljs-keyword">return</span> <span class="hljs-string">'This range is highlighted!'</span>;
  }
  <span class="hljs-comment">// highlight-end</span>
</code></pre>
<ul>
<li><p><code>highlight-next-line</code>: allows you to highlight a single line of code</p>
</li>
<li><p><code>highlight-start and highlight-end</code>: allows you to highlight a range of lines</p>
</li>
</ul>
<h2 id="heading-docusaurus-blog">Docusaurus Blog</h2>
<p>The Docusaurus blog also comes by default with the <code>classic</code> template. If you don’t have a blog, you can add the following lines to your <code>docusaurus.config.js</code> file:</p>
<pre><code class="lang-javascript">{
  <span class="hljs-attr">label</span>: <span class="hljs-string">'Blog'</span>,
  <span class="hljs-attr">to</span>: <span class="hljs-string">'/blog'</span>,
}
</code></pre>
<p>Usually, this line should already be in your config file after installing Docusaurus for the first time.</p>
<p>The Docusaurus blog is very simple to understand. Navigate to the blog folder in the project explorer, and you’ll see all the blog posts, which are MDX files. The blog post date should be included on the file name as shown below:</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1728403567052/c60d665d-f29b-433e-bd10-b86542d0063e.png" alt="Image showing blog folder" class="image--center mx-auto" width="600" height="400" loading="lazy"></p>
<p>When you open one of the blog posts, you see something like this:</p>
<pre><code class="lang-markdown">---
slug: long-blog-post
title: Long Blog Post
authors: yangshun
<span class="hljs-section">tags: [hello, docusaurus]
---</span>

This is the summary of a very long blog post,

Use a <span class="hljs-code">`&lt;!--`</span> <span class="hljs-code">`truncate`</span> <span class="hljs-code">`--&gt;`</span> comment to limit blog post size in the list view.

<span class="xml"><span class="hljs-comment">&lt;!-- truncate --&gt;</span></span>

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque elementum dignissim ultricies. Fusce rhoncus ipsum tempor eros aliquam consequat. Lorem ipsum dolor sit amet
</code></pre>
<ul>
<li><p><code>slug</code>: You can add a slug to the URL of the blog post</p>
</li>
<li><p><code>title</code>: Title of the blog post</p>
</li>
<li><p><code>authors</code>: The authors of the blog post</p>
</li>
<li><p><code>tags</code>: Tags related to the blog post</p>
</li>
</ul>
<p>In the blog post, we can also use all the Markdown features plus JSX as we have seen before.</p>
<h2 id="heading-custom-pages">Custom Pages</h2>
<p>Technically, Docusaurus isn’t just a fancy documentation site generator with a blog. It’s a standard static site generator – which means you can create any page you want.</p>
<p>To see how creating a custom page in Docusaurus works, let’s create an about.js file in the <code>src</code> <strong>&gt;</strong> <code>pages</code> folder and include the following code:</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">import</span> React <span class="hljs-keyword">from</span> <span class="hljs-string">'react'</span>;
<span class="hljs-keyword">import</span> Layout <span class="hljs-keyword">from</span> <span class="hljs-string">'@theme/Layout'</span>;
<span class="hljs-keyword">import</span> Head <span class="hljs-keyword">from</span> <span class="hljs-string">'@docusaurus/Head'</span>;

<span class="hljs-keyword">export</span> <span class="hljs-keyword">default</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">About</span>(<span class="hljs-params"></span>) </span>{
  <span class="hljs-keyword">return</span> (
    <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">Layout</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">Head</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">title</span>&gt;</span>About<span class="hljs-tag">&lt;/<span class="hljs-name">title</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">meta</span> <span class="hljs-attr">name</span>=<span class="hljs-string">"description"</span> <span class="hljs-attr">content</span>=<span class="hljs-string">"This is the about page"</span> /&gt;</span>
      <span class="hljs-tag">&lt;/<span class="hljs-name">Head</span>&gt;</span>

      <span class="hljs-tag">&lt;<span class="hljs-name">div</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">h1</span> <span class="hljs-attr">className</span>=<span class="hljs-string">"red-text"</span>&gt;</span>About<span class="hljs-tag">&lt;/<span class="hljs-name">h1</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">p</span>&gt;</span>This is the about page.<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
      <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">Layout</span>&gt;</span></span>
  );
}
</code></pre>
<p>When you go to <a target="_blank" href="http://localhost:3000/about">http://localhost:3000/about</a>, you should see something like this:</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1728404291897/394ee43b-2b30-43f8-a8cf-ff260d51e82a.png" alt="Image showing how custom pages work " class="image--center mx-auto" width="600" height="400" loading="lazy"></p>
<p>We can also add the page to the navbar by going to the docusaurus.config.js file and adding a new item to the navbar array. The item looks like this:</p>
<pre><code class="lang-json">{to: 'about', label: 'About', position: 'left'},
</code></pre>
<p>It then appears on the homepage nav menu like this:</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1728404457186/25545cf0-a5bf-4561-8dc8-49045c3cfc9d.png" alt="Image showing how custom pages work " class="image--center mx-auto" width="600" height="400" loading="lazy"></p>
<p>You can now style and customize the <code>about.js</code> file any way you’d prefer using React.</p>
<h2 id="heading-styling-in-docusaurus">Styling in Docusaurus</h2>
<p>Let’s look at how you can style your site in Docusaurus. The easiest way is to customize the <code>custom.css</code> file inside the <code>css</code> <strong>&gt;</strong> <code>custom.css</code> file. This is what the file looks like:</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1728404914713/bd2c8b65-52f9-43d4-b0c8-d09ec9562865.png" alt="Image showing how to perform styling" class="image--center mx-auto" width="600" height="400" loading="lazy"></p>
<p>Here, you can change the whole color schema of the site and different styling to this file.</p>
<p>You can <strong>read more</strong> about this in the <a target="_blank" href="https://docusaurus.io/docs/styling-layout">Docusaurus styling and layout</a> docs.</p>
<h2 id="heading-seo-in-docusaurus">SEO in Docusaurus</h2>
<p>Docusaurus takes SEO very seriously. By default, Docusaurus automatically adds a description title, canonical URL links, and other useful metadata to each page. This can be configured as shown below:</p>
<pre><code class="lang-markdown">---
title: Our First Page
sidebar<span class="hljs-emphasis">_position: 1

description: A short description of this page
image: ../static/img/docusaurus-social-card.jpg
keywords: [keywords, describing, the main topics]
---

# Single Page

This is a single page.</span>
</code></pre>
<p>You can <strong>read more</strong> about this in the <a target="_blank" href="https://docusaurus.io/docs/seo">Docusaurus SEO</a> docs.</p>
<h2 id="heading-deployment">Deployment</h2>
<p>Deployment is pretty easy with Docusaurus. Since it’s a static site, you can deploy it to any static site hosting service. To do this, run the <code>npm run build</code> command on your CLI. This creates a build folder like the one below:</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1728405905725/a7633e46-cb10-4220-bce8-7b12545a124f.png" alt="Image showing build folder for deployment" class="image--center mx-auto" width="600" height="400" loading="lazy"></p>
<p>Then, you can upload the contents of the build folder to your hosting service.</p>
<h2 id="heading-conclusion">Conclusion</h2>
<p>In this article, we covered how to build documentation from scratch, how to create, customize, and style pages, and the awesome SEO power of Docusaurus.</p>
<p>Docusaurus is friendly to both developers and technical writers. As a developer, you can focus on customizing the site, while as a technical writer, you can focus on writing the documentation.</p>
<p>I will highly recommend this tool for both startups and established enterprises looking to build stunning documentation sites.</p>
<p>This guide is not exhaustive, but covers everything you need to know about the basics of building a documentation site with React and Docusaurus.</p>
<p>I hope you found it helpful :)</p>
<p>Here’s the link to my <a target="_blank" href="https://github.com/ChisomUma/docusaurus-project">GitHub code</a> for follow-up purposes.</p>
<p>And here’s the main Docusaurus <a target="_blank" href="https://docusaurus.io/docs/docs-introduction">documentation</a> if you’d like to dive in deeper.</p>
 ]]>
                </content:encoded>
            </item>
        
    </channel>
</rss>
