我目前正在尝试一种在我的博客中投放广告的方法,用户可以通过明确选择博客帖子的广告版本或无广告版本来选择观看广告。因此,从一个单独的post,比如“_post/post1”,我需要生成/post/post1.html和/withads/post1.html,它们具有相同的内容,但布局不同。我怎么才能和Jekyll一起做呢?
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)发布于 2020-12-03 18:45:37
无论是作为普通页面还是作为collection的一部分,Jekyll都会生成一个页面输入文件,因为它只需一步生成。我能想到的解决问题的唯一方法是使用两个独立的集合:
_config.yml
# rest of the file
collections:
withads:
output: true
adfree:
output: truewithads/post1.md
---
layout: withads
source: _post/post1.md
---
{{source.content}}adfree/post1.md
---
layout: adfree
source: _post/post1.md
---
{{source.content}}坏的是你必须为每个帖子写三个文件(_post/postX.md,_withads/postX.md和_addfree/postX.md),但好的是withads/postX.md和addfree/postX.md很短,并且总是有相同的结构。在正确生成Jekyll站点之前,您甚至可以很容易地自动生成它们(换句话说,做Jekyll做不到的工作,即做两个步骤来生成页面)。
https://stackoverflow.com/questions/65115631
复制相似问题