使用 Jekyll-compose 时,我无法为草稿或帖子设置默认的 front matter

I am unable to set default front matter for drafts or posts when using Jekyll-compose

我已经安装了 jekyll-compose gem 来简化创建页面,posts 等。在 documentation 中。我让它工作(即使用我能够生成的 CLI 命令、草稿、posts 和页面)。

然而,当我生成一个 post 时,我希望它在前面有一些变量。 Jekyll Compose 的自述文件中提到了一个功能,它说您可以为 posts 和草稿设置 front matter 默认值。

我按照说明在我的网站的 config.yaml 中添加了所需的行,但是 post 我使用 jekyll-compose 生成的草稿并没有生成我想要的变量.

Jekyll-compose 指出,如果你想要默认的前端变量,你需要在你的 _config.yaml:

中添加这样的东西
jekyll_compose:
  default_front_matter:
    drafts:
      description:
      image:
      category:
      tags:
    posts:
      description:
      image:
      category:
      tags:
      published: false
      sitemap: false

我已经尝试了上面的默认配置和下面我自己的配置

jekyll_compose:
  default_front_matter:
    drafts:
      main_img_url:
      author_name:
      categories:
      description:
    posts:
      main_img_url:
      author_name:
      categories:
      description:

但是当我生成新的 post 或草稿时,两者都不起作用。没有使调试变得困难的错误消息。

本来我的Jekyll版本是3.7.0,我想可能是Jekyll版本太旧的问题。然而,当我将 Jekyll 更新到 3.8.6 时,这个问题仍然存在。

当我为我的自定义变量设置默认值时它也不起作用,即:

jekyll_compose:
  default_front_matter:
    drafts:
        main_img_url: "https://images-we-got-pop.imgix.net/website/blog/pop-logo-small.png"
        author_name: "Me"
        categories: "general"
        description: "Description"
    posts:
        main_img_url: "https://images-we-got-pop.imgix.net/website/blog/pop-logo-small.png"
        author_name: "Me"
        categories: "general"
        description: "Description"

我的 _config 文件如下所示:

title: Title
email: your-email@domain.com
description: > # this means to ignore newlines until "baseurl:"
  Write an awesome description for your new site here. You can edit this
  line in _config.yml. It will appear in your document head meta (for
  Google search results) and in your feed.xml site description.
baseurl: "" # the subpath of your site, e.g. /blog
url: "" # the base hostname & protocol for your site, e.g. http://example.com
twitter_username: name
github_username:  name

# Build settings
markdown: kramdown
theme: minima
plugins:
  - jekyll-feed
  - jekyll-paginate-v2
exclude:
  - Gemfile
  - Gemfile.lock
  - Makefile
  - README.md

permalink: /pages/:year/:month/:day/:title/

jekyll_compose:
  default_front_matter:
    drafts:
      main_img_url:
      author_name:
      categories:
      description:
    posts:
      main_img_url:
      author_name:
      categories:
      description:

future: true

pagination:
  enabled: true
  sort_reverse: true
  trail:
    before: 1
    after: 1

我的 Gemfile 如下所示:

source "https://rubygems.org"
ruby RUBY_VERSION

gem "jekyll", "3.8.6"

# This is the default theme for new Jekyll sites. You may change this to anything you like.
gem "minima", "~> 2.0"

# If you want to use GitHub Pages, remove the "gem "jekyll"" above and
# uncomment the line below. To upgrade, run `bundle update github-pages`.
# gem "github-pages", group: :jekyll_plugins

# If you have any plugins, put them here!
group :jekyll_plugins do
   gem "jekyll-feed", "~> 0.6"
   gem "jekyll-paginate-v2", "~> 1.9"
   gem 'jekyll-compose', "~> 0.11"
end

我期待我的自定义封面出现在我新生成的 posts:

---
title: this-is-a-new-post
date: 2019-10-09 10:45 +0100
main_img_url:
author_name:
categories:
description:
---

但我只得到用 post/draft 创建的标准的,例如:

---
title: this-is-a-new-post
date: 2019-10-09 10:45 +0100
---

有什么想法吗??

好吧,在看到 GH 上自定义变量的语法与我在 rubydoc.info 上深入研究 jekyll-compose post 创建方法时发现的语法不同后,我设法自己解决了这个问题。

基本上有 PR 更改了合并到 master 但尚未发布的语法,因此我很难让它工作

最新版本的当前语法:

jekyll_compose:
  draft_default_front_matter:
    description:
    image:
    category:
    tags:
  post_default_front_matter:
    description:
    image:
    category:
    tags:
    published: false
    sitemap: false

与自述文件中说明的配置结构和 jekyll-compose 存储库中的 master 相比,但在我查看文档时尚未发布:

jekyll_compose:
  default_front_matter:
    drafts:
      description:
      image:
      category:
      tags:
    posts:
      description:
      image:
      category:
      tags:
      published: false
      sitemap: false