0
我写了一个Jekyll插件“Tags”,它生成一个文件并返回该文件的链接字符串。使用Jekyll插件在_site内生成文件
一切都很好,但如果我直接将该文件写入_site文件夹,它将被删除。如果我将该文件放在_site文件夹之外,它不会在_site内部生成。
我应该在哪里以及如何添加我的文件,使其在_site文件夹中可用?
我写了一个Jekyll插件“Tags”,它生成一个文件并返回该文件的链接字符串。使用Jekyll插件在_site内生成文件
一切都很好,但如果我直接将该文件写入_site文件夹,它将被删除。如果我将该文件放在_site文件夹之外,它不会在_site内部生成。
我应该在哪里以及如何添加我的文件,使其在_site文件夹中可用?
您应该使用类Page
这个和调用方法render
和write
。
这是一个例子,生成archive page在我的博客:
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
我发现杰奇:: StaticFile可以扩展到生成静态文件! – roxxypoxxy
@roxxypoxxy究竟如何?你是否会立即生成这些文件,然后将其删除? (即不在源文件夹中) – Elchin