yaml front matter in a haml file

霸气de小男生 提交于 2019-12-10 14:14:15

问题


I am attempting to use the haml-jekyll-extension only I do not understand how to include yaml front matter? I have the following:

---
user: hello
---
!!!
%html
  %title RudyIndustries
  %body
    %h1 Hello World! {{ page.user }}

but it ends up getting compiled into the following html:

user: hello
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
  <title>RudyIndustries</title>
  <body>
    <h1>Hello World! {{ page.user }}</h1>
  </body>
</html>

How to do I mark the yaml front matter such that it gets compiled into html properly?


回答1:


Use a back slash:

haml file:

\---
user: hello
\---
%html
  %title RudyIndustries
  %body
    %h1 Hello World! {{ page.user }}

compiles into the following html:

---
user: hello
---
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
  <title>RudyIndustries</title>
  <body>
    <h1>Hello World! {{ page.user }}</h1>
  </body>
</html>



回答2:


You can use Haml comments for front matter. This will let you use nesting in your YAML and it won't reproduce the front matter in your html. The following haml file

-#
  ---
  user: hello
  ---
!!!
%html
  %title RudyIndustries
  %body
    %h1 Hello World! {{ page.user }}

will generate the following HTML

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
  <title>RudyIndustries</title>
  <body>
   <h1>Hello World! {{ page.user }}</h1>
  </body>
</html>


来源:https://stackoverflow.com/questions/10457920/yaml-front-matter-in-a-haml-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!