2017-07-17 47 views
0

我知道strip_newlines但它不這樣做我想要的東西:如何去除jekyll中的換行符?

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

{{ string | strip_newlines }} 

輸出Hellothere,但我需要Hello there INSEAD。

替換不能工作,因爲你不能把換行字符。

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

如何用空格替換所有換行符?例如用於元標記中。

回答

1

這裏是特技:

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

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

與BR代碼替換換行符,然後剝去換行符,然後用空間替換<br />。剝離html並在元描述中截斷使用。