Eleventy: Support yaml format in global data files

Created on 3 Jul 2020  路  2Comments  路  Source: 11ty/eleventy

Is your feature request related to a problem? Please describe.
Global data files are very usefull to store the common data that can be used in all pages. But currently only accept json and js formats. This is not convenient for people with no technical skills that only want to edit the content of a website (menu, footer text, cookies banner, etc).

Describe the solution you'd like
I'd like to be able to place yaml files in _data folder in the same way that I can put js and json.

Describe alternatives you've considered
An alternative is a js file that parse other yaml file and export the data, but it's a nuisance :)

enhancement

Most helpful comment

@scottishstoater OMG, I don't know why I didn't see this. Thanks for your help!

Maybe, yaml format could be enabled by default because js-yaml is installed anyway (is a dependency of gray-matter, used by eleventy to parse the front-matter of the files), so it does not requires any additional dependency.

All 2 comments

@oscarotero You can use yaml, it's just not turned on by default 馃槉

  1. Install js-yaml as a dependency.
npm i -D js-yaml
  1. In your .eleventy.js require the module and inside your eleventyConfig tell eleventy to support yaml:
const yaml = require("js-yaml");

module.exports = eleventyConfig => {
  eleventyConfig.addDataExtension("yaml", contents => yaml.safeLoad(contents));
};

Hope this helps 馃槉

Official docs: https://www.11ty.dev/docs/data-custom/#yaml

@scottishstoater OMG, I don't know why I didn't see this. Thanks for your help!

Maybe, yaml format could be enabled by default because js-yaml is installed anyway (is a dependency of gray-matter, used by eleventy to parse the front-matter of the files), so it does not requires any additional dependency.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jamrelian picture jamrelian  路  3Comments

AjitZero picture AjitZero  路  3Comments

nebrelbug picture nebrelbug  路  3Comments

smaimon picture smaimon  路  3Comments

DirtyF picture DirtyF  路  3Comments