0
votes

I'm currently trying out an approach for advertisement in my blog where the user opts-in watching ads by explicitly choosing the ad-version of the blog post, or the ad-free version. So, from a single post, say "_posts/post1", I'll need to generate /posts/post1.html and /withads/post1.html, with the same content, but with different layouts. How can I do it with 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)
1

1 Answers

1
votes

Be it as a normal page or as part of a collection, Jekyll generates a single page input file, because it does a one step generation. The only approach I can think for your problem is to have two separated collections:

_config.yml

# rest of the file
collections:
    withads:
        output: true
    adfree:
        output: true

withads/post1.md

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

adfree/post1.md

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

The bad thing is that you would have to write three files per post (_post/postX.md, _withads/postX.md and _addfree/postX.md), but the good thing is that the withads/postX.md and addfree/postX.md are short and have the same structure always. You could easily even automate their generation before properly generating the Jekyll site (In other words, do the work that Jekyll cannot, that is doing two steps for generating the page).