Guide: Combining a Custom HTML Landing Page with MkDocs
If you want a unique, custom-coded HTML landing page while still using the power of MkDocs for weekly documentation, this guide explains how to set that up without breaking your GitLab pipeline.
π Step 1: Organize Your Folder Structure
To prevent files from clashing, you must separate your "Landing Page" source from your "Documentation" source. Arrange your repository like this:
custom_landing/: Put your customindex.html,style.css, and images here.docs/: Put your weekly Markdown files (e.g.,week01.md) and your documentationindex.mdhere.mkdocs.yml: Your MkDocs configuration file (keep this in the root)..gitlab-ci.yml: Your GitLab automation instructions (keep this in the root).
βοΈ Step 2: Configure the .gitlab-ci.yml
GitLab needs a "recipe" to build your site. This specific configuration ensures Python is available and moves your files to the correct place.
Replace everything in your .gitlab-ci.yml with this:
image: python:latest
pages:
stage: deploy
script:
- pip install mkdocs
# 1. Build the MkDocs site into a subfolder
- mkdocs build --site-dir public/docs
# 2. Copy the custom landing page to the main root
- cp -r custom_landing/. public/
artifacts:
paths:
- public
rules:
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
π» Step 3: Pushing Changes via VS Code
When you move or delete files to organize your repo, you must tell Git to "record" those changes.
- Open Source Control: Click the branch icon on the left sidebar in VS Code.
- Stage All Changes: Hover over the Changes section and click the + (plus) icon. This stages everythingβnew files, moves, and deletions.
- Commit: Type a clear message in the box (e.g., "Setup custom landing page and MkDocs structure") and click Commit.
- Sync: Click Sync Changes (or the circular arrow icon) at the bottom left to push to GitLab.
π Step 4: Verify the Build
- Go to your GitLab project online.
- Navigate to Build > Pipelines.
- Blue (Running): Wait 1-2 minutes.
- Green (Passed): Success!
- Red (Failed): Click the red badge, click the "pages" job, and check the bottom of the log for errors (usually a typo or a missing folder).
π Step 5: Linking Everything Together
Now that your site has two parts, your links must be correct:
- From Landing Page to Docs: In your
custom_landing/index.html, your link should look like this:<a href="docs/index.html">View My Documentation</a> -
From Docs to Landing Page: In your
mkdocs.yml, you can add a link back to your home page:YAMLextra: homepage: ../index.html
π‘ Top Tips for Success
- Case Sensitivity: Linux servers care about capitals!
Custom_Landingis not the same ascustom_landing. Pick one and stay consistent. - The "Busybox" Error: If your pipeline says
pip: command not found, it means your.gitlab-ci.ymlis missing theimage: python:latestline at the very top. - Wait for the Refresh: After a green pipeline, wait about 60 seconds for the website to actually update.