Grav - 蓝图
Blueprints 蓝图是有关资源(信息来源)的元数据信息。它有两个用途 −
- 首先是资源标识本身。
- 其次是关于表单。
此完整信息保存在每个插件或主题中的 blueprints.yaml 文件中。
资源标识
在 blueprints.yaml 文件中,为每个主题和插件定义标识。在蓝图未格式化和编译完美之前,不会将资源添加到 Grav 存储库中。
蓝图示例
name: plugin name
version: 0.6.0
description: Adds an advanced plugin to manage your site
icon: empire
author:
name: Team Grav
email: devs@getGrav.org
url: http://getGrav.org
homepage: https://github.com/getGrav/Grav-plugin-assets
keywords: assets, plugin, manager, panel
bugs: https://github.com/getGrav/Grav-plugin-assets/issues
readme: https://github.com/getGrav/Grav-plugin-assets/blob/develop/README.md
license: MIT
dependencies:
- form
- email
- login
form:
validation: loose
fields:
Basics:
type: section
title: Basics
underline: false
enabled:
type: hidden
label: Plugin status
highlight: 1
default: 0
options:
1: Enabled
0: Disabled
validate:
type: bool
以下几个属性是可选的,其中一些用于提供您的身份和资源。
| Sr.No. | 属性和描述 |
|---|---|
| 1 | name* 提及资源的名称。 |
| 2 | version* 指定资源的版本。 |
| 3 | description* 提供关于资源的简要描述。不得超过 200 个字符。 |
| 4 | icon* 指定用于开发新主题或插件的图标库。 |
| 5 | author.name* 指定开发者的姓名。 |
| 6 | author.email(可选) 指定开发人员。 |
| 7 | author.url(可选) 指定开发人员的 URL 主页。 |
| 8 | homepage(可选) 指定资源的主页分配的 URL。 |
| 9 | docs(可选) 指定您为资源编写的文档链接资源。 |
| 10 | demo (可选) 指定演示资源的链接。 |
| 11 | guide (可选) 指定资源的操作指南或教程的链接。 |
| 12 | keywords (可选) 指定与您的资源。 |
| 13 | bugs (可选) 指定可以报告问题或错误的网址。 |
| 14 | license (可选) 指定您的资源许可证,即 MIT、GPL 等。 |
| 15 | dependencies (可选) 指定插件或主题。 |
以下是登录插件蓝图的示例 −
name: Login version: 0.3.3 description: Enables user authentication and login screen. icon: sign-in author: name: Team Grav email: devs@getGrav.org url: http://getGrav.org keywords: admin, plugin, login homepage: https://github.com/getGrav/Grav-plugin-login keywords: login, authentication, admin, security bugs: https://github.com/Getgrav/Grav-plugin-login/issues license: MIT
表单
如果您希望主题或插件具有可从管理界面直接配置的选项,则可以使用表单填充 blueprints.yaml 文件。此资源的一部分可以通过 管理插件 进行配置,该插件由 表单 元数据定义。
以下是 Archives 插件 archives.yaml 文件的示例。
enabled: true built_in_css: true date_display_format: 'F Y' show_count: true limit: 12 order: by: date dir: desc filter_combinator: and filters: category: blog
这些是插件的默认设置。若要在不使用管理插件的情况下配置它们,用户必须将此文件复制到 /user/config/plugins/archives.yaml 文件夹中并进行更改。您可以正确提供 archives.yaml 文件;您可以选择在用户的管理界面中更改设置。
保存更改后,它将自动写入 <your_folder_name>/user/config/plugins/archives.yaml。
Archives 插件的 blueprint.yaml 文件包含如下所示的结构 −
name: Archives
version: 1.3.0
description: The **Archives** plugin creates links for pages grouped by month/year
icon: university
author:
name: Team Grav
email: devs@getGrav.org
url: http://getGrav.org
homepage: https://github.com/getGrav/Grav-plugin-archives
demo: http://demo.getGrav.org/blog-skeleton
keywords: archives, plugin, blog, month, year, date, navigation, history
bugs: https://github.com/getGrav/Grav-plugin-archives/issues
license: MIT
form:
validation: strict
fields:
enabled:
type: toggle
label: Plugin status
highlight: 1
default: 1
options:
1: Enabled
0: Disabled
validate:
type: bool
date_display_format:
type: select
size: medium
classes: fancy
label: Date Format
default: 'jS M Y'
options:
'F jS Y': "January 1st 2014"
'l jS of F': "Monday 1st of January"
'D, m M Y': "Mon, 01 Jan 2014"
'd-m-y': "01-01-14"
'jS M Y': "10th Feb 2014"
limit:
type: text
size: x-small
label: Count Limit
validate:
type: number
min: 1
order.dir:
type: toggle
label: Order Direction
highlight: asc
default: desc
options:
asc: Ascending
desc: Descending
以下是 archive.yaml 中的表单元素。
Toggle
enabled:
type: toggle
label: Plugin status
highlight: 1
default: 1
options:
1: Enabled
0: Disabled
validate:
type: bool
Select
date_display_format:
type: select
size: medium
classes: fancy
label: Date Format
default: 'jS M Y'
options:
'F jS Y': "January 1st 2014"
'l jS of F': "Monday 1st of January"
'D, m M Y': "Mon, 01 Jan 2014"
'd-m-y': "01-01-14"
'jS M Y': "10th Feb 2014"
Text
limit:
type: text
size: x-small
label: Count Limit
validate:
type: number
min: 1
根元素 Enabled、date_display_format 和 limit 是选项。此根元素中存在的字段决定类型、大小、标签、默认值和选项。根据字段类型,其他字段可能会发生变化;例如,select 字段需要选项列表。
订单方向
order.dir:
type: toggle
label: Order Direction
highlight: asc
default: desc
options:
asc: Ascending
desc: Descending
此字段由嵌套选项组成。plugins/admin/themes/Grav/templates/forms/fields 中可以使用许多字段类型。正如我们在 archive.yaml 文件中看到的,表单验证设置为严格。当验证设置为严格时,对于所有选项,您都必须添加蓝图表单,否则在保存时会弹出错误。当您只想将两个字段自定义到管理界面时,可以将 form.validation 设置为宽松。
下表简要说明了与上述表单元素相关的字段。
| Sr.No. | 字段 &描述 |
|---|---|
| 1 | Type 表示字段类型。 |
| 2 | Size 指定字段的大小。 |
| 3 | Label 指定字段的标签。 |
| 4 | Validate 验证字段的类型和字段中输入的最小长度。 |
| 5 | Default 设置默认字段。 |
| 6 | Options 指定选项列表。 |
| 7 | Classes 指定字段的类。 |
管理中可用的表单字段
有许多内置表单字段可供插件和主题使用,也可以创建自己的表单字段。下表列出了可用的表单字段 −
常见表单字段
| Sr.No. | 字段和说明 |
|---|---|
| 1 | Checkbox 显示单个复选框。 |
| 2 | Checkboxes 显示复选框列表。 |
| 3 | Date 包含日期字段。 |
| 4 | Datetime 包含日期和时间字段。 |
| 5 | 包含带验证的电子邮件地址字段。 |
| 6 | Password 包含以点格式显示的密码字段。 |
| 7 | Hidden 包含隐藏的输入字段。 |
| 8 | Radio 允许从列表中仅选择一个选项。 |
| 9 | Select 此字段包含几个选项。 |
| 10 | Spacer 向表单添加标题、文本或水平线。 |
| 11 | Text 包含普通文本字段。 |
| 12 | Textarea 包含多行文本输入。 |
特殊表单字段
| Sr.No. | 字段和说明 |
|---|---|
| 1 | Array 添加多个键值行。 |
| 2 | Ignore 未使用的字段将被删除。 |
| 3 | Columns 将表单分成多个列。 |
| 4 | Column 显示单个列。 |
| 5 | Dateformat 设置日期和时间格式。 |
| 6 | Display 显示文本值,不带任何输入值。 |
| 7 | Frontmatter 页面以原始格式显示。 |
| 8 | List 显示没有键的项目列表。 |
| 9 | Markdown 显示 markdown 编辑器。 |
| 10 | Pages 显示页面列表。 |
| 11 | Section 设置页面分为多个部分,每个部分都有一个标题。 |
| 12 | Selectize 用于选择框。 |
| 13 | Tabs 设置分为标签列表。 |
| 14 | Tab tabs 字段用于提供选项卡。 |
| 15 | Taxonomy 它是一个预先配置的选择,用于选择分类法。 |
| 16 | Toggle 它表示指定输入类型开启或关闭的切换效果。 |

