当你准备使用Jekyll来撰写文章时,你肯定不愿意烦心地手动创建文件、修改文件后缀名,再在文本开头添加yml语法了吧?
Mar sin is dòcha gu bheil thu a’ smaoineachadhJekyll artaigil ùr, gus seo uile a dhèanamh nas sìmplidhe, nach biodh e loidsigeach sgriobt a sgrìobhadh?
Nach bi prògramadairean uile a’ sgrìobhadh còd dìreach airson a bhith leisg? Aig an àm seo, faodaidh Rake a bhith feumail.
Ciamar a chleachdas tu Jekyll gus artaigilean a ghineadh gu fèin-ghluasadach?
A dh’ aindeoin riatanasan teann Jekyll airson tiotal md agus cruth yaml, tha e ro dhoirbh yaml a sgrìobhadh le làimh a h-uile turas, agus mar sin tha cleachdadh sgriobtaichean airson susbaint a chraoladh na dheagh roghainn.
An toiseach, dèan cinnteach a bheil rake air a chuir a-steach:
gem list rake
Mura h-eil e air a stàladh, stàlaich e:
gem install rake
An uairsin, cruthaich Rakefile agus cuir e ann an eòlaire freumh jekyll.
An uairsin, dèan lethbhreac den chòd a leanas a-steach don 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
- Is e seo dìreach dreach nas sìmplidhe.
Mu dheireadh, cuir a-steach aig an loidhne-àithne:
rake post title="article name"
Leis an acras, bidh thu ann _post
Anns a 'phasgan, chunnaic mi artaigil ùr le ainm an fhaidhle年-月-日-文章标题.md
.
An dòchas blog Chen Weiliang ( https://www.chenweiliang.com/ ) 分享的《如何利用Jekyll自动生成文章创建时间,轻松提升博客更新频率?》,对您有帮助。
Fàilte gus ceangal an artaigil seo a cho-roinn:https://www.chenweiliang.com/cwl-31597.html
Fàilte don t-sianal Telegram de bhlog Chen Weiliang gus na h-ùrachaidhean as ùire fhaighinn!
📚 Tha luach mòr anns an stiùireadh seo, 🌟 Is e cothrom ainneamh a tha seo, na caill e! ⏰⌛💨
Roinn agus toil ma thogras tu!
Is e do roinneadh agus do rudan mar ar brosnachadh leantainneach!