I wrote a plugin to display future posts during recent Jekyll upgrade. As you can see it is used on the main page, so I will share it with you.
The main part of the process is to store parsed future posts as a snippet and then include it on the main page.
Create future_list.rb
plugin to get and store future posts.
$ cat _plugins/future_list.rb
module Jekyll class FutureList < Page def initialize(site, base, dir, posts) @site = site @base = base @dir = dir @name = 'future.html' self.process(@name) self.read_yaml(File.join(base, '_layouts'), 'future_list.html') self.data['posts'] = posts end end class FutureListGenerator < Generator safe true def generate(site) if site.layouts.key? 'topic_list' config = site.config config["future"] = true newsite = Jekyll::Site.new(site.config) newsite.read posts=Hash.new; newsite.posts.docs.map do |entry| if entry.date > Time.now posts[entry["date"]] = entry["title"] end end dir = 'snippets' write_future_list(site, dir, posts) end end def write_future_list(site, dir, topics) index = FutureList.new(site, site.source, dir, topics) index.render(site.layouts, site.site_payload) index.write(site.dest) site.pages << index end end end
Create simple future_list.html
layout file for future posts.
$ cat _layouts/future_list.html
--- layout: null --- <div class="post-wrap"> <div class="post-inner"> <div class="entry-content"> {% for post in page.posts limit: 5 %} <p><strong>{{ post[1] }}</strong><br/> <em>scheduled for {{ post[0] | date_to_string }}</em></p> {% endfor %} </div> <div class="clearfix"></div> </div><!-- End post-inner --> </div><!-- End post-wrap -->
Use this layout to to customize the look and define number of posts (
5
in this example).Modify main index.html
to include created snippet.
<h2 class="page-title">Upcoming posts</h2> {% include_relative _site/snippets/future/index.html %}
Rebuild the site and enjoy.