gpt4 book ai didi

javascript - Harp js + 博客示例 : Is there a way to set default partial for articles?

转载 作者:太空宇宙 更新时间:2023-11-04 00:27:37 25 4
gpt4 key购买 nike

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

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

例如我的应用程序概要

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

有没有简单的方法可以做到这一点?

最佳答案

您应该能够在 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文件。 articles 目录中的任何内容(在本例中为 article1.jadearticle2.md)都将使用同一目录中的 _layout.jade

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

关于javascript - Harp js + 博客示例 : Is there a way to set default partial for articles?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42176507/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com