【问题标题】:"Pasting" raw contents of a yaml file in Liquid“粘贴” Liquid 中 yaml 文件的原始内容
【发布时间】:2022-09-30 01:47:10
【问题描述】:

我有一个yaml 配置文件,看起来类似于:

# This file is placed at _data/snakemake_config.yaml

control: \"controls/master_control.csv\"
results_dir: \"results\"
generation:
  genome_save_dir: \"genome/star\"
  gtf_file: \"genome/Homo_sapiens.105.gtf\"

我想将此文件的内容作为一种“实时更新程序”在屏幕上输出,所以如果我更改配置文件中的某些内容(例如,将control: 更新为control: \"controls/new_default_file.csv\"),它的更改也将反映在 Jekyll/Liquid 降价页面中。这是我到目前为止所做的,但它在每一行都放置了一个额外的换行符:

{% comment %}
This can be under index.md
Note: indentation is intentional, read further for reasoning
{% endcomment %}

```yaml
{% for line in site.data.snakemake_config %}
{% if line[0] == \"generation\" %} 
{{- line[0] }}:
   {% for element in site.data.snakemake_config.generation %}
   {{- element[0] -}}: {{ element[1] }}
   {% endfor %}
{% else %}
{{- line[0] -}}: {{ line[1] }}
{% endif %}
{% endfor %}
``` 

这是我得到的输出:


control: controls/master_control.csv


results_dir: results


generation:
   genome_save_dir: genome/star
   gtf_file: genome/Homo_sapiens.105.gtf
   



我可以通过将 Liquid 代码的不同行放在同一行上来删除一些换行符,但是可读性非常困难(更不用说将来维护了)。即使是现在,Liquid 部分也不容易阅读——嵌套的 for/if 语句等没有缩进。

理想情况下,我会有效地“复制和粘贴”snakemake_config.yaml 文件信息index.md 的内容

有谁知道我该怎么做?谢谢你的帮助!

    标签: file yaml jekyll liquid


    【解决方案1】:

    您可以使用捕获来获取原始数据,然后使用该变量。基于this answer(以<pre>为例):

    {%- capture rawContent -%}
      {%- include_relative _data/snakemake_config.yaml -%}
    {%- endcapture -%}
    <pre>
    {{rawContent}}
    </pre>
    

    【讨论】:

      猜你喜欢
      • 2012-01-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-04-05
      • 2012-07-21
      • 1970-01-01
      相关资源
      最近更新 更多