Jekyll: Include a file from directory outside of _includes

后端 未结 7 1523
陌清茗
陌清茗 2021-02-07 03:34

I have an directory called /patterns in my Jekyll site, whose structure generally looks generally like this:

_includes _layouts _site /patterns index

7条回答
  •  清歌不尽
    2021-02-07 04:04

    I improved the plugin that @Jeremy Lynch referred to. Here is the documentation:

    include_absolute

    Jekyll's built-in include tag does not support including files outside of the _includes folder. This plugin supports 4 types of includes:

    1. Absolute filenames (start with /).
    2. Filenames relative to the top-level directory of the Jekyll web site (Do not preface with . or /).
    3. Filenames relative to the user home directory (preface with ~).
    4. Executable filenames on the PATH (preface with !).

    Syntax:

    {% include_absolute path [ optionalParam1='yes' optionalParam2='green' ] %}
    

    The optional parameters can have any name. The included file will have parameters substituted.

    Installation

    Copy include_absolute.rb into /_plugins and restart Jekyll.

    Examples

    1. Include files without parameters; all four types of includes are shown.

      {% include_absolute '../../folder/outside/jekyll/site/foo.html' %}
      {% include_absolute 'folder/within/jekyll/site/bar.js' %}
      {% include_absolute '/etc/passwd' %}
      {% include_absolute '~/.ssh/config' %}
      
    2. Include a file and pass parameters to it.

      {% include_absolute '~/folder/under/home/directory/foo.html' param1='yes' param2='green' %}
      

提交回复
热议问题