使用Jekyll插件在_site内生成文件

我编写了一个Jekyll插件“Tags”,它生成一个文件并返回该文件的链接字符串。

一切都很好,但如果我将该文件直接写入_site文件夹,它将被删除。 如果我将该文件放在_site文件夹之外,则不会在_site内生成。

我应该在哪里以及如何添加我的文件,以便它在_site文件夹中可用?

你应该使用类Page来调用方法renderwrite

这是在我的博客上生成存档页面的示例:

 module Jekyll class ArchiveIndex < Page def initialize(site, base, dir, periods) @site = site @base = base @dir = dir @name = 'archive.html' self.process(@name) self.read_yaml(File.join(base, '_layouts'), 'archive_index.html') self.data['periods'] = periods end end class ArchiveGenerator < Generator priority :low def generate(site) periods = site.posts.reverse.group_by{ |c| {"month" => Date::MONTHNAMES[c.date.month], "year" => c.date.year} } index = ArchiveIndex.new(site, site.source, '/', periods) index.render(site.layouts, site.site_payload) index.write(site.dest) site.pages << index end end end