Couscous icon indicating copy to clipboard operation
Couscous copied to clipboard

Extend Metadata with YAML data files defined in configuration

Open adrienrn opened this issue 8 years ago • 3 comments

I took the liberty to implement a first attempt at mimicking Jekyll _data directory by loading files in configuration as if it was included in couscous.yml.

It works by defining the dataFiles in your couscous.yml:

...
# List of files to parse and load into the configuration and make available to twig templates by their key
# Paths are relative to the optional source path given when generating the website, repository root by default
dataFiles:
  myCustomFile: data/my-custom-file.yml
  otherFile: data/other-file.yml
...

Path to those files are resolved related to project source directory, repository root by default. You can then use values in any twig templates by their keys, as if it was defined in the couscous.yml file itself.

  • [x] Load YAML files
  • [ ] Load JSON files
  • [ ] Load CSV files

See #174 for more informations.

adrienrn avatar Jul 15 '16 22:07 adrienrn

Hi, thanks for the pull request. We cannot merge a pull request without tests though, could you write some?

Also I would rather see the section named import rather than dataFiles. That section could also contain a list of files, not a map:

import:
    - data/my-custom-file.yml
    - data/other-file.yml

Since it would be a straight import the keys would not be necessary: it makes the whole thing simpler to think about imports than "data files", and it also restricts less the possibilities (those files could contain configuration, not data).

mnapoli avatar Jul 20 '16 06:07 mnapoli

Hi, thanks for the pull request. We cannot merge a pull request without tests though, could you write some?

Also I would rather see the section named import rather than dataFiles. That section could also contain a list of files, not a map

Done something and added some unit tests too.

Before merging, there's something that I'm not quite sure it's the best idea.

I'm using array_replace_recursive to merge imported files and couscous.yml. It works for the most part but if you want to overwrite a list (such as include) you have to repeat the original value. See the unit test.

Don't sure we want to merge though, but difficult to handle collision if we do not merge.

adrienrn avatar Jul 21 '16 23:07 adrienrn

I'm using array_replace_recursive to merge imported files and couscous.yml. It works for the most part but if you want to overwrite a list (such as include) you have to repeat the original value. See the unit test.

I think it's fine to overwrite the whole key and not merge values. It would be very difficult to do otherwise because what we would like to happen depends a lot on the configuration value (sometimes we would want to merge, sometimes we would want to replace). Always replace is easier.

mnapoli avatar Jul 26 '16 20:07 mnapoli