如何调试被忽略的插件?

cas*_*tor 7 ruby plugins jekyll

Jekyll的新人(以前在海德).

  • 放置在_plugins /目录中的Ruby文件显然是默默地被忽略的.
  • 我使用的是Jekyll的0.11.2版,在Ubuntu 12.04上使用了ruby 1.8.7.

是否应该添加额外的配置参数来加载这些插件?文档没有这么说 - 理智的默认应该是查看_plugins,它们应该是自动需要的.如何调试Jekyll插件的加载?

Ala*_*ith 2

对于我的 jekyll 实例(也是 0.11.2,但在 Mac 上使用 ruby​​ 1.9.2p290),我不必添加任何额外的配置,但您可以尝试将以下行添加到顶级“_config.yml”文件。

plugins:     _plugins
Run Code Online (Sandbox Code Playgroud)

或者,可能,

plugins:     ./_plugins
Run Code Online (Sandbox Code Playgroud)

测试插件是否正常工作的最简单方法是删除所有插件,除了您知道可以正常工作的插件之外。我整理了以下内容,这些内容在我的安装中按预期工作。

  1. 在 jekyll 源目录的根目录中创建一个名为“plugin_test.md”的新文件,其中包含以下内容:

    ---
    layout: default
    title: Plugin Test
    ---
    
    the quick brown fox jumps over the lazy dog.
    
    Testing plugin output of '_plugins/testplugin.rb': {% testplugin %}
    
    Run Code Online (Sandbox Code Playgroud)

    请注意,您可能需要将“布局:默认”更改为您实际使用的内容。

  2. 在“_plugins/testplugin.rb”处创建一个包含以下内容的新文件:

    module Jekyll
      class TestPlugin < Liquid::Tag
        def render(context)
          "It's Working!"
        end
      end
    end
    
    Liquid::Template.register_tag('testplugin', Jekyll::TestPlugin)
    
    Run Code Online (Sandbox Code Playgroud)
  3. 在源目录上运行 jekyll。

testplugin.rb 所做的就是将 Liquid 标签的实例替换{% testplugin %}为文本“It'sworking!”。如果您的插件正在触发,您将看到输出

Testing plugin output of '_plugins/testplugin.rb': It's Working!" 
Run Code Online (Sandbox Code Playgroud)

在输出站点根目录的“plugin_test.html”页面上。如果你看到:

Testing plugin output of '_plugins/testplugin.rb':
Run Code Online (Sandbox Code Playgroud)

这意味着插件没有触发。如果你遇到这种情况,我认为这是一个迹象,表明有些东西非常不正常,建议重新安装 jekyll。