Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/mercurial/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何输出社交url';JSON中的s+;来自yaml数据文件的LD?_Yaml_Jekyll_Liquid_Jekyll Theme - Fatal编程技术网

如何输出社交url';JSON中的s+;来自yaml数据文件的LD?

如何输出社交url';JSON中的s+;来自yaml数据文件的LD?,yaml,jekyll,liquid,jekyll-theme,Yaml,Jekyll,Liquid,Jekyll Theme,我的代码将从数据文件中捕获项目。我需要用逗号分隔。我运气不好 数据文件socialmedia.yml 我试过这个。但是,它不会用逗号分隔它们: "sameAs":[ {% if site.data.socialmedia %} {% assign sm = site.data.socialmedia %} {% for entry in sm %} {% assign key = entry | first | split%} {% if sm

我的代码将从数据文件中捕获项目。我需要用逗号分隔。我运气不好

数据文件
socialmedia.yml
我试过这个。但是,它不会用逗号分隔它们:

 "sameAs":[ 
{% if site.data.socialmedia %}
    {% assign sm = site.data.socialmedia %}
    {% for entry in sm %}
        {% assign key = entry | first | split%}
        {% if sm[key].id %}
{% capture social %}{{ sm[key].href }}{{ sm[key].id }}{% endcapture %}
    {{ social | replace: " ", "," | jsonify }}
        {% endif %}
    {% endfor %}
{% endif %}
   ],
所需的输出格式:

 "sameAs": [
    "http://www.facebook.com/your-profile",
    "http://instagram.com/yourProfile",
    "http://www.linkedin.com/in/yourprofile",
    "http://plus.google.com/your_profile"
  ]
实际无效输出:

"sameAs":[ "https://www.facebook.com/dpcgco" "https://www.twitter.com/DenverProphitJr" ],

您必须检查项目是否是
forloop.last
中的最后一个

  {% if site.data.socialmedia %}
  {% assign sm = site.data.socialmedia %}
"sameAs":[
    {% for entry in sm %}
      {% assign key = entry | first %}
        {% if sm[key].id %}"{{ sm[key].href }}
        {{ sm[key].id }}",
        {% if forloop.last %}
        "{{ sm[key].href }}{{ sm[key].id }}"
       {% endif %}
    {% endif %}
  {% endfor %}
  {% endif %}
 ],
  {% if site.data.socialmedia %}
  {% assign sm = site.data.socialmedia %}
"sameAs":[
    {% for entry in sm %}
      {% assign key = entry | first %}
        {% if sm[key].id %}"{{ sm[key].href }}
        {{ sm[key].id }}",
        {% if forloop.last %}
        "{{ sm[key].href }}{{ sm[key].id }}"
       {% endif %}
    {% endif %}
  {% endfor %}
  {% endif %}
 ],