使用Jekyll为同一篇博文生成两个布局

使用Jekyll为同一篇博文生成两个布局,jekyll,Jekyll,我目前正在尝试一种在我的博客中做广告的方法,用户通过明确选择博客文章的广告版本或无广告版本来选择观看广告。因此,从一篇文章,比如“_posts/post1”,我需要生成具有相同内容但布局不同的/posts/post1.html和/withads/post1.html。我怎么能和杰基尔一起做 source: _posts/post1.md layout 1: _layout/adfree.html layout 2: _layout/withads.html output1: _site/pos

我目前正在尝试一种在我的博客中做广告的方法,用户通过明确选择博客文章的广告版本或无广告版本来选择观看广告。因此,从一篇文章,比如“_posts/post1”,我需要生成具有相同内容但布局不同的/posts/post1.html和/withads/post1.html。我怎么能和杰基尔一起做

source: _posts/post1.md
layout 1: _layout/adfree.html
layout 2: _layout/withads.html

output1: _site/posts/post1.html (post1.md + adfree.html)
output2: _site/withads/post1.html (post1.md + withads.html)

无论是作为普通页面还是作为应用程序的一部分,Jekyll都会生成一个页面输入文件,因为它只执行一步生成。我认为解决您的问题的唯一方法是有两个独立的集合:

\u config.yml

#文件的其余部分
收藏:
有广告:
输出:真
免费广告:
输出:真
withads/post1.md

---
layout: withads
source: _post/post1.md
---
{{source.content}}
---
layout: adfree
source: _post/post1.md
---
{{source.content}}
adfree/post1.md

---
layout: withads
source: _post/post1.md
---
{{source.content}}
---
layout: adfree
source: _post/post1.md
---
{{source.content}}
不好的是,您必须为每篇文章编写三个文件(
\u post/postX.md
\u with ads/postX.md
\u addfree/postX.md
),但好的是
with ads/postX.md
addfree/postX.md
都很短,并且总是具有相同的结构。在正确生成Jekyll站点之前,您甚至可以轻松地自动化它们的生成(换句话说,完成Jekyll无法完成的工作,即执行两个步骤来生成页面)