MkDocs on Windows: Serving & Building
Important Note: These instructions are applicable only if you intend to modify the content of this documentation website. Please proceed with caution and make sure to follow our guidelines for making contributions.
Installation
- Install Python: Download and install Python from the official website. Follow the installation instructions for Windows.
- Verify Python Installation: Open a PowerShell terminal (run as administrator) and type
python --versionto confirm that Python is installed correctly. - Install pip: Use PowerShell to install pip by running the command:
py -m ensurepip --upgrade. Verify the installation by typingpip --versionin PowerShell. - Install mkdocs: Open a PowerShell terminal, and run
pip install mkdocsto install mkdocs on your system.
Usage
- Fetch the latest version of the documentation repository using GitHub Desktop or Git Bash.
- Open a PowerShell or VS Code terminal, navigate to the root directory of the
mkdocsrepository (e.g.,cd C:\Github\thefield\docs\mkdocs). - Run the command
mkdocs serve. Open your browser and visit http://127.0.0.1:8000 to view your documentation. - Add, delete, or edit
.mdfiles within themkdocsdirectory (e.g.,cd C:\thefield\mkdocs) to reflect your desired changes. Verify these updates in your browser. - Run the command
mkdocs buildto generate the html files that include the recent changes and push these changes to the Github repository.
Troubleshooting
Error: "pip is not recognized as an internal command"
If you encounter this error, it's likely because pip was not installed correctly during the Python installation process.
Verify Python Installation
Run python --version in PowerShell to confirm that Python is installed correctly. Check if pip is listed as a dependency or included with the Python installation.
Add Environment Path for pip (if necessary)
If pip is not recognized, you may need to add an environment path for pip:
- Right-click on "Computer" or "This PC", select "Properties", then click on "Advanced system settings".
- Under "System Variables", scroll down and find the "Path" variable, then click "Edit".
- Click "New" and add the path to the Pip directory (usually
C:\Python39\Scriptsor similar). - Click "OK" to close all the windows.
After adding the environment path, try running the command again to verify that pip is recognized correctly.
Error: "mkdocs serve" does not start the server
Ensure that you are running PowerShell or VS Code as an administrator, and that the directory path is correct.
Updating MkDocs
To keep your documentation up-to-date, it's essential to update mkdocs regularly. Here's how:
- Open a PowerShell terminal and run
pip install --upgrade mkdocsto upgrade mkdocs. - Verify the installation by running
mkdocs --version. - Update any dependencies or plugins as needed.
Additional Tips
Consistent Naming Convention
Use a consistent naming convention (e.g., lowercase letters and underscores) when creating new files or directories to avoid confusion.
Organizing Your Content
Organize your content using clear headings, subheadings, and sections to make it easy for users to navigate. This will also help you maintain a logical structure for your documentation.
Testing Changes
Before committing any changes, test them by running mkdocs serve and verifying that the updates are reflected in your browser. This ensures that your changes are accurate and functional.
Keeping mkdocs Up-to-Date
Regularly update mkdocs to ensure you have access to the latest features and bug fixes. You can do this by running pip install --upgrade mkdocs in a PowerShell terminal.