0
votes

I'm trying to turn my one page website here over to Jekyll.

I'm not quite sure that I have everything set up correctly. I'm trying have X amount of areas that I can create custom repeatable content (jobs, education, portfolio), but I cannot seem to get them to display.

Because I am only going to have one page I did all the work in the default.html layout (I don't think this is correct) creating loop for say jobs, then creating a folder called 'jobs' in the route of the directory where I have a sub directory '_posts' containing custom mark down files. Is this correct?

Here is my code relating to the question.

default.html snippet

<h3 class="secondary-heading">Employment</h3>
    <ul class="history-list clearfix">
    {% for post in site.categories.JOBS %}
      <li class="item four columns offset-by-one alpha">
       <i class="indicator"></i>
       <div class="main-info clearfix">
          <h5 class="tertiary-heading title alighleft">{{ post.title }}</h5>
          <h6 class="dates alignright">{{ post.length }}</h6>
       </div>
       <h6 class="meta-info">{{ post.position }}</h6>
       <p class="description">
        {{ post.excerpt }}
       </p>
     </li>
    {% endfor %}
   </ul>

markdown example

title: test 
category: jobs 
length: April 2010 – April 2012 
position: Junior Developer
--- 
Content to be displayed 
2

2 Answers

2
votes

For markdown files to be processed as posts, they need to reside in the _posts directory which should be in the root directory of your Jekyll blog.

The directory structure you have described above looks like the following:

MyBlog
+-----jobs
      +-----_posts

But it needs to look like the following:

MyBlog
+-----_posts

Then to use the categories, you specify it in the front-matter as you have done. Categories are meant to be a means of viewing posts specific to a category at a URL for that category.

If you want to display certain categories of posts in specific places of your page, then you will likely have to use the Liquid Templating syntax to loop through your posts in each of those places only displaying the ones that match a certain category.

Also, if you didn't want to muck up the categories feature doing this, you could specify some other property in the front-matter that you differentiate based on.

1
votes

I figured out the problem. First one is the folder structure. Simply keep all the postfiles in the _posts/ file in the root directory. The second one is the capitalization of the category name in your liquid tag. Although there are no semantic differences between JOBS and jobs, when used in liquid arguments, they act in a weird way. So try to keep them in lower case. Simply replace the line

{% for post in site.categories.JOBS %}

with this

{% for post in site.categories.jobs %}

This won't solve your problem right away. Jekyll expects you to wrap your posts YAML matter between --- 3 dashes. So you've to use the following format for you post markdown and everything will work:

---
title: test 
category: jobs 
length: April 2010 – April 2012 
position: Junior Developer
--- 
Content to be displayed