【发布时间】:2018-02-13 22:40:42
【问题描述】:
我编写了一个简单的插件,可以生成一个小的 JSON 文件
module Jekyll
require 'pathname'
require 'json'
class SearchFileGenerator < Generator
safe true
def generate(site)
output = [{"title" => "Test"}]
path = Pathname.new(site.dest) + "search.json"
FileUtils.mkdir_p(File.dirname(path))
File.open(path, 'w') do |f|
f.write("---\nlayout: null\n---\n")
f.write(output.to_json)
end
# 1/0
end
end
end
但是每次 Jekyll 运行完成时,生成的 JSON 文件都会被删除。如果我取消注释除以零行并导致它出错,我可以看到 search.json 文件正在生成,但随后被删除。如何防止这种情况发生?
【问题讨论】: