ruby - Get Jekyll Configuration Inside Plugin -


I want to make a configuration option change to make a generation of 'Read more' link.

To do this, I need to be able to access Jekyll site configurations within the AssetFilter of the plugin. I can make changes as the configuration is available. I do not know how the site configuration is available for the plugin.

The code below shows where site.config will be available to me:

  requires 'Nokogiri' module JKL module AssetFilter DEF only_first_p (post) # site.config configuration output = "& lt; p & gt;" Should be available here to modify the output on the basis of. Output & lt; & Lt; Note: :: HTML (post ["content"]). At_css ("p"). Inner_html output & lt; & Lt; % {& Lt; / P & gt; & Lt; A class = "readmore" href = "# {post [" url "]}" & gt; Read more & lt; / A & gt;} Output End End Liquid :: Template.register_filter (Jekyll:: Asset Filter)   


Can it be achieved?

overview

You can access the following in these plugins for the jacile config options :

  Jekyll.configuration ({}) ['KEY_NAME']   

If the configuration key has nested levels, then the format is:

  Jekyll.configuration ({}) ['KEY_LEVEL_1'] ['KEY_LEVEL_2']    
  testvar : The new value is custom_root: second_level: sub-level data     P> A basic example that outputs those values, will look like:  
  'Nocogiri 'Module Required Module AssetFilter Df only_first_p (post) @c_value = Jekyll.configuration ({}) [' testvar '] @ C_value_nested = Jekyll.configuration ({}) [' custom_root '] [' second_level '] output = " & Lt; p & gt; ### Confirm that you got config value output & lt; & Lt; "
" Output & lt; & Lt; "C_value:" + @c_value + " & lt; br / & gt; Output & lt; & Lt; "C_value_nested:" + @c_value_nested + " & lt; br / & gt; Output & lt; & Lt; "
" ### Output & lt; & Lt; Note: :: HTML (post ["content"]). At_css ("p"). Inner_html output & lt; & Lt; % {& Lt; / P & gt; & Lt; A class = "readmore" href = "# {post [" url "]}" & gt; Read more & lt; / A & gt;} Output End End End Liquid :: Template.register_filter (Jekyll:: Asset Filter)

Of course, you want to check in the check that the config key / value to use them Is defined before. This is left as an exercise for the reader.


Another possible option

The "Liquid Filter" section includes the following:

In jacile you can use the site object, through the registers, for example, you can use the global configuration (_config.yml) like this: @ reference. Register [: site] .config ['cdn'].

I have not spent time doing this to work, but it may be worth checking out well.

Comments