如何在转换器插件中访问页面属性(YAML前端内容)

pip*_*ull 6 ruby jekyll jekyll-extensions

我正在为Jekyll编写一个转换器插件,需要访问一些页眉(YAML前端)属性.只有内容传递给主转换器方法,似乎无法访问上下文.

例:

module Jekyll
  class UpcaseConverter < Converter
    safe true
    priority :low

    def matches(ext)
      ext =~ /^\.upcase$/i
    end

    def output_ext(ext)
      ".html"
    end

    def convert(content)

      ###########
      #
      # Its here that I need access to the content page header data 
      #
      # 
      ###########

      content.upcase
    end
  end
end
Run Code Online (Sandbox Code Playgroud)

有关如何在转换器插件中访问页眉数据的任何想法?

小智 2

根据 Jekyll 源代码,不可能在转换器中检索 YAML 前面的内容。

我看到两种可以根据您的情况起作用的解决方案。

  1. 您的文件扩展名可以具有足够的描述性,以提供您将包含在前言中的信息。看起来 Converter 插件就是这么基本设计的。

  2. 如果可以选择修改 Jekyll,则可以更改 Convertible.transform 方法以将前面的内容发送到 Converter.convert。Jekyll 附带的转换器也必须进行修改。在 GitHub 上分叉它,看看其他人是否喜欢这个想法。从这里开始:https://github.com/mojombo/jekyll/blob/cb1a2d1818770ca5088818a73860198b8ccca27a/lib/jekyll/convertible.rb#L49

祝你好运。