Skip to content

Instantly share code, notes, and snippets.

@navilan
Last active December 17, 2015 18:09
Show Gist options
  • Save navilan/5651355 to your computer and use it in GitHub Desktop.
Save navilan/5651355 to your computer and use it in GitHub Desktop.
How to create draft posts using hyde.

This shows how to add draft posts feature to hyde. This will be a part of hyde 0.8.7.

Create a fresh hyde test site using hyde 0.8.6

mkdir ~/test_drafts
cd ~/test_drafts
hyde create

Generate and test the site to make sure you see 3 blog posts by default

  1. Generate and serve
hyde gen -r
hyde serve
  1. Open http://localhost:8080/blog to make sure you see "A Happy Post", "An Angry Post" and "A Sad Post" listed.

Add the drafts plugin

  1. Add drafts.py to ~/test_drafts
  2. Make the edits to site.yaml as shown in this gist
  3. Add prod.yaml to ~/test_drafts
  4. Mark content/blog/angry-post.html as draft as shown in this gist.

Test the drafts plugin

  1. Generate the site in production mode

Drafts are not enabled in development mode.

hyde gen -r -c prod.yaml
hyde serve -c prod.yaml
  1. Open http://localhost:8080/blog to make sure you only see "A Happy Post" and "A Sad Post" listed.
---
title: An Angry Post
description: >
Temper. Temper. Temper.
created: !!timestamp '2011-01-01 10:00:00'
tags:
- angry
- thoughts
is_draft: true # Mark the post as draft. Change the value or delete to make it published.
---
....
from hyde.plugin import Plugin
class DraftPlugin(Plugin):
def begin_site(self):
in_production = self.site.config.mode.startswith('prod')
if not in_production:
self.logger.info('Not production')
return
for resource in self.site.content.walk_resources():
if not resource.is_processable:
self.logger.info('Not processable')
continue
try:
is_draft = resource.meta.is_draft
except AttributeError:
is_draft = False
resource.is_processable = not is_draft
resource.meta.is_processable = not is_draft
self.logger.info(
'%s is%s draft' % (resource,
'' if is_draft else ' not'))
extends: site.yaml
mode: production
# Just edits
...
plugins:
- hyde.ext.plugins.meta.MetaPlugin
- hyde.ext.plugins.meta.AutoExtendPlugin
- hyde.ext.plugins.meta.SorterPlugin
- hyde.ext.plugins.meta.TaggerPlugin
- hyde.ext.plugins.text.SyntextPlugin
- hyde.ext.plugins.text.TextlinksPlugin
- draft.DraftPlugin # Add the draft plugin
meta:
nodemeta: meta.yaml
created: !!timestamp 2010-01-01 00:00:00
author: Lakshmi Vyasarajan
is_draft: false # Default value for the is_draft metavar
...
sorter:
time:
attr:
- meta.created
reverse: true
filters:
source.kind: html
meta.listable: true
meta.is_draft: false # Make sure draft files are not included in listing
...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment