项目作者: computer-lab

项目描述 :
Netlify-compatible YAML transformer for gatsby
高级语言: JavaScript
项目地址: git://github.com/computer-lab/gatsby-transformer-yaml-netlify.git


gatsby-transformer-yaml-netlify

Parses YAML files. Supports a data layout that is compatible with netlify-cms.

DEPRECATION WARNING

This behavior was added to gatsby.
If you cannot upgrade you can still use this plugin by installing it via npm or
cloning it into a plugins/ folder as described in the docs.

Prerequisites

You must be using a version of node that supports object rest/spread (e.g v8.6.0).

Install

npm install --save gatsby-transformer-yaml-netlify@alpha

How to use

  1. // In your gatsby-config.js
  2. plugins: [
  3. `gatsby-transformer-yaml-netlify`,
  4. ]

Parsing algorithm

If you have a data layout like so:

  1. data/
  2. takers/
  3. a-taker.yml // value: a
  4. b-taker.yml // value: b
  5. leavers/
  6. a-leaver.yml // value: a
  7. b-leaver.yml // value: b

Then four nodes will be created:

  1. [
  2. {
  3. value: 'a',
  4. type: 'TakersYaml'
  5. },
  6. {
  7. value: 'b',
  8. type: 'TakersYaml'
  9. },
  10. {
  11. value: 'a',
  12. type: 'LeaversYaml'
  13. },
  14. {
  15. value: 'b',
  16. type: 'LeaversYaml'
  17. }
  18. ]

How to query

You’d be able to query your takers like:

  1. {
  2. allTakersYaml {
  3. edges {
  4. node {
  5. value
  6. }
  7. }
  8. }
  9. }

And your leavers like:

  1. {
  2. allLeaversYaml {
  3. edges {
  4. node {
  5. value
  6. }
  7. }
  8. }
  9. }