如何去除 jekyll 中的换行符?

How to strip newlines in jekyll?

我知道 strip_newlines 但它并没有按照我的意愿行事:

{% capture string %}
Hello
there
{% endcapture %}

{{ string | strip_newlines }}

输出 Hellothere 但我需要 Hello there insead.

替换也不起作用,因为你不能放入换行符。

{{ string | replace: '\n', ' ' }}

如何用space替换所有换行符?例如在元标记中的使用。

这是技巧:

{% assign description = page.excerpt | newline_to_br | strip_newlines | replace: '<br />', ' ' | strip_html | strip |  truncatewords: 30 %}

<meta name="description" content="{{ description }}">

用br标签替换换行符,然后去掉换行符,然后用space替换<br />。去除 html 并截断以用于元描述。