0

I have a Jekyll blog where the main page is a bunch of links to posts, but where I also want to include a link to a project's gh-pages page and I want the list to stay sorted by date. Right now, I'm just manually inserting it at the top of the page.

  <ul class="posts">
    <li>
      <span class="post-date">Jul 8, 2015</span>
      <a class="post-link" href="/QuisCustodiet/">The Most Influential Works, According to TvTropes</a>
    </li>
    {% for post in site.posts %}
      <li>
        <span class="post-date">{{ post.date | date: "%b %-d, %Y" }}</span>
        <a class="post-link" href="{{ post.url | prepend: site.baseurl }}">{{ post.title }}</a>
      </li>
    {% endfor %}
  </ul>

This looks okay, but it will break in a week or two when I make another post. Is there a way to create another "post" and insert it into the list of site.posts in a way that it stays sorted? Is there some other much better way of doing this that I don't know about?

Joshua Snider
  • 705
  • 1
  • 8
  • 34

1 Answers1

2

If I understand your problem right, you want to have some "special project posts" in your list of posts that are only links to another specific project site but have a date and therefore can be sorted together with the other posts.

Here is what I came up with:

You create an empty Post in _posts/ with front matter like this:

---
layout: post
title: "Project Example"
customlink: http://www.example.org
date:   2015-07-12 12:50:25
---

The customlink attribute is for the link to your project page. In your html, where you list all your posts, you make an if-statement to check for the attribute and handle it properly. Like this for example:

<ul>
  {% for post in site.posts %}
    <li>
      {% if post.customlink %}
        <a href="{{ post.customlink }}">{{ post.title }}</a>
      {% else %}
        <a href="{{ post.url }}">{{ post.title }}</a>
      {% endif %}
    </li>
  {% endfor %}
</ul>

Your project post is treated as your other posts and sorted with them by date, but its link will direct the user to your project page.

Jekyll will still create the html for this post and serve it like all the other posts under a specific path. To prevent this you could add an empty permalink attribute in the posts front matter like permalink: "" and your post would lie under the root of your blog. Jekyll would still create a ".html" file for this post in the _site folder.

You need to create the posts for every external project manually but I do not know a better solution.