Add --drafts flag #769

Merged
merged 11 commits into from Mar 4, 2013

Projects

None yet

6 participants

@scribu
scribu commented Jan 20, 2013

I really liked the _drafts folder idea suggested by @mojombo a while ago:

It might be nice to have a --drafts switch that just picks up
and publishes stuff in a _drafts directory if it exists.

So, this pull request allows you to do this:

jekyll serve --watch --drafts

Related: #513

@mattr-

Please use spaces instead of a tab here

@mattr-

Please use spaces instead of a tab here

@scribu
scribu commented Jan 31, 2013

Fixed. Thanks for reviewing.

@mattr-
Member
mattr- commented Jan 31, 2013

👍

@scribu
scribu commented Feb 2, 2013

After using this for a while, maybe it would make sense to exclude the date from the draft file names:

_drafts/some-post.md
_drafts/another-post.md

since most of the time you're not sure when the draft will be ready to get published.

Of course, that would mean that Jekyll would need to generate some arbitrary date for each draft. Using the file's lastmodified attribute would work pretty well, I think.

Authors should still be able to set the date in the front matter, if they wish.

@parkr
Member
parkr commented Feb 3, 2013

@scribu I like that. You might need to change the filename, though. Post#process will freak out without the date.

@scribu
scribu commented Feb 9, 2013

The travis build reports lots of errors related to the unit tests.

I see failures when running rake features, but when I run rake test, I just get a link to the coverage report.

@scribu
scribu commented Feb 9, 2013

Yay, all tests pass again.

@parkr parkr and 1 other commented on an outdated diff Feb 10, 2013
lib/jekyll/site.rb
@@ -5,7 +5,7 @@ module Jekyll
class Site
attr_accessor :config, :layouts, :posts, :pages, :static_files,
:categories, :exclude, :include, :source, :dest, :lsi, :pygments,
- :permalink_style, :tags, :time, :future, :safe, :plugins, :limit_posts,
+ :permalink_style, :tags, :time, :future, :safe, :plugins, :limit_posts, :show_drafts,
@parkr
parkr Feb 10, 2013 Jekyll member

Please put this option on the next line, with :keep_files. We have a column width limit!

@scribu
scribu Feb 10, 2013

Ok, and what is that limit? 'cause that line already had 90 chars without :show_drafts.

@scribu
scribu Feb 10, 2013

In general, I can't find a link to a page describing the coding standards anywhere.

@parkr
parkr Feb 10, 2013 Jekyll member

As this is a @mojombo project (primarily), we tend to use the GitHub style guide for Ruby.

@parkr parkr commented on an outdated diff Feb 10, 2013
lib/jekyll/site.rb
@@ -160,7 +173,7 @@ def read_directories(dir = '')
# Read all the files in <source>/<dir>/_posts and create a new Post
# object with each one.
#
- # dir - The String relative path of the directory to read.
+ # dir - The String relative path of the directory to read.
@parkr
parkr Feb 10, 2013 Jekyll member

?

@parkr parkr and 1 other commented on an outdated diff Feb 10, 2013
lib/jekyll/site.rb
- self.posts.sort!
+ # Read all the files in <source>/<dir>/_drafts and create a new Post
+ # object with each one.
+ #
+ # dir - The String relative path of the directory to read.
@parkr
parkr Feb 10, 2013 Jekyll member

Yeah, this extra space isn't needed (between "dir" and "-").

@scribu
scribu Feb 10, 2013

Yeah, was a leftover from intermediate commits. Will fix.

@parkr parkr and 1 other commented on an outdated diff Feb 28, 2013
lib/jekyll/post.rb
@@ -66,6 +65,11 @@ def initialize(site, source, dir, name)
end
end
+ # Get the full path to the directory containing the post files
+ def get_base(source, dir)
@parkr
parkr Feb 28, 2013 Jekyll member

Perhaps containing_dir, dirname or something similar here. Ruby idioms tend to disagree with get_- and set_-prefixed methods.

@parkr parkr commented on the diff Feb 28, 2013
lib/jekyll/site.rb
- self.posts.sort!
+ # Read all the files in <source>/<dir>/_drafts and create a new Post
+ # object with each one.
+ #
+ # dir - The String relative path of the directory to read.
+ #
+ # Returns nothing.
+ def read_drafts(dir)
+ base = File.join(self.source, dir, '_drafts')
@parkr
parkr Feb 28, 2013 Jekyll member

Hm, this is used here and in Draft. Maybe this should be a setting, like drafts_dir on Site and we can use that in all the cases where getting the drafts dir path is required.

@scribu
scribu Mar 3, 2013

I don't think this should be a setting. I've attempted to refactor things to avoid the duplication, but it gets hairy and dilutes the focus of this pull request.

Besides, it's the same problem with '_posts'.

@parkr parkr commented on the diff Feb 28, 2013
lib/jekyll/draft.rb
+ name =~ MATCHER
+ end
+
+ # Get the full path to the directory containing the draft files
+ def get_base(source, dir)
+ return File.join(source, dir, '_drafts')
+ end
+
+ # Extract information from the post filename.
+ #
+ # name - The String filename of the post file.
+ #
+ # Returns nothing.
+ def process(name)
+ m, slug, ext = *name.match(MATCHER)
+ self.date = File.mtime(File.join(@base, name))
@parkr
parkr Feb 28, 2013 Jekyll member

👍

@mojombo mojombo referenced this pull request Mar 4, 2013
Merged

Drafts fixup #833

@mojombo mojombo merged commit 1a35128 into jekyll:master Mar 4, 2013

1 check passed

Details default The Travis build passed
@mojombo
Collaborator
mojombo commented Mar 4, 2013

This is now merged into master. Thanks for the code, this is an awesome feature!

@scribu scribu deleted the scribu:drafts branch Mar 4, 2013
@nathanstaines

Any idea when this feature will be available via the Ruby gem?

@parkr
Member
parkr commented Mar 5, 2013

Soonish. No exact time :-)

@tillcarlos

Yeah, what a great feature! However, I would like to know if I can make a if condition checking for the draft stage of a post. Right now I cannot find another solution than matching the date against the Time.now (which is not that elegant).

I have searched the documentation and a bit in in the code. Can someone help me where to find it? Thanks so much!

@parkr
Member
parkr commented Sep 4, 2013

@tielefeld There is presently no way to exclude drafts based on time. When using the --drafts flag, all drafts are added. :)

@tillcarlos

It's alright. I used a tag for it "draft" which I remove when uploading. However, I switched to wordpress for my new project. pleasedontkillme! tielefeld.com is still jekyll :)

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