Deploy an Eleventy Site to NeoCities with GitLab CI/CD
A GitLab CI/CD pipeline builds an Eleventy site and uploads it to NeoCities through the NeoCities API. The setup covers environment variables, deciding which files to upload, and error handling.
- By
- Brennan Kenneth Brown
- Published
- Reading time
- 4 minutes
- Level
- Intermediate
- You need
- An Eleventy site in a GitLab repository
- A NeoCities account
You can deploy an Eleventy site to NeoCities by having a GitLab CI/CD pipeline build the site and upload the rendered _site folder through the NeoCities API. I host my main site on Netlify and use this pipeline to mirror it to NeoCities as a backup, in line with the 3-2-1 backup rule. NeoCities is a free host in the spirit of the early web, with 1 GB of storage and 200 GB of bandwidth on the free tier, but it restricts which file types you can upload.
The pipeline does the following:
- Deploys the 11ty site to NeoCities on each commit
- Supports two authentication methods (username/password or API key)
- Uploads only modified files
- Filters out unsupported file types automatically
- Logs errors in enough detail to debug failures
The full .gitlab-ci.yml is long, so it is linked rather than pasted. This guide walks through its main parts, and the snippets below come from it.
How does the NeoCities API authenticate requests?
NeoCities provides a REST API with two authentication methods:
Basic authentication (username and password)
curl -u "username:password" https://neocities.org/api/info
Bearer token (API key)
curl -H "Authorization: Bearer YOUR_API_KEY" https://neocities.org/api/info
You can get your API key from the NeoCities API key page.
Which file types does NeoCities allow?
NeoCities free accounts support a specific set of file extensions. The complete list includes:
apng asc atom avif bin cjs css csv dae eot epub geojson gif glb
glsl gltf gpg htm html ico jpeg jpg js json jxl key kml knowl
less manifest map markdown md mf mid midi mjs mtl obj opml osdx
otf pdf pgp pls png py rdf resolveHandle rss sass scss sf2 svg
text toml ts tsv ttf txt webapp webmanifest webp woff woff2 xcf
xml yaml yml
Files like .pf_fragment, .pf_meta, and .wasm (generated by Pagefind for my site's search) are not supported on free accounts.
How do I set up the GitLab CI/CD variables?
Add your credentials to GitLab CI/CD variables (Settings → CI/CD → Variables):
NEOCITIES_USERNAMENEOCITIES_PASSWORDNEOCITIES_API_KEY
Mark these as Masked. Store them only in GitLab settings and never in the repository, since anyone with repository access could read them there. Also make sure neither the "protect variable" nor the "expand variable reference" flag is checked.
When does the pipeline deploy?
You do not always want to upload every file. The pipeline has three triggers:
- Automatic: Every commit to the main branch
- Manual: You can trigger it from GitLab's web interface, useful for re-running a deploy
- Forced full deploy: Set
FORCE_FULL_DEPLOY=truewhen you need to upload everything (for first-time setup or to repair a bad state)
For the very first deployment, the script uploads ALL supported files. There are no previous files to compare against. The same thing happens for manual triggers or when you force a full deploy.
How does the script decide what to upload?
Eleventy builds your src/ folder into _site/, but Git tracks changes in src/, so the script maps between them by stripping the src/ prefix from file paths.
# Remove src/ prefix if it exists
if [[ "$file" == src/* ]]; then
built_file="${file#src/}"
else
built_file="$file"
fi
The script prints debug output listing what it will upload:
DEBUG: Modified source files:
src/posts/my-new-post.md
src/assets/css/new-style.css
DEBUG: New source files:
src/images/cat-photo.jpg
DEBUG: Files to upload after mapping:
posts/my-new-post.md
assets/css/new-style.css
images/cat-photo.jpg
It also counts the files it is about to upload.
What optional GitLab CI features does it use?
These do not affect the deployment itself:
- Artifacts: The
_sitefolder gets saved, so you can download the built site if needed - Environment: GitLab tracks this as a "production" environment with your NeoCities URL
How does authentication fallback and file filtering work?
The script tries username/password first, then falls back to the API key. The test_auth function validates credentials before attempting upload, and prints error messages if authentication fails.
Both jq (if available) and grep patterns are used to parse JSON responses, handling variations in whitespace and formatting:
# Flexible grep pattern allows for whitespace
grep -q '"result":[[:space:]]*"success"'
Only modified files are uploaded after the first deployment. This reduces deployments from minutes to seconds:
# Get changed files between commits
git diff --name-only HEAD~1 HEAD
The regex automatically filters to only supported file types, preventing errors from trying to upload things like the Pagefind search index files and anything else unsupported:
grep -E "\.($SUPPORTED_EXTENSIONS)$"
What does the error output look like?
For authentication failures, it extracts the actual error message from NeoCities:
Error type: invalid_auth
Message: Invalid username or password
A debug feature prints just enough of your API key to verify it's correct without exposing the whole thing:
API Key length: 64 characters
First 8 chars: abcd1234...
Last 8 chars: ...efgh5678
The script also uses Node.js 18 in the Docker image, which matters if you're using newer JavaScript features in your build process.
What are the drawbacks?
Some features do not work on the NeoCities mirror, such as the Pagefind search (its index files are unsupported) and the contact form. A separate branch with a NeoCities-friendly version of the site would avoid mirroring broken features, but I have not built one.
How do I fix curl parsing errors in the pipeline?
Curl's progress meter interfered with response parsing, so I used -sS and redirected stderr:
curl -sS -w "\nHTTP_CODE:%{http_code}" [...] 2>/dev/null
Storing curl flags in variables causes word splitting issues. Use conditional curl commands directly instead:
if [ "$method" = "Username/Password" ]; then
response=$(curl -sS -u "${USER}:${PASS}" [...])
else
response=$(curl -sS -H "Authorization: Bearer ${KEY}" [...])
fi
Multi-line string assignments cause YAML parsing errors, so use echo -e with \n:
MODIFIED_FILES=$(echo -e "$MODIFIED_FILES\n$NEW_FILES")
How do I test the deployment?
The script tests authentication before attempting uploads, and GitLab CI keeps detailed logs. To verify, visit your NeoCities site to confirm the upload, then commit a small change and check that only the modified file is uploaded.
What should I know before trying this?
This took a lot of trial and error. When I attempted API-key-only authentication I kept getting failures, and username and password was more reliable for me, which is why the script tries it first.
Syntax will differ if your repository is not on GitLab. Sophie of localghost.dev has a write-up for deploying an Eleventy site to NeoCities from GitHub that I relied on for debugging.