<?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[ docs-as-code - 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[ docs-as-code - freeCodeCamp.org ]]>
            </title>
            <link>https://www.freecodecamp.org/news/</link>
        </image>
        <generator>Eleventy</generator>
        <lastBuildDate>Mon, 27 Jul 2026 15:22:37 +0000</lastBuildDate>
        <atom:link href="https://www.freecodecamp.org/news/tag/docs-as-code/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="1335" height="698" 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="1337" height="654" 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="1335" height="650" 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="1336" height="690" 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="1347" height="519" 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="1317" height="657" 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>
        
    </channel>
</rss>
