Skip to content

Instantly share code, notes, and snippets.

@benjaminsnorris
Last active October 20, 2017 11:19
Show Gist options
  • Save benjaminsnorris/1248c19efce6da007d5017d7b3cfaf1e to your computer and use it in GitHub Desktop.
Save benjaminsnorris/1248c19efce6da007d5017d7b3cfaf1e to your computer and use it in GitHub Desktop.
Jekyll changes to support public drafts
collections:
drafts:
output: true
defaults:
-
scope:
path: ""
type: drafts
values:
layout: draft
---
layout: post
meta_robots: noindex
---
{{ content }}
---
layout: page
title: Drafts
permalink: /drafts/
meta_robots: noindex
---
<p>These are draft posts for previewing.</p>
<div class="posts">
{% assign sorted = (site.drafts | sort: 'date') | reverse %}
{% for draft in sorted %}
<div class="post py2">
<p class="post-meta h5">{{ draft.date | date: site.date_format }}</p>
<a href="{{ draft.url }}" class="post-link"><h3 class="post-title">{{ draft.title }}</h3></a>
{% if draft.categories.size > 0 %}
<span class="post-meta small">
{% for category in draft.categories %}
<a href="{{ category }}" class="category">{{ category }}</a>
{% endfor %}
</span>
{% endif %}
</div>
{% endfor %}
</div>
{% if page.meta_robots %}
<meta name="robots" content="{{ page.meta_robots }}">
{% elsif layout.meta_robots %}
<meta name="robots" content="{{ layout.meta_robots }}">
{% else %}
<meta name="robots" content="all">
{% endif %}
@blapid
Copy link

blapid commented Oct 20, 2017

Thanks, this has helped me a lot!
I had to make the following changes though:

  1. draft.html line 9: I had to remove the parenthesis as I was getting a Liquid warning
  2. I wanted to remove the drafts index link from the main navigation. To do that, I had to override the header.html file under _includes and change it to the following:
    {% if my_page.title and my_page.title != 'Drafts' %}
            <a class="page-link" href="{{ my_page.url | relative_url }}">{{ my_page.title | escape }}</a>
    {% endif %}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment