Install Octopress to create new posts/pages
This commit is contained in:
parent
873eb786e9
commit
a2417a58d4
5 changed files with 39 additions and 90 deletions
90
Rakefile.rb
90
Rakefile.rb
|
@ -1,90 +0,0 @@
|
||||||
require "rubygems"
|
|
||||||
require "bundler/setup"
|
|
||||||
require "stringex"
|
|
||||||
|
|
||||||
## -- Config -- ##
|
|
||||||
|
|
||||||
posts_dir = "_posts" # directory for blog files
|
|
||||||
new_post_ext = "md" # default new post file extension when using the new_post task
|
|
||||||
new_page_ext = "md" # default new page file extension when using the new_page task
|
|
||||||
|
|
||||||
|
|
||||||
#############################
|
|
||||||
# Create a new Post or Page #
|
|
||||||
#############################
|
|
||||||
|
|
||||||
# usage rake new_post
|
|
||||||
desc "Create a new post in #{posts_dir}"
|
|
||||||
task :new_post, :title do |t, args|
|
|
||||||
if args.title
|
|
||||||
title = args.title
|
|
||||||
else
|
|
||||||
title = get_stdin("Enter a title for your post: ")
|
|
||||||
end
|
|
||||||
filename = "#{posts_dir}/#{Time.now.strftime('%Y-%m-%d')}-#{title.to_url}.#{new_post_ext}"
|
|
||||||
if File.exist?(filename)
|
|
||||||
abort("rake aborted!") if ask("#{filename} already exists. Do you want to overwrite?", ['y', 'n']) == 'n'
|
|
||||||
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): ")
|
|
||||||
puts "Creating new post: #{filename}"
|
|
||||||
open(filename, 'w') do |post|
|
|
||||||
post.puts "---"
|
|
||||||
post.puts "layout: post"
|
|
||||||
post.puts "title: \"#{title.gsub(/&/,'&')}\""
|
|
||||||
post.puts "modified: #{Time.now.strftime('%Y-%m-%d %H:%M:%S %z')}"
|
|
||||||
post.puts "category: [#{category}]"
|
|
||||||
post.puts "tags: [#{tags}]"
|
|
||||||
post.puts "image:"
|
|
||||||
post.puts " feature: "
|
|
||||||
post.puts " credit: "
|
|
||||||
post.puts " creditlink: "
|
|
||||||
post.puts "comments: "
|
|
||||||
post.puts "share: "
|
|
||||||
post.puts "---"
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
# usage rake new_page
|
|
||||||
desc "Create a new page"
|
|
||||||
task :new_page, :title do |t, args|
|
|
||||||
if args.title
|
|
||||||
title = args.title
|
|
||||||
else
|
|
||||||
title = get_stdin("Enter a title for your page: ")
|
|
||||||
end
|
|
||||||
filename = "#{title.to_url}.#{new_page_ext}"
|
|
||||||
if File.exist?(filename)
|
|
||||||
abort("rake aborted!") if ask("#{filename} already exists. Do you want to overwrite?", ['y', 'n']) == 'n'
|
|
||||||
end
|
|
||||||
tags = get_stdin("Enter tags to classify your page (comma separated): ")
|
|
||||||
puts "Creating new page: #{filename}"
|
|
||||||
open(filename, 'w') do |page|
|
|
||||||
page.puts "---"
|
|
||||||
page.puts "layout: page"
|
|
||||||
page.puts "permalink: /#{title.to_url}/"
|
|
||||||
page.puts "title: \"#{title}\""
|
|
||||||
page.puts "modified: #{Time.now.strftime('%Y-%m-%d %H:%M')}"
|
|
||||||
page.puts "tags: [#{tags}]"
|
|
||||||
page.puts "image:"
|
|
||||||
page.puts " feature: "
|
|
||||||
page.puts " credit: "
|
|
||||||
page.puts " creditlink: "
|
|
||||||
page.puts "share: "
|
|
||||||
page.puts "---"
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def get_stdin(message)
|
|
||||||
print message
|
|
||||||
STDIN.gets.chomp
|
|
||||||
end
|
|
||||||
|
|
||||||
def ask(message, valid_options)
|
|
||||||
if valid_options
|
|
||||||
answer = get_stdin("#{message} #{valid_options.to_s.gsub(/"/, '').gsub(/, /,'/')} ") while !valid_options.include?(answer)
|
|
||||||
else
|
|
||||||
answer = get_stdin(message)
|
|
||||||
end
|
|
||||||
answer
|
|
||||||
end
|
|
10
_octopress.yml
Normal file
10
_octopress.yml
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
# Default extensions
|
||||||
|
post_ext: md
|
||||||
|
page_ext: md
|
||||||
|
|
||||||
|
# Found in _templates/
|
||||||
|
post_layout: post
|
||||||
|
page_layout: page
|
||||||
|
|
||||||
|
# Format titles with titlecase?
|
||||||
|
titlecase: true
|
9
_templates/archive
Normal file
9
_templates/archive
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
---
|
||||||
|
layout: post-index
|
||||||
|
title: {{ title }}
|
||||||
|
permalink:
|
||||||
|
modified:
|
||||||
|
excerpt:
|
||||||
|
image:
|
||||||
|
feature:
|
||||||
|
---
|
10
_templates/page
Normal file
10
_templates/page
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
---
|
||||||
|
layout: {{ layout }}
|
||||||
|
title: {{ title }}
|
||||||
|
date: {{ date }}
|
||||||
|
modified:
|
||||||
|
excerpt:
|
||||||
|
tags: []
|
||||||
|
image:
|
||||||
|
feature:
|
||||||
|
---
|
10
_templates/post
Normal file
10
_templates/post
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
---
|
||||||
|
layout: {{ layout }}
|
||||||
|
title: {{ title }}
|
||||||
|
modified:
|
||||||
|
categories: {{ dir }}
|
||||||
|
excerpt:
|
||||||
|
tags: []
|
||||||
|
image:
|
||||||
|
feature:
|
||||||
|
---
|
Loading…
Reference in a new issue