Last active
April 18, 2019 09:32
-
-
Save abearxiong/e830331e0872031240a38d32b7f93e8f to your computer and use it in GitHub Desktop.
jekyll中创建一个新的post文章
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
#!/usr/bin/ruby | |
# -*- coding: UTF-8 -*- | |
# 2018-11-07 15:40 | |
task :newart,[:article,:title,:categories,:tags,:description] do |t,args| | |
time = Time.new #Get new time | |
timeinfos = time.to_s.split(" ") | |
path ="_posts/" | |
filename= args["article"].gsub(" ","-") | |
suffix = ".markdown" | |
newfile = path+timeinfos[0]+"-"+filename+suffix | |
title =args["title"].nil?? "title-name" : args["title"] | |
date = time.inspect | |
categories =args["categories"].nil?? "articles" : args["categories"] | |
tags = args["tags"].nil?? "notags" : args["tags"].split(" ") | |
comments = true | |
description = args["description"].nil?? "" : "desctiption: #{args["description"]}\n" | |
inputContent = "---\nlayout: post\ntitle: #{title} \ndate: #{date} \ncategories: #{categories} \ntags: #{tags}\ncomments: #{comments}\n#{description}---\n" | |
File.open(newfile,"w+") do |aFile| | |
aFile.write(inputContent) | |
end | |
end | |
# Learning other | |
time = Time.new | |
# Time 的组件 | |
puts "当前时间 : " + time.inspect | |
puts time.year # => 日期的年份 | |
puts time.month # => 日期的月份(1 到 12) | |
puts time.day # => 一个月中的第几天(1 到 31) | |
puts time.wday # => 一周中的星期几(0 是星期日) | |
puts time.yday # => 365:一年中的第几天 | |
puts time.hour # => 23:24 小时制 | |
puts time.min # => 59 | |
puts time.sec # => 59 | |
puts time.usec # => 999999:微秒 | |
puts time.zone # => "UTC":时区名称 | |
# 22:31 | |
# filename = "test.markdown" | |
# File.open(filename, "w+") do |aFile| | |
# aFile.write("test") | |
# end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment