Me pehea te whakamahi i a Jekyll ki te whakaputa aunoa i te waa hanga tuhinga me te ngawari ki te whakapiki ake i te waa whakahou blog?

Ina rite koe ki te whakamahi i a Jekyll hei tuhituhi tuhinga, kāore rawa koe e hiahia ki te whakararuraru i te waihanga ā-ringa i ngā kōnae, te whakarerekē i ngā toronga kōnae, me te tāpiri i te wetereo yml ki te tīmatanga o te tuhinga, tika?

Nō reira, me whakaaro pea koe ki te waihanga i tētahi pou hou ki Jekyll . Hei whakangawari i tēnei katoa, kāore ianei e tika kia tuhia he tuhinga?

Kaua nga kaihōtaka katoa e tuhi waehere kia mangere noa? I tenei wa, ka taea e Rake te whai waahi.

Me pehea te whakamahi i a Jekyll hei whakaputa aunoa i nga tuhinga?

I runga i nga whakaritenga a Jekyll mo te taitara md me te whakatakotoranga yaml, he uaua rawa ki te tuhi a-ringa i te yaml i nga wa katoa, no reira he pai te whiriwhiri ma te whakamahi i nga tuhinga hei whakaputa i nga ihirangi.

Me pehea te whakamahi i a Jekyll ki te whakaputa aunoa i te waa hanga tuhinga me te ngawari ki te whakapiki ake i te waa whakahou blog?

Tuatahi, tirohia mena kua whakauruhia te rake:

gem list rake

Mena kaore i whakauruhia, whakauruhia:

gem install rake

Muri iho, hangahia he Rakefile ka tuu ki te raarangi pakiaka o jekyll.

Na, kapehia te waehere e whai ake nei ki te 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
  • He putanga ngawari noa tenei.

Hei whakamutunga, tomo ki te raina whakahau:

rake post title="article name"

Ma te tangi, ka noho koe ki reira _post I roto i te kōpaki, i kite ahau i tetahi tuhinga hou me te ingoa kōnae年-月-日-文章标题.md.

发表 评论

您的邮箱地址不会被公开。必填项已用*标注

Panuku ki te Runga