Add category to rake new_post

This commit is contained in:
Michael Rose 2014-02-27 15:00:37 -05:00
parent 938c653c71
commit 0cdcde10bf
5 changed files with 6 additions and 20 deletions

3
.gitignore vendored
View file

@ -4,5 +4,4 @@ _site
*.sublime-workspace *.sublime-workspace
codekit-config.json codekit-config.json
node_modules node_modules
_asset_bundler_cache _asset_bundler_cache
Gemfile.lock

View file

@ -1,8 +0,0 @@
source 'https://rubygems.org'
gem 'jekyll'
gem 'kramdown'
gem 'coderay'
gem 'rake'
gem 'activesupport'
gem 'stringex'

View file

@ -25,6 +25,7 @@ task :new_post, :title do |t, args|
if File.exist?(filename) if File.exist?(filename)
abort("rake aborted!") if ask("#{filename} already exists. Do you want to overwrite?", ['y', 'n']) == 'n' abort("rake aborted!") if ask("#{filename} already exists. Do you want to overwrite?", ['y', 'n']) == 'n'
end end
category = get_stdin("Enter category name to group your post in (leave blank for none): ")
tags = get_stdin("Enter tags to classify your post (comma separated): ") tags = get_stdin("Enter tags to classify your post (comma separated): ")
puts "Creating new post: #{filename}" puts "Creating new post: #{filename}"
open(filename, 'w') do |post| open(filename, 'w') do |post|
@ -32,6 +33,7 @@ task :new_post, :title do |t, args|
post.puts "layout: post" post.puts "layout: post"
post.puts "title: \"#{title.gsub(/&/,'&')}\"" post.puts "title: \"#{title.gsub(/&/,'&')}\""
post.puts "modified: #{Time.now.strftime('%Y-%m-%d %H:%M:%S %z')}" post.puts "modified: #{Time.now.strftime('%Y-%m-%d %H:%M:%S %z')}"
post.puts "category: [#{category}]"
post.puts "tags: [#{tags}]" post.puts "tags: [#{tags}]"
post.puts "image:" post.puts "image:"
post.puts " feature: " post.puts " feature: "

View file

@ -40,23 +40,15 @@
</div><!-- /#main --> </div><!-- /#main -->
<div class="footer-wrap"> <div class="footer-wrap">
{% if site.related_posts.size > 0 %}<div class="related-articles"> <div class="related-articles">
<h4>You might also enjoy <small class="pull-right">(<a href="{{ site.url }}/posts/">View all posts</a>)</small></h4> <h4>You might also enjoy <small class="pull-right">(<a href="{{ site.url }}/posts/">View all posts</a>)</small></h4>
<ul> <ul>
{% for post in site.related_posts limit:3 %} {% for post in site.related_posts limit:3 %}
{% assign match = false %}
{% for category in post.categories %}
{% if page.categories contains category %}
{% assign match = true %}
{% endif %}
{% endfor %}
{% if match %}
<li><a href="{{ site.url }}{{ post.url }}" title="{{ post.title }}">{{ post.title }}</a></li> <li><a href="{{ site.url }}{{ post.url }}" title="{{ post.title }}">{{ post.title }}</a></li>
{% endif %}
{% endfor %} {% endfor %}
</ul> </ul>
<hr /> <hr />
</div><!-- /.related-articles -->{% endif %} </div><!-- /.related-articles -->
<footer> <footer>
{% include _footer.html %} {% include _footer.html %}
</footer> </footer>

View file

@ -116,6 +116,7 @@ There are two rake tasks that can be used to create a new post or page with all
rake new_post rake new_post
Enter a title for your post: My Awesome Post Enter a title for your post: My Awesome Post
Enter category name to group your post in (leave blank for none): blog
Enter tags to classify your post (comma separated): web development, code Enter tags to classify your post (comma separated): web development, code
Creating new post: _posts/2014-02-10-my-awesome-post.md Creating new post: _posts/2014-02-10-my-awesome-post.md
{% endhighlight %} {% endhighlight %}