I have used collections in my Jekyll website for GitHub Pages. I'm trying to get Jekyll to see the Markdown files inside the collection folder, _projects
.
Here's a rundown of the file structure:
root
│
├─ _projects
│ │
│ ├─ project_1.md
│ └─ project_2.md
│
└─ /*Rest of the Jekyll folders and files, _posts, _includes, etc.*/
At the moment, I realized that you must put the Markdown files in the root, so Jekyll can be able to see and parse the files to display them when after you clicked a link that points to them via permalinks. But it cannot "see" the Markdown files if the files are not in the root folder, after testing quite a while.
Is there a way to let Jekyll see and parse files inside the subfolder, _projects
, just like how it can see files in the root folder? Maybe I need to set something up in the _config.yml
, I guess?
Thanks in advance.
The OP tom-mai78101 comments the the article "Jekyll Blog From a Subdirectory" from Hemanth.HM
has confirmed my guesses that subdirectories are only defined by the permalinks in the Markdown files, and not through the folders within the repository.
I quickly wrote a code snippet, and created a few Markdown files shown here, I am now able to create webpages using Markdown files nested within the _posts
folder.
In short, there's no need to use collections in the _config.yml
, and just use the default _posts
.
It would've been better if there is a way to change the default permalink setup in the _config.yml
.
The question "Jekyll not generating pages in subfolders" could be relevant, in order to make some pages being generated in a subfolder.
Or you could use a different baseurl. (Jekyll 1.0+)
Or use the _include
folder (see "Jekyll paginate blog
as subdirectory")
Or, The article "Running Your Jekyll Blog from a Subdirectory" (from Josh Branchaud) seems to address your situation:
Solution 1
Create a directory called blog
in your public html directory (that is, in the directory that your domain points to).
Assuming you are using some sort of deployment scheme (GitHub pages or deployment methods), you need to have that deployment scheme tell Jekyll to deploy to the blog
directory instead of the directory it is currently using.
(in your case blog
would be projects
)
Solution 2
Start by creating a directory locally where you have your Jekyll blog
setup.
This directory will sit along side _posts
, _site
, css
, etc.
This is only going to hold non-post files such as index.html
.
The blog
posts will still go in the _posts directory.
Next, we are going to tell Jekyll that we want it to take our blog posts and put them inside a directory called blog when it generates them.
This can be done by adding a permalink setting to the _config.yml
file.
Add a line like this to the top of the file:
permalink: /blog/:categories/:year/:month/:day/:title.html.
The default (which you have probably been using) puts posts
in a directory structure starting with the category, followed by the date, and finally with the title of the blog post as the name of the html file.
Which, spelled out would be
/:categories/:year/:month/:day/:title.html.
Does that look familiar? Sure does. It is what we have used above, sans the /blog
part.
We are essentially emulating the default directory structure and while adding our blog
directory at the beginning.
Lastly, you are going to want to add an index.html
file to the blog
directory that you created.
This way, when a person goes to mydomain.com/blog/
they can see what blog
posts you have to offer.
This index page is going to more or less mirror exactly what you had setup originally for listing your blog
posts.
Edit : My first answer was completely wrong. I was talking
_config.yml
collections:
project:
output: true
_project/project_1.md
---
layout: project
title: project
---
## Yo!
Project in **strong** yo `inline code`
some code
yolo !
_layouts/project.html
<!DOCTYPE html>
<html>
{% include head.html %}
<body>
{% include header.html %}
<div class="page-content">
<div class="wrapper">
{{ content }}
</div>
</div>
{% include footer.html %}
</body>
</html>
You now have a project/project_1.html
page.
No need to use include:
parameter in order to Jekyll to see collection folder or subfolder.
exclude:
parameter can be used to ignore a subfolder in the collection.
End Edit
Old answer (nothing to do with collection)
Your _project
folder is ignored by Jekyll, just like any underscored folder
To force Jekyll to parse files in this folder, in your _config.yml
you can add :
include:
- _project
jekyll build
and all is good !