2013-07-12 32 views
2

在液體雙換行符,您可以捕捉一個變量:地帶有液體

{% capture header %} 

<!-- My header content --> 

{% endcapture %} 

那麼無論是這個變量中可以使用的過濾器轉化:

{{ header | strip_newlines }} 

現在,讓我們說你有網頁上的<head>中的一些參考文獻/元標記:

<meta charset="utf-8"> 
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"> 
<meta name="viewport" content="width=device-width, initial-scale=1.0"> 

{% if page.demo %} <link href="/css/demo.css" rel="stylesheet" type="text/css" media="screen">{% endif %} 
<link href="/css/hello.css" rel="stylesheet" type="text/css" media="print"> 

如何僅剝離雙換行符?我想要結束的是一個乾淨的<head>,每行有一個「參考」。 「如果」結構的demo.css文件將讓這個非演示頁面的源看起來有點像這樣:

<meta charset="utf-8"> 
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"> 
<meta name="viewport" content="width=device-width, initial-scale=1.0"> 


<link href="/css/hello.css" rel="stylesheet" type="text/css" media="print"> 

我不希望這樣的線之間多餘的空格 - 中有些情況下,在較大的網站上,可能會有10多行空格。尋找關於如何通過過濾內容來擺脫這個空白的建議。

回答

3

Jekyll plugin,剝去空白。

Aucor的傑基爾插件:例如插件。修剪不需要的 換行符/空格和按重量屬性排序頁面。

您可以直接從它的Github repository。所以基本上你用{% strip %}{% endstrip %}來包裝你的代碼。即使這不適合您的需要,您可以輕鬆更改ruby腳本。

例如:

{% strip %} 
    <meta charset="utf-8"> 
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"> 
    <meta name="viewport" content="width=device-width, initial-scale=1.0"> 
    {% if page.demo %} <link href="/css/demo.css" rel="stylesheet" type="text/css"  media="screen">{% endif %} 
    <link href="/css/hello.css" rel="stylesheet" type="text/css" media="print"> 
{% endstrip %} 

但是,請記住哲基爾插件的性質,你不能GitHub的網頁服務器上運行它們。

報價從documentation

GitHub Pages is powered by Jekyll, however all Pages sites are generated using the --safe option to disable custom plugins for security reasons. Unfortunately, this means your plugins won’t work if you’re deploying to GitHub Pages. 

You can still use GitHub Pages to publish your site, but you'll need to convert the site locally and push the generated static files to your GitHub repository instead of the Jekyll source files. 
0

如果你的項目使用液體4.0或更高版本,那麼你就可以使用大括號內連字符,以避免產生新的生產線液體的最新版本有a built-in way of controlling whitespace.

{%- capture random -%} 
Here's a cool example 
{%- endcapture -%}