和/或Jekyll上的where_exp表达式 [英] and/or on a where_exp expression on Jekyll

查看:121
本文介绍了和/或Jekyll上的where_exp表达式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用where_exp使用or运算符基于两个类别过滤Jekyll页面:

I'm trying to use where_exp to filter Jekyll pages based on two categories using or operator:

{% assign sortedPages = site.pages | sort:"date" | reverse | where_exp:"page","page.categories contains 'design-pattern'" %}

但是我收到此错误:

期望的end_of_string但找到了管道

Expected end_of_string but found pipe

Ar or/and运算符是否真正受支持?如我的代码片段所示,我不知道如何使用where_exp过滤页面.

Ar or/and operators really supported? I can't figure out how to filter pages using where_exp as shown in my code snippet.

推荐答案

我已经通过一些变通办法解决了我的问题……这不是一个非常优雅的解决方案,但因为Jekyll并不是要创建实际的软件体系结构. ..目前,它可以正常工作:

I've managed to solve my issue with some workarounds... It's not a very elegant solution, but as Jekyll isn't about creating actual software architecture... For now, it works flawlessly:

{% assign patterns = "" | split,"" %}

{% for page in site.pages %}
{% if page.categories contains "design-pattern" or page.categories contains "anti-pattern" %}
{% assign patterns = patterns | push:page %}
{% endif %}
{% endfor %}

{% assign sortedPages = patterns | sort:"date" | reverse %}

  1. 我创建一个空数组.
  2. 我遍历所有页面,并按两个可能的类别对其进行过滤.
  3. 我推送满足所有条件的页面.
  4. 一旦获得过滤后的页面数组,便对其进行排序和反转.

这篇关于和/或Jekyll上的where_exp表达式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆