【问题标题】:Harp js + blog example: Is there a way to set default partial for articles?Harp js + 博客示例:有没有办法为文章设置默认部分?
【发布时间】:2017-04-13 04:55:28
【问题描述】:

我正在使用 Harp 静态站点生成器,到处都有这个博客示例,例如:http://kennethormandy.com/journal/start-a-blog-with-harp

我在问是否有一种方法可以为所有文章设置默认的玉模板/部分,而不是为每篇文章定义一个,这对我来说似乎相当不方便?

例如我的应用概述

/public
/articles
  _data.json        <--- json with my articles
  article.jade      <--- I would like to have one template for all articles
                           instead of having to add files:
                           article1.jade, 
                           article2.jade, ...
/index.jade   

/articles/_data.json

{
 "article1": {
    "title": "Some article"
 },
 "article2": {
    "title": "Another one"
 }
 // eventually some more articles ...
}

/index.jade

...
ul
  each article, slug in public.articles._data
    li
      a(href="/articles/#{ slug }") #{ article.name }     // generated link only works when for each slug (e.g. "article1") a jade file exists
...

有简单的方法吗?

【问题讨论】:

    标签: javascript node.js harp


    【解决方案1】:

    您应该能够在articles/ 目录中添加一个_layout.jade 文件以获取您想要的内容:https://harpjs.com/docs/development/layout

    以该文档页面上的多个布局示例为基础:

    public/
      _layout.jade
      index.jade
      about.md
      articles/
        _data.json
        _layout.jade
        article1.jade
        article2.md
    

    这里,index.jadeabout.md 将使用项目根目录中的 _layout.jade 文件。文章目录中的任何内容(在本例中为 article1.jadearticle2.md)都将使用同一目录中的 _layout.jade

    这是 Harp 内置的功能,适用于 Jade 和 EJS。如果您将 Jade 用于一切,您还可以使用 Jade 特定功能,例如 blockextends。在同一个文档页面上也有一个示例。

    【讨论】:

      猜你喜欢
      • 2010-12-20
      • 1970-01-01
      • 2018-07-23
      • 2016-08-29
      • 1970-01-01
      • 2022-01-18
      • 1970-01-01
      • 2023-03-17
      • 2010-11-19
      相关资源
      最近更新 更多