【问题标题】:Jekyll print content of fileJekyll 打印文件内容
【发布时间】:2018-06-20 09:00:16
【问题描述】:

我有一个包含代码的文件。我想将该文件放在自定义文件夹中并在帖子中获取它的源代码。是否可以?

类似这样的:

{{ 'samples/trafikito.html' | raw }}

所以它会读取文件内容并返回里面的内容。

【问题讨论】:

    标签: jekyll jekyll-extensions


    【解决方案1】:

    您可以将sample 文件夹放在_includes 文件夹中。然后,将包含标签包裹在<pre><code> ... </code></pre> 中。所以,它看起来像下面这样:

    # inside _includes/samples/trafikito.html
    
    <div>
        <h1>Test Code<h1>
        <p>Test Code</p>
    </div>
    
    
    ================
    
    
    # inside the file where you want to include the sample
    
    ...
    <pre>
        <code>
            {% include samples/trafikito.html %}
        </code>
    </pre>
    ...
    

    这适用于任何源代码文件类型(.html.json 等),因为 Jekyll 只是将完整的文件内容插入到目标文件中。插入的代码被标记包围,告诉浏览器将内容呈现为文本代码而不是实际代码

    【讨论】:

      猜你喜欢
      • 2012-06-12
      • 1970-01-01
      • 2021-03-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-08-03
      • 2020-04-25
      相关资源
      最近更新 更多