当你准备使用Jekyll来撰写文章时,你肯定不愿意烦心地手动创建文件、修改文件后缀名,再在文本开头添加yml语法了吧?
Mar sin b'fhéidir go gceapfáJekyll alt nua, chun é seo go léir a shimpliú, nach mbeadh sé loighciúil script a scríobh?
Ná scríobh ríomhchláraitheoirí cód díreach le bheith leisciúil? Ag an am seo, is féidir Rake teacht i handy.
Conas Jekyll a úsáid chun earraí a ghiniúint go huathoibríoch?
I bhfianaise na gceanglas dian atá ag Jekyll maidir le teideal md agus formáid yaml, tá sé ró-deacair yaml a scríobh de láimh gach uair, agus mar sin is rogha mhaith é scripteanna a úsáid chun ábhar a aschur.
Ar dtús, seiceáil féachaint an bhfuil rake suiteáilte:
gem list rake
Mura bhfuil sé suiteáilte, suiteáil é:
gem install rake
Ansin, cruthaigh Rakefile agus cuir i bhfréamheolaire jekyll é.
Ansin, cóipeáil an cód seo a leanas isteach sa Rakefile:
require 'rake'
require 'yaml'
SOURCE = "."
CONFIG = {
'posts' => File.join(SOURCE, "_posts"),
'post_ext' => "md",
}
# Usage: rake post title="A Title"
desc "Begin a new post in #{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-]/, '')
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'
end
puts "Creating new post: #{filename}"
open(filename, 'w') do |post|
post.puts "---"
post.puts "layout: post"
post.puts "title: \"#{title.gsub(/-/,' ')}\""
post.puts "category: "
post.puts "tags: []"
post.puts "---"
end
end # task :post
- Níl anseo ach leagan simplithe.
Ar deireadh, cuir isteach ag an líne ordaithe:
rake post title="article name"
Le whoosh, beidh tú ann _post
San fhillteán, chonaic mé alt nua leis an ainm comhaid年-月-日-文章标题.md
.
Tá súil agam Blag Chen Weiliang ( https://www.chenweiliang.com/ ) 分享的《如何利用Jekyll自动生成文章创建时间,轻松提升博客更新频率?》,对您有帮助。
Fáilte romhat nasc an ailt seo a roinnt:https://www.chenweiliang.com/cwl-31597.html
Fáilte chuig cainéal Telegram de bhlag Chen Weiliang chun na nuashonruithe is déanaí a fháil!
📚 Tá luach ollmhór sa treoir seo, 🌟 Seo deis annamh, ná caill é! ⏰⌛💨
Roinnigí agus más maith libh!
Is iad do chomhroinnt agus do thaitin ár spreagadh leanúnach!