Last active
January 1, 2016 22:09
-
-
Save alalwww/8207758 to your computer and use it in GitHub Desktop.
markdownファイルの拡張子をmdに変更し、記事の新規作成時に、画像用のディレクトリ自動生成と、年月毎ディレクトリ以下に記事を配置するように変更したのでメモ。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/Rakefile b/Rakefile | |
index c2f2a78..f9188c8 100644 | |
--- a/Rakefile | |
+++ b/Rakefile | |
@@ -22,9 +22,10 @@ blog_index_dir = 'source' # directory for your blog's index page (if you put | |
deploy_dir = "_deploy" # deploy directory (for Github pages deployment) | |
stash_dir = "_stash" # directory to stash posts for speedy generation | |
posts_dir = "_posts" # directory for blog files | |
+posts_images_dir= "images/posts" | |
themes_dir = ".themes" # directory for blog files | |
-new_post_ext = "markdown" # default new post file extension when using the new_post task | |
-new_page_ext = "markdown" # default new page file extension when using the new_page task | |
+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 | |
server_port = "4000" # port for preview server eg. localhost:4000 | |
@@ -98,8 +99,12 @@ task :new_post, :title do |t, args| | |
title = get_stdin("Enter a title for your post: ") | |
end | |
raise "### You haven't set anything up yet. First run `rake install` to set up an Octopress theme." unless File | |
- mkdir_p "#{source_dir}/#{posts_dir}" | |
- filename = "#{source_dir}/#{posts_dir}/#{Time.now.strftime('%Y-%m-%d')}-#{title.to_url}.#{new_post_ext}" | |
+ time_now = Time.now | |
+ post_dir_of_monthly = "#{source_dir}/#{posts_dir}/#{time_now.strftime('%Y-%m')}" | |
+ mkdir_p post_dir_of_monthly | |
+ # create dir of post's images | |
+ mkdir_p "#{source_dir}/#{posts_images_dir}/#{time_now.strftime('%Y/%m/%d')}/#{title.to_url}" | |
+ filename = "#{post_dir_of_monthly}/#{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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment