2013-07-12 33 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 -%}