How to Work on Documentation
Welcome to the guide for contributing to freeCodeCamp’s documentation site! This site is built using Astro with the Starlight theme and deployed on Cloudflare Pages.
Follow these guidelines for setting up a development environment for the freeCodeCamp documentation site. This is highly recommended if you want to contribute regularly to our contributing guidelines.
Fork the contribute repository on GitHub
Section titled “Fork the contribute repository on GitHub”You will need to fork the contribute repository on GitHub to get your own copy of the codebase. This will allow you to follow a Git-based workflow to contribute to freeCodeCamp’s documentation.
Follow these steps to fork the repository:
-
Click the button below to fork the contribute repository on GitHub.
Fork “freeCodeCamp/contribute”
-
On the create new fork page, check the details and click the Create fork button.
-
You should automatically be redirected to your fork, the URL should be something like
https://github.com/YOUR_USER_NAME/contribute
.
That’s it! You have successfully forked the contribute repository. You can always delete your fork if you want to start fresh.
Clone your Fork from GitHub
Section titled “Clone your Fork from GitHub”Next, you will need to clone your fork to your local machine.
Run these commands on your local machine:
-
Open a terminal in your projects directory, for example:
/home/username/projects/ -
Clone your fork of the contribute repository, replacing
YOUR_USER_NAME
with your GitHub UsernameTerminal window git clone --depth=1 https://github.com/YOUR_USER_NAME/contribute.gitThis will download the entire contribute repository to your projects directory.
Set up Syncing from Parent
Section titled “Set up Syncing from Parent”Now that you have downloaded a copy of your fork, you will need to set up an upstream
remote to the parent repository.
As mentioned earlier, the main repository is referred to as the upstream
repository. Your fork is referred to as the origin
repository.
You need a reference from your local clone to the upstream
repository in addition to the origin
repository. This is so that you can sync changes from the main repository without the requirement of forking and cloning repeatedly.
-
Change the directory to the new contribute directory:
Terminal window cd contribute -
Add a remote reference to the main contribute repository:
Terminal window git remote add upstream https://github.com/freeCodeCamp/contribute.git -
Ensure the configuration looks correct:
Terminal window git remote -vThe output should look something like below (replacing
YOUR_USER_NAME
with your GitHub username):origin https://github.com/YOUR_USER_NAME/contribute.git (fetch)origin https://github.com/YOUR_USER_NAME/contribute.git (push)upstream https://github.com/freeCodeCamp/contribute.git (fetch)upstream https://github.com/freeCodeCamp/contribute.git (push)
Create a Working Branch
Section titled “Create a Working Branch”Before making any changes, it’s important to create a new branch for your work. This keeps your changes organized and separate from the main codebase.
-
Create and switch to a new branch, replacing
feature/your-feature-name
with a descriptive name for your changes:Terminal window git checkout -b feature/your-feature-name -
Ensure you are on your new branch:
Terminal window git branchYou should see your new branch name with an asterisk (*) next to it, indicating it’s the active branch.
Prerequisites
Section titled “Prerequisites”- Node.js (LTS version recommended)
- pnpm v10 (required - do not use npm or yarn)
Core Development Commands
Section titled “Core Development Commands”# Install pnpm globally if not already installednpm install -g pnpm
# Install dependenciespnpm install
# Start the development server (localhost:4321)pnpm develop
# Build for productionpnpm build
# Build and preview locally using Cloudflare Pagespnpm preview
Code Quality Commands
Section titled “Code Quality Commands”# Run Prettier and ESLint checkspnpm lint
# Auto-fix Prettier and ESLint issuespnpm format
# Install Git hooks (runs automatically on install)pnpm prepare
Testing Commands
Section titled “Testing Commands”# Run all tests oncepnpm test
# Update test snapshotspnpm test:update
# Run a specific test filenpx vitest run tests/homepage.test.ts
# Run tests matching a patternnpx vitest run -t "has correct title"
Working on Documentation Content
Section titled “Working on Documentation Content”To work on the contributing guidelines, you can edit or add files in the src/content/docs
directory available here. When your changes are merged, they will be made available automatically at the documentation site.
When adding a new file to the docs
directory, you should evaluate if the file should also be added to the sidebar navigation. We typically create a link in the src/sidebar.ts
file for new and independent guides.
Creating Internal Links
Section titled “Creating Internal Links”If you want to create a link targeting a different section of the contributing guidelines, follow this format:
[Link text](/target-file-name#target-section-heading-id)
// If the target section is within the same page, you can omit the file name[Link text](#target-section-heading-id)
This is necessary to make these links work for the translated version of the document. Otherwise, they will redirect to the English version of the page regardless of the language.
Translating Docs with Internal Links
Section titled “Translating Docs with Internal Links”When you work on translating docs on Crowdin, make sure to replace the #target-section-heading-id
with the id on the translated document. Learn more about translating files here.
Structure of the Docs Website
Section titled “Structure of the Docs Website”The site is generated using Astro and served using Cloudflare Pages. Here’s how it works:
- All documentation content is stored in
src/content/docs/
as MDX files - The sidebar navigation is configured in
src/sidebar.ts
- Site configuration is managed in
astro.config.ts
- The site is automatically built and deployed via Cloudflare Pages
Serving the Documentation Site Locally
Section titled “Serving the Documentation Site Locally”The documentation site can be served locally using the development command:
pnpm develop
The documentation site should be available at http://localhost:4321
Deployment
Section titled “Deployment”The site is deployed on Cloudflare Pages. Please check the wrangler config for deployment details.
Proposing a Pull Request (PR)
Section titled “Proposing a Pull Request (PR)”After you’ve committed your changes, check here for how to open a Pull Request.