Posts not showing correctly on jekyll (multiple site) blog -- only post code

I have a personal website built with jekyll and hosted on Github pages. I am trying to add a sub-site blog within the same domain. For this, I set up a blog.md page and followed the instructions from this website: https://www.garron.me/en/blog/multi-blog-site-jekyll.html. The idea is that if I access http://<mydomain>.com it will go to my personal website, and if I go to http://<mydomain>.com/blog it will go to a different site also set up with jekyll.

My file structure is different than what they suggest in the link above. It is like this:

/personalwebsite
   config.yml
   index.md
   (other personal website pages).md
   blog.md
   /_site
   /_layouts
   /_posts    

My index.md page is completely customized, and I wrote my own layout for that website. It is a static site and everything in _posts is ignored by it. My blog.md page is also on the root folder and it changes according to _config.yml. I am trying to use Github jekyll themes for it. The theme loads, but instead of showing the posts, it shows the code: enter image description here

This is what blog.md looks like:

---
layout: blog
title: the blog
permalink: blog
---

{% raw %}
{% for post in site.posts %}
   {% if post.categories contains 'blog' %}
   <div class="post">
       <h3 class="title"><a href="{{ post.url }}">{{ post.title }}</a></h3>
    <p class="meta">Date: {{ post.date }}</p>
    <div class="entry">
        {{ post.content | strip_html | truncatewords: 100 }}
    </div>
</div>
{% endif %}
{% endfor %}
{% endraw %}

And this is what a post looks like:

---
layout: post
title: New test
category: blog
---

This is a test post

If I remove the {% raw %} parts in blog.md, the posts show up like this: enter image description here

I have already checked that my posts are in the right place, the category parameter is filled in, the dates and post filenames are properly formatted. What am I doing wrong? Jekyll does not show any error messages other than a Github metadata warning:

GitHub Metadata: No GitHub API authentication could be found. Some fields may be missing or have incorrect data

Upvotes: 1

Views: 592

Answers (1)

David Jacquel
David Jacquel

Reputation: 52789

blog.md is a markdown file.

In markdown a four space indentation represents code or preformatted text. Kramdown will wrap this code in <pre> tag, resulting on what you actualy see on your site.

If you remove your indentation (or keep it under 4 spaces), your problem is solved.

{% for post in site.posts %}
{% if post.categories contains 'blog' %}
<div class="post">
 <h3 class="title"><a href="{{ post.url }}">{{ post.title }}</a></h3>
 <p class="meta">Date: {{ post.date }}</p>
 <div class="entry">
  {{ post.content | strip_html | truncatewords: 100 }}
 </div>
</div>
{% endif %}
{% endfor %}

Upvotes: 3

Related Questions