Community Plugin
View plugin on GitHubgatsby-yaml-full-import
Plugin for gatsby-transformer-yaml-full
to enable YAML files importing using
!import
tag.
Install
$ npm install gatsby-yaml-full-import gatsby-transformer-yaml-full
Configure
// gatsby-config.js
module.exports = {
plugins: [
{
resolve: 'gatsby-transformer-yaml-full',
options: {
plugins: [
'gatsby-yaml-full-import'
],
},
},
// ...
],
}
Usage
Use the !import
tag to import the content of a YAML file inside a property.
Importing YAML data from another file
YAML files
# post.yaml
title: Post title
# index.yaml
importedPost: !import ./post.yaml
Returning object
{
importedPost: {
title: 'Post title'
}
}
Importing a specific field
Use an exclamation mark (!
) to separate file name from field names.
YAML files
# post.yaml
authors:
- name: John Doe
- name: John Q.
# index.yaml
importedAuthorName: !import ./post.yaml!authors.0.name
Returning object
{
importedAuthorName: 'John Doe'
}