1

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

但是,例如,当我生成一个帖子时,我希望它在前面有某些变量。Jekyll Compose 的自述文件中提到了一个功能,它说您可以为帖子和草稿设置前端默认值。

我已经按照说明在我的站点的 config.yaml 中添加了所需的行,但是我使用 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:

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

最初我的 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

我希望我的自定义前端问题出现在我新生成的帖子中:

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

但我只得到用帖子/草稿创建的标准,例如:

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

有任何想法吗??

4

1 回答 1

1

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

基本上有 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
于 2019-10-09T11:10:23.613 回答