hugomods / decap-cms

[Experimental] Hugo Decap CMS Module
https://hugomods.com
MIT License
6 stars 1 forks source link

Allow extending collection's configurations #10

Closed razonyang closed 9 months ago

razonyang commented 1 year ago

Sth likes this:

decap_cms:
  collections:
    foo:
      extends: [
        "bar",
        "fizz"  
      ]
yippyskippy commented 9 months ago

@razonyang it would be helpful to clarify how this works in your documentation. Previously I understood params.decap_cms to basically be a clone of the normal config.yml file but this introduces new things which deviate from Decap's spec, IIUC

razonyang commented 9 months ago

it would be helpful to clarify how this works in your documentation.

I didn't write any details for this PR because it's not stable, it maybe broken in future version.

but this introduces new things which deviate from Decap's spec.

I don't think so, it was defined with keys that with a leading _ (underline) char, and will be removed in the generated config.yml. That is, those module's scope parameters is used internally, won't be a part of the final configuration.

If you want to see how this feature work, here is an example.

params:
  decap_cms:
    # extensible configurations for collections.
    _configs:
      # the key is the name of the extensible config, it's configuration should be same as the `collection`.
      i18n:
        i18n: true
        nested:
          depth: 5
        meta:
          path:
            widget: string
            label: Path
            index_file: _index
    collections:
      news:
        label: News
        label_singular: News
        create: true
        name:  news
        folder: content/news
        _extends:
          - i18n # extends the `_configs.i18n` config.
          - field_title # extends the built-in title field.
          - field_description # extends the built-in description field.
          - field_draft # extends the built-in draft field.
          - field_body # extends the built-in body field.
        nested: # override the nested setting from `i18n` config.
          depth: 3
        fields:
          - {name: description, required: false} # override built-in description field to be optional, default is required.
          - {label: Foo, name: foo, widget: string} # add extra fields.
          - {label: Bar, name: bar, widget: string} # add extra fields.