quandu site prontu à adupràJekyllQuandu scrivite un articulu, certamente ùn vulete micca fastidiu à creà manualmente i schedari, mudificà l'estensioni di u schedariu, è dopu aghjunghje a sintassi yml à l'iniziu di u testu, nò?
Allora pudete pensàJekyll novu articulu, Per simplificà tuttu questu, ùn saria micca logicu di scrive un script ?
Ùn i programatori ùn scrivenu micca u codice solu per esse pigro? À questu tempu, Rake pò esse utile.
Cumu aduprà Jekyll per generà automaticamente articuli?
In vista di i stretti requisiti di Jekyll per u titulu md è u formatu yaml, hè troppu ingombrante per scrive manualmente yaml ogni volta, cusì l'usu di scripts per u cuntenutu di u cuntenutu hè una bona scelta.
Prima, verificate per vede se u rake hè stallatu:
gem list rake
Se ùn hè micca stallatu, installate:
gem install rake
In seguitu, crea un Rakefile è mette in u cartulare radicali di jekyll.
Dopu, copiate u codice seguente in u 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
- Questa hè solu una versione simplificata.
Infine, entre in a linea di cummanda:
rake post title="article name"
Cù un whoosh, sarete quì _post
In u cartulare, aghju vistu un novu articulu cù u nome di u schedariu年-月-日-文章标题.md
.
Hope Chen Weiliang Blog ( https://www.chenweiliang.com/ ) hà spartutu "Cumu aduprà Jekyll per generà automaticamente u tempu di creazione di l'articulu è facilmente aumentà a freccia di l'aghjurnamentu di u blog?" 》, utile per voi.
Benvenuti à sparte u ligame di stu articulu:https://www.chenweiliang.com/cwl-31597.html
Benvenuti à u canali Telegram di u blog di Chen Weiliang per avè l'ultime aghjurnamenti!
📚 Questa guida cuntene un valore enormu, 🌟Questa hè una rara opportunità, ùn mancate micca! ⏰⌛💨
Condividi è mi piace se ti piace!
A vostra spartera è Mi piace sò a nostra motivazione cuntinua!