Yuav siv Jekyll yuav ua li cas thiaj li tsim cov ntawv tsim lub sijhawm thiab yooj yim nce blog hloov tshiab zaus?

thaum koj npaj sivJekyllThaum sau ib tsab xov xwm, koj yeej tsis xav thab manually tsim cov ntaub ntawv, hloov kho cov ntaub ntawv extensions, thiab ces ntxiv yml syntax thaum pib ntawm cov ntawv nyeem, txoj cai?

Yog li koj yuav xavJekyll new article, kom yooj yim rau tag nrho cov no, nws puas yog qhov laj thawj los sau tsab ntawv?

Puas yog programmers txhua tus sau code tsuas yog ua tub nkeeg? Lub sijhawm no, Rake tuaj yeem ua ke.

Yuav siv Jekyll li cas los tsim cov ntawv?

Raws li Jekyll cov kev cai nruj rau md lub npe thiab yaml hom, nws yog ib qho nyuaj heev rau manually sau yaml txhua lub sijhawm, yog li siv cov ntawv sau tawm cov ntsiab lus yog qhov kev xaiv zoo.

Yuav siv Jekyll yuav ua li cas thiaj li tsim cov ntawv tsim lub sijhawm thiab yooj yim nce blog hloov tshiab zaus?

Ua ntej, xyuas seb puas yog rake tau teeb tsa:

gem list rake

Yog tias nws tsis tau nruab, nruab nws:

gem install rake

Tom ntej no, tsim ib Rakefile thiab muab tso rau hauv lub hauv paus directory ntawm jekyll.

Tom qab ntawd, luam cov cai hauv qab no rau hauv 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
  • Qhov no tsuas yog ib qho yooj yim version.

Thaum kawg, nkag mus rau ntawm kab hais kom ua:

rake post title="article name"

Nrog ib tug whoosh, koj yuav nyob ntawd _post Hauv daim nplaub tshev, kuv pom ib tsab xov xwm tshiab nrog cov ntaub ntawv npe年-月-日-文章标题.md.

Cia siab Chen Weiliang Blog ( https://www.chenweiliang.com/ ) qhia "Yuav ua li cas siv Jekyll kom tau txais cov lus tsim lub sijhawm thiab yooj yim nce blog hloov tshiab zaus?" 》, pab tau rau koj.

Zoo siab txais tos los qhia qhov txuas ntawm kab lus no:https://www.chenweiliang.com/cwl-31597.html

Zoo siab txais tos rau Telegram channel ntawm Chen Weiliang blog kom tau txais qhov hloov tshiab tshiab!

🔔 Ua thawj tus tau txais txiaj ntsig "ChatGPT Content Marketing AI Tool Usage Guide" hauv cov npe saum toj kawg nkaus channel! 🌟 ib
📚 Daim ntawv qhia no muaj nuj nqis loj, 🌟Qhov no yog lub sijhawm tsis tshua muaj, tsis txhob nco nws! ⏰⌛💨
Share thiab like yog tias koj nyiam!
Koj qhov kev sib koom thiab kev nyiam yog peb qhov kev txhawb nqa tas mus li!

 

评论 评论

Koj email chaw nyob yuav tsis tsum luam tawm. Yuav tsum tau siv cov liaj teb * Ntaus Cim

scroll rau saum