2017-02-11 32 views
1

我玩弄豎琴靜態站點生成器並沒有這個博客例子到處,參見例如:http://kennethormandy.com/journal/start-a-blog-with-harp豎琴js +博客例子:有沒有一種方法來設置文章的默認部分?

我問,如果有設置默認模板玉/部分的所有物品的方式而不是爲每件看起來相當不方便的物品定義一個?

E.g.我的應用程序

/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 
... 

有一個簡單的方法來做到這一點?

回答

1

您應該能夠添加_layout.jade文件中articles/目錄得到你以後: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。在同一文檔頁面上也有一個例子。

相關問題