我有以下代码:
{% set pageDescription = item.description|length > 197 ? item.description|striptags|trim|slice(0, 197) ~ '...' : item.description %}
我将从 item.description 中移除换行符。
例如,我有以下内容:
<meta name="description" content="An easy playing game about the natural numbers. There will randomly appear the natural. You have to choose what the right after number is. It&#8217;s so easy to play this game, isn&#8217;t it?
The..." />
转换为
<meta name="description" content="An easy playing game about the natural numbers. There will randomly appear the natural. You have to choose what the right after number is. It&#8217;s so easy to play this game, isn&#8217;t it? The..." />
我可以帮助您做什么?
谢谢。
|replace({ "\n": "" })
吗? - Maerlyn{{ post.content | replace({ '\r\n': '\\r\\n', '\n': '\\n', '\r': '\\r' }) }}
作为唯一正确的方法,如果要删除换行符,则可以使用{{ post.content | replace({ '\r\n': '', '\n': '', '\r': '' }) }}
。请注意不改变原意,并使翻译通俗易懂。 - caw