【问题标题】:Generate two layouts for the same blog post with Jekyll使用 Jekyll 为同一篇博文生成两个布局
【发布时间】:2020-12-02 20:25:43
【问题描述】:

我目前正在尝试一种在我的博客中投放广告的方法,用户可以通过明确选择博客文章的广告版本或无广告版本来选择观看广告。因此,从单个帖子中,比如“_posts/post1”,我需要生成 /posts/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)

【问题讨论】:

    标签: jekyll


    【解决方案1】:

    无论是作为普通页面还是作为collection 的一部分,Jekyll 都会生成一个单页输入文件,因为它是一步生成的。对于您的问题,我能想到的唯一方法是有两个单独的集合:

    _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}}
    

    坏事是您必须在每个帖子中编写三个文件(_post/postX.md_withads/postX.md_addfree/postX.md),但好的是 withads/postX.mdaddfree/postX.md 很短,并且有总是相同的结构。您甚至可以在正确生成 Jekyll 站点之前轻松地自动生成它们(换句话说,做 Jekyll 无法完成的工作,即执行两个步骤来生成页面)。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-12-01
      • 2020-05-07
      • 2015-11-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多