Metalsmith将自己描绘成一个极其简单的静态站点生成器。我正在尝试编写最基本的站点,只是为了让自己熟悉软件的基础知识,但我似乎连这些都不能构建。下面是我的文件夹结构:
|- build/
|- index.js
|- src/
|-index.html
|- templates
|-index.hbt我的index.js文件:
var Metalsmith = require('metalsmith');
Metalsmith(__dirname)
.destination('./build')
.build();我的index.html文件:
---
title: Home
template: index.hbt
---和我的index.hbt模板:
<!doctype html>
<html>
<head>
<title>FOO</title>
</head>
<body>
something
</body>
</html>我的理解是,YAML命令应该遍历src目录,并解析它找到的任何顶部带有YAML内容的文件。因此,它应该查看index.html,看到它使用templates/index.hbt模板呈现,基本上只是将文件移动到build/index.html中。但是当我运行node index.js时,我什么也得不到。没有进度指示器,没有“完成构建你的东西!”消息,只是一个闪烁的命令提示行。我的build目录是空的。很明显,有什么东西坏了,但是没有日志可以检查,也没有状态消息给google。我做错了什么?难道不应该在build目录中至少创建一个页面吗?
发布于 2015-05-06 06:04:20
在一个教程的评论中找到了所有地方的答案:https://blog.robinthrift.com/2014/04/14/metalsmith-part-1-setting-up-the-forge/。它也在github示例中:https://github.com/segmentio/metalsmith
根据这些链接,您需要在.build()函数上包含一个错误回调:
Metalsmith(__dirname)
.build(function(err) {
if (err) throw err;
});发布于 2015-06-21 07:33:57
除了您已经确定的错误回调问题之外,我认为您的文件中还遗漏了一些东西。诚然,Metalsmith非常简单,但它的简单性意味着许多功能(如对模板的支持)是由您需要显式安装和包含的模块带来的。
您说您的index.js文件的内容是:
var Metalsmith = require('metalsmith');
Metalsmith(__dirname)
.destination('./build')
.build();这就是你所有的东西了吗index.js?如果要使用Handlebars模板,则需要显式添加metalsmith plugin that handles templates,并指示其使用handlebars:
var Metalsmith = require('metalsmith');
var templates = require('metalsmith-templates');
Metalsmith(__dirname)
.destination('./build')
.use(templates('handlebars'))
.build();并确保从npm安装metalsmith-templates和handlebars模块。
此外,您可能知道这一点,但在您的index.hbt中,您需要更改
<title>FOO</title>至
<title>{{ title }}</title>以便从index.html加载标题元数据。
如果这能让你上手,或者你需要更多帮助,请告诉我。
https://stackoverflow.com/questions/30063417
复制相似问题