让 metalsmith、contentful 和 markdown 一起工作

Get metalsmith, contentful and markdown to work together

我正在尝试使用 Metalsmith 从 Contentful 平台呈现内容(根据示例 here 使用 metalsmith-contentful 平台和 metalsmith-layout)。

我的一个内容丰富的字段是降价文本,所以我想在最终模板中将其呈现为 HTML。我的初始设置与上面的示例类似,但只将降价文本读取为纯文本。

我现在正尝试在车把助手中转换降价,即

 handlebars.registerHelper('markdown', function(object) {
 var text = marked(object);
 return new handlebars.SafeString(text);
 })

并使用 {{{ markdown mycontentfulobject}}}

调用

但这也不管用。

有什么想法吗?

有例外吗?

我现在有完全相同的设置。我认为你已经很接近了。

我做的是,我叫registerHelper

const marked = require( 'marked' )

handlebars.registerHelper('marked', function (text) {
  return marked(text);
})

我在我的模板中使用它。

<section>{{#marked fields.excerpt}}{{/marked}}</section>

这对我来说效果很好。 :)

您可以在此处找到示例项目https://github.com/stefanjudis/stefan-judis-website/blob/master/build.js#L22-L25