Jekyll技术问询:如何保留空格调用多词featured标签?
Jekyll带空格标签的Liquid调用方案
文章头部标签写法
要确保top featured被识别为单个标签(而非两个独立标签),需要用数组格式声明:
layout: post title: author: categories: Jekyll image: tags: ["top featured"] # 或者换行列表格式 # tags: # - top featured
Liquid模板调用方式
在sidebar-featured.html中,直接使用方括号包裹带空格的标签字符串来访问对应集合,替换原有的site.tags.featured:
<ol class="list-featured"> {% for post in site.tags["top featured"] %} <li class="mb-4"> <!-- 原有内容 --> </li> {% endfor %} </ol>
原理说明
Jekyll会将带空格的标签作为site.tags字典中的一个字符串键存储,但Liquid的点语法(site.tags.xxx)仅支持不含空格、特殊字符的标识符。用方括号+引号包裹的方式,就能直接访问包含空格的键值,完美匹配你需要保留top featured空格的需求,无需改成连字符形式。
内容的提问来源于stack exchange,提问作者Goemon Code
相关产品推荐
相关产品推荐

