gpt4 book ai didi

hugo - 从 Netlify CMS 添加到 Hugo 站点变量

转载 作者:行者123 更新时间:2023-12-01 13:25:43 26 4
gpt4 key购买 nike

我正在使用 Forty Theme为雨果与 Netlify CMS ,以及 config.toml文件有一个 Tiles 部分,如下所示:

# Tiles Section
[params.tiles]
enable = true

# Display your showcases here.
[[params.tiles.showcase]]
title =
subtitle =
image =
url =

我希望能够从 CMS 向磁贴部分添加条目。如何将变量添加到 params.tiles.showcase来自CMS?这是我的 config.yml 中的一个片段
collections:
- name: "blog"
label: "Blog post"
folder: "post/"
create: true
fields:
- { label: "Title", name: "title" }
- { label: "Publish Date", name: "date", widget: "datetime" }
- { label: "Description", name: "description", widget: "markdown", required: false }
- { label: "Featured Image", name: "image", widget: "image", required: false }
- { label: "Body", name: "body", widget: "markdown", required: false }

最佳答案

NetlifyCMS 配置允许您设置专门针对文件的集合类型。在下面的设置中,目标文件被称为 test.toml .当然,你可以让它定位config.toml但我将在此答案的后面解释为什么您可能希望将它分开以保持它在 中的清洁。雨果

指定 file而不是像我们在下面所做的那样为您的收藏项目创建一个文件夹。请记住,该值将是从您的存储库/项目根目录开始的路径。然后我们使用对象类型字段嵌套来配置字段以创建我们的对象路径。
config.yml

collections:
- name: "blog"
label: "Blog post"
folder: "post/"
create: true
fields:
- { label: "Title", name: "title" }
- { label: "Publish Date", name: "date", widget: "datetime" }
- { label: "Description", name: "description", widget: "markdown", required: false }
- { label: "Featured Image", name: "image", widget: "image", required: false }
- { label: "Body", name: "body", widget: "markdown", required: false }
- label: "Config"
name: "configs"
files:
- name: "test"
label: "test.toml"
file: "test.toml"
fields:
- name: "params"
label: "Params"
widget: "object"
fields:
- name: "tiles"
label: "Tiles"
widget: "object"
fields:
- {label: "Enable", name: "enable", widget: "boolean"}
- name: "showcase"
label: "Showcase Items"
widget: "list"
create: true # Allow users to create new documents in this collection
fields:
- { label: "Title", name: "title", widget: "string" }
- { label: "Sub Title", name: "subtitle", widget: "string" }
- { label: "Image", name: "image", widget: "image", required: false }
- { label: "URL", name: "url", widget: "string" }

输出:
test.toml
[params]

[params.tiles]
enable = true

[[params.tiles.showcase]]
image = "/images/some-image.jpg"
subtitle = "SubTitle 1"
title = "Title 1"
url = "/path1/"

[[params.tiles.showcase]]
image = "/images/some-other-image.jpg"
subtitle = "SubTitle 2"
title = "Title 2"
url = "/path2/"

推荐(雨果):由于此配置将针对某个展示页面的集合,因此最好将其放入带有前端的文件位置( tiles/_index.md)或创建一个数据文件( data/tiles.json)。 全部 config.toml 中的字段需要配置为能够写出集合。此时,您不能在 NetlifyCMS 中的文件设置中仅指定文件的一部分作为目标。

关于hugo - 从 Netlify CMS 添加到 Hugo 站点变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48365670/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com