lumeland / cms

A framework-agnostic CMS for Deno
https://lume.land/cms/
MIT License
62 stars 6 forks source link

Can't create object lists for lists without a key in YAML #28

Closed pixeldesu closed 1 week ago

pixeldesu commented 1 week ago

My site is composed from a lot of files inside _data that don't have an explicit key in YAML.

For example, I do have a _data/buttons.yaml that looks like so:

- title: Example site
  url: 'https://example.com'
  image: example.png
- title: Foo site
  url: 'https://foo.com'
  image: foo.png

Since I need a list of items the object-list field is probably what I need to go for...but what name do I need to pick, if it's even supported?

Because configuring it like so, by the assumption that buttons is also the global data key that I can access the items with in Lume (regularly), doesn't work

cms.document("buttons", "src:_data/buttons.yaml", [
  {
    name: "buttons",
    type: "object-list",
    fields: [
      {
        name: "title",
        type: "text"
      },
      {
        name: "url",
        type: "url"
      },
      {
        name: "image",
        type: "file",
        uploads: "buttons"
      }
    ]
  }
]);

To aid with issue reproduction, I created a cms branch in my website repository with my configuration: https://github.com/pixeldesu/pixelde.su/tree/cms

oscarotero commented 1 week ago

Hmmm, that's not possible right now. Let me think of a way to implement it.

oscarotero commented 1 week ago

I just released a new version v0.7.0 that allows to do that. You only have to set the name [] to indicate that this value is an array without a key. Your example would be:

cms.document("buttons", "src:_data/buttons.yaml", [
  {
    name: "[]",
    type: "object-list",
    fields: [
      {
        name: "title",
        type: "text"
      },
      {
        name: "url",
        type: "url"
      },
      {
        name: "image",
        type: "file",
        uploads: "buttons"
      }
    ]
  }
]);