Node.js can';无法安装极其基本的metalsmith来构建页面
Metalsmith将自己描绘成一个极其简单的静态站点生成器。我试图编写最基本的网站,只是为了让自己熟悉软件的基本知识,但我似乎连构建这些网站都做不到。以下是我的文件夹结构:Node.js can';无法安装极其基本的metalsmith来构建页面,node.js,metalsmith,Node.js,Metalsmith,Metalsmith将自己描绘成一个极其简单的静态站点生成器。我试图编写最基本的网站,只是为了让自己熟悉软件的基本知识,但我似乎连构建这些网站都做不到。以下是我的文件夹结构: |- build/ |- index.js |- src/ |-index.html |- templates |-index.hbt 我的index.js文件: var Metalsmith = require('metalsmith'); Metalsmith(__dirname) .des
|- build/
|- index.js
|- src/
|-index.html
|- templates
|-index.hbt
我的index.js
文件:
var Metalsmith = require('metalsmith');
Metalsmith(__dirname)
.destination('./build')
.build();
---
title: Home
template: index.hbt
---
我的index.html
文件:
var Metalsmith = require('metalsmith');
Metalsmith(__dirname)
.destination('./build')
.build();
---
title: Home
template: index.hbt
---
和我的index.hbt
模板:
<!doctype html>
<html>
<head>
<title>FOO</title>
</head>
<body>
something
</body>
</html>
福
某物
我的理解是,
build
命令应该查看src
目录,并解析它找到的任何文件,其中YAML内容位于顶部。因此,它应该查看index.html
,查看它使用templates/index.hbt
模板进行渲染,基本上只需将文件移动到build/index.html
。但是当我运行node index.js
时,我什么也得不到。没有进度指示器,没有“完成构建您的东西!”消息,只有闪烁的命令提示行。我的生成目录为空。很明显,有什么东西坏了,但没有日志要检查,也没有状态消息给谷歌。我做错了什么?在build
目录中不应该至少创建一个页面吗?在教程的注释中找到了所有位置的答案:。github上也有这样的例子:
根据这些链接,您需要在.build()
函数中包含一个错误回调:
Metalsmith(__dirname)
.build(function(err) {
if (err) throw err;
});
除了您已经确定的错误回调问题之外,我认为您的文件中还缺少一些内容。诚然,Metalsmith非常简单,但它的简单性意味着许多功能(如对模板的支持)都是由您需要安装并显式包含的模块带来的 您说您的
index.js
文件的内容是:
var Metalsmith = require('metalsmith');
Metalsmith(__dirname)
.destination('./build')
.build();
这就是你index.js中的所有内容吗?如果要使用把手模板,则需要显式添加,并指示其使用把手:
var Metalsmith = require('metalsmith');
var templates = require('metalsmith-templates');
Metalsmith(__dirname)
.destination('./build')
.use(templates('handlebars'))
.build();
并确保从npm安装metalsmith模板
和把手
模块
另外,您可能知道这一点,但在index.hbt
中,您需要进行更改
<title>FOO</title>
FOO
到
{{title}
为了从index.html
加载标题元数据
让我知道这是否能帮助你,或者你是否需要更多帮助。我个人做的更多。。。我将错误输出到生成日志。这样我以后可以看到他们。这是个好主意,@JamesKhoury。我必须实现这一点。谢谢如果你愿意,你能和我们分享一下吗?我很想看看你们是怎么做的。看起来他改变了修改规则。更新了新链接,尽管注释不再存在。顺便说一句,metalsmith模板
插件已被弃用,并拆分为两个不同的插件metalsmith布局
和metalsmith就地