Skip to content

Commit

Permalink
update rakefile
Browse files Browse the repository at this point in the history
  • Loading branch information
Blissful-Jasper committed Jan 27, 2024
1 parent da703a3 commit c12c51a
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
require 'rake'
require 'yaml'
require 'stringex'

SOURCE = "."
CONFIG = {
Expand All @@ -8,26 +9,26 @@ CONFIG = {
}

# Usage: rake post title="A Title" image="13.jpg" category="WRF" tags="tag1, tag2"
desc "Begin a new post in #{CONFIG['posts']}"
desc "开始一个新的博文在 #{CONFIG['posts']}"
task :post do
abort("rake aborted: '#{CONFIG['posts']}' directory not found.") unless FileTest.directory?(CONFIG['posts'])
title = ENV["title"] || "new-post"
slug = title.downcase.strip.gsub(' ', '-').gsub(/[^\w-]/, '')
abort("rake 中止: '#{CONFIG['posts']}' 目录未找到.") unless FileTest.directory?(CONFIG['posts'])
title = ENV["title"] || "新文章"
slug = title.to_url
filename = File.join(CONFIG['posts'], "#{Time.now.strftime('%Y-%m-%d')}-#{slug}.#{CONFIG['post_ext']}")
if File.exist?(filename)
abort("rake aborted!") if ask("#{filename} already exists. Do you want to overwrite?", ['y', 'n']) == 'n'
abort("rake 中止!") if ask("#{filename} 已存在. 您想要覆盖吗?", ['y', 'n']) == 'n'
end

image = ENV["image"] || "default-image.jpg"
category = ENV["category"] || "uncategorized"
image = ENV["image"] || "默认图片.jpg"
category = ENV["category"] || "未分类"
creation_date = Time.now.strftime('%Y-%m-%d %H:%M')
tags = ENV["tags"] || "tag1, tag2" # Set default tags or leave it empty
tags = ENV["tags"] || "标签1, 标签2" # 设置默认标签或留空

puts "Creating new post: #{filename}"
puts "创建新的博文: #{filename}"
open(filename, 'w') do |post|
post.puts "---"
post.puts "layout: post"
post.puts "title: \"#{title.gsub(/-/,' ')}\""
post.puts "title: \"#{title}\""
post.puts "author: Jianpu"
post.puts "categories: #{category}"
post.puts "tags: [#{tags}]"
Expand Down

0 comments on commit c12c51a

Please sign in to comment.