I’m working on a website with numerous web pages but no blog or blog posts. I would like to move all the pages (including the index.html) out of the root of the project and into a separate directory (maybe _pages). I have tried this many ways but I cannot get Jekyll to recognize the pages when they are in a separate directory. What is the best way to go about this as I am sure it can be done. Is there something that needs to be in the _config.yml or GEMFILE for this to work?
It is probably best to keep index.html (or index.md) at the root. You can place all your content into another folder, but generally, using an _
to prefix the folder is a bad idea with Jekyll. Try calling the folder content
or pages
and then see if the problem persists. If it does persist and you happen to have the site available in a public Git repo, please send the link.
There is no problem with this approach.
I’ve done it before.
_pages/
abc.md
def.md
index.md
I can’t remember why I chose the underscore approach but it works fine.
The bit you are missing is in your config. Add a section. Otherwise Jekyll will ignore the directory.
include:
- _pages
You could also name your directory pages
and then Jekyll will see it by default. But… Jekyll will process the files as static files so .md will output as .md. So to fix that you still would have to include it.
include:
- pages
Side note. Either way your output files will be either
_pages/abc.html
pages/abc.html
Unless you set permalink for each file in the pages directory.
e.g.
---
title: ABC
permalink: /abc.html
---
To output as
/abc.html
Or maybe there is a way to set it under defaults
in the config for the whole pages directory. Like using the filename but not the directory name.
Go setup a defaults structure in your config: Front Matter Defaults | Jekyll • Simple, blog-aware, static sites
Then set the permalink: "/:title:output_ext"
for your folder
It will render everything in that folder at the root, without the files being in the root.
Thanks @Uberfuzzy , that was the solution I was thinking of.
It works!!! Thanks for all your help: @MichaelCurrin , @Uberfuzzy , @BillRaymond