Sub topic 8
How Jekyll processing works and when to disable it
This chapter assumes you can commit and push with Git, read YAML, and write basic HTML. It also assumes you already have a site published from a branch, as covered in the earlier chapters.
What Jekyll does on a branch-published site
Jekyll is a static site generator written in Ruby. When you publish from a branch and folder, GitHub Pages runs Jekyll on that folder before serving it. This happens even if you never wrote a Jekyll site. A plain index.html passes through unchanged, so the step is easy to miss.
Jekyll changes your content in these ways:
- Markdown files (
.md) become HTML pages. - Files that start with a YAML block between
---lines (front matter) are processed, and Liquid tags such as{{ page.title }}are filled in. - Files and folders whose names start with an underscore or a dot are not copied to the output. Examples are
_drafts,_site, and.git. - Files that match
excluderules in_config.ymlare skipped.
Everything else is copied as it is.
Where Jekyll causes problems
Jekyll is harmless for simple HTML. Three situations tend to cause trouble.
- Missing folders. A framework build might output a folder such as
_nextor_astro. Jekyll skips folders that start with an underscore, so the page loads but its scripts and styles return 404. - Curly braces in content. A page that contains
{{ something }}or{% something %}, such as a JavaScript template, can be read as Liquid. If it has front matter, Jekyll tries to evaluate those tags and may fail the build or change your text. - Slow or failing builds. Jekyll must parse every file it processes. A build error in a file you never meant Jekyll to touch can stop a deployment.
Your site needs Jekyll only if you actually use it, for example with a theme, Markdown pages, or layouts.
Disabling Jekyll with .nojekyll
An empty file named .nojekyll at the root of the published folder tells GitHub Pages to skip Jekyll and serve the files as they are.
touch .nojekyll
git add .nojekyll
git commit -m "Disable Jekyll processing"
git pushThe file must be in the folder you chose as the publishing source. If you publish from /docs, put it in docs/, not in the repository root. The file must also be committed, since a hidden file can be left out by tools that ignore dotfiles. Check with git ls-files .nojekyll.
Jekyll and GitHub Actions publishing
When you publish with a GitHub Actions workflow, GitHub Pages does not run its built-in Jekyll step. Your workflow decides what is uploaded. The workflow in this tutorial uploads the site folder with actions/upload-pages-artifact, and those files are served as they are. A .nojekyll file is not needed there.
If you want Jekyll with a workflow, add a build step yourself, for example with actions/jekyll-build-pages, and upload its output.
Choosing
| Situation | Choice |
|---|---|
| Hand-written HTML, CSS, and JavaScript | Add `.nojekyll`, or leave it off if nothing breaks |
| Output of a framework build with underscore folders | Add `.nojekyll`, or publish with Actions |
| Markdown pages with a theme or layouts | Keep Jekyll on |
| Need full control of the build | Publish with Actions |
Checking the result
If a file you expect is missing, open the site's URL for that file directly. A 404 for a file under an underscore folder points to Jekyll. Then open the Actions tab and read the run named "pages build and deployment". Errors from Jekyll appear in its log.
Exercise
Your site is published from the /docs folder of the main branch. It was built by a framework and has a docs/_assets/app.js file. The page loads, but the script returns 404. What is the likely cause, and what is the fix?
Show answer
Jekyll skips folders whose names start with an underscore, so _assets was not copied to the published site. Add an empty .nojekyll file inside docs/, commit and push it, and wait for the new deployment. Renaming the folder to remove the underscore would also work.
Exercise
You publish with a GitHub Actions workflow that uploads the site folder. Do you need a .nojekyll file? Explain why.
Show answer
No. With Actions publishing, GitHub Pages does not run its built-in Jekyll step. The workflow uploads the files you point it at, and they are served as they are.