Skip to content

Instantly share code, notes, and snippets.

@wtnabe
Last active May 5, 2016 14:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wtnabe/4e57c3fc01665b5d32ec621590e9c5fe to your computer and use it in GitHub Desktop.
Save wtnabe/4e57c3fc01665b5d32ec621590e9c5fe to your computer and use it in GitHub Desktop.
Jekyll drafts
# Returns whether the document is a draft. This is only the case if
# the document is in the 'posts' collection but in a different
# directory than '_posts'.
#
# Returns whether the document is a draft.
def draft?
data['draft'] ||= relative_path.index(collection.relative_directory).nil? && collection.label == "posts"
end
@wtnabe
Copy link
Author

wtnabe commented May 5, 2016

_で始まらない通常のディレクトリか、 _posts/ ディレクトリ以外に置かれているものはすべて draft 扱いになり、variable draft に true か false が入る。{% %} の中では TrueClass or FalseClass で、 {{ }} の中では "true" or "false" で返ってくる。

collection を定義して posts 以外に増やしたとしてもそれらの collection に対しては draft の機能を使えないように見えるけど、どうなんだろう?

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