我已经安装了node.js和模块。IDE是Visual 2013,安装了Node.js工具。我已经设置了一个基本的结构,并且我正在尝试用一个模板来渲染一个页面。
指令要求将以下内容放入文件中:
---
title: Home
template: home.hbt
---
This is your first page具有如下模板:
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>{{ title }} | Metalsmith Page</title>
</head>
<body>
<div class="main-wrapper">
{{{ contents }}}
</div>
</body>
</html>教程说它应该呈现到html页面中,但是我得到的结果如下:
--- title: Home template: home.hbt --- This is your first page当我使用减价渲染器时
<p>---
title: Home</p>
<h2 id="template-home-hbt">template: home.hbt</h2>
<p>This is your first page</p>调试代码表明,当它到达呈现器时,YAML前沿问题元数据就会丢失。这似乎很重要,因为插件使用元数据来呈现页面。
发布于 2014-05-29 09:41:42
解决方案的关键在于在呈现的标记页开始时的三个奇怪的字符。
YAML前沿问题警告:
UTF-8字符编码警告 如果使用UTF-8编码,请确保文件中不存在BOM头字符,否则Jekyll将发生非常非常糟糕的事情。如果您在Windows上运行Jekyll,这一点尤其重要。
查看加载在Node.js中的缓冲区时,显示了utf8 BOM字符。
一种解决方案是让IDE停止使用BOM将其保存为utf8,但对我来说,这不是一个可行的选择。
我创建了一个解决方案,作为一些小行,必须运行之前,任何其他金属匠插件。
var stripBom = require('strip-bom');
var front = require('front-matter');
var extend = require('extend');
// **snip**
.use(function __utf8BOM_workaround(files, metalsmith, done)
{
setImmediate(done);
Object.keys(files).forEach(function (file)
{
var data = files[file];
var parsed = front(stripBom(data.contents.toString()));
data = extend({}, data, parsed.attributes);
data.contents = new Buffer(parsed.body);
files[file] = data;
});
})https://stackoverflow.com/questions/23930304
复制相似问题