如何在杰基尔中剥离换行符?



我知道strip_newlines但它没有做我想要的:

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

输出Hellothere但我需要Hello thereinsead。

替换也不起作用,因为您无法放置换行符。

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

如何用空格替换所有换行符?例如,在元标记中使用。

这是技巧:

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

将换行符替换为br 标记,然后去除换行符,然后将<br />替换为空格。剥离 html 并截断以在元描述中使用。

最新更新