lumeland / cms

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

Unexpected document behaviour #16

Closed Steffo99 closed 2 months ago

Steffo99 commented 3 months ago

Heya, since this repository seems to be pretty new, I hope you don't mind if I open a couple issues about my experience in learning to use LumeCMS, so that it can be made even easier to use!

What I did

I defined a document with the following code:

cms.document(
    "site",
    "src:site.yml",
    [
        {
            name: "title",
            type: "text",
            label: "Site title", 
            description: "The main title of the site.",
        }
    ]
)

Then I went to http://localhost:3000/admin/document/site to set a title.

What I expected

I expected an empty site.yml file to be created, and then it to be filled with what I entered in the CMS form.

What happened

The webpage returned:

There was an error. See logs for more info.

The logs returned:

ERROR NotFound: 2024-06-14T09:17:07.839Z [GET] http://localhost:3000/admin/document/site - No such file or directory (os error 2): readfile './site.yml'
    at Object.readTextFile (ext:deno_fs/30_fs.js:878:24)
    at FsEntry.readData (https://cdn.jsdelivr.net/gh/lumeland/cms@v0.5.1/storage/fs.ts:104:32)
    at Document.read (https://cdn.jsdelivr.net/gh/lumeland/cms@v0.5.1/core/document.ts:45:30)
    at template (https://cdn.jsdelivr.net/gh/lumeland/cms@v0.5.1/core/templates/document/edit.ts:18:31)
    at Object.handler (https://cdn.jsdelivr.net/gh/lumeland/cms@v0.5.1/core/routes/document.ts:18:9)
    at eventLoopTick (ext:core/01_core.js:168:7)
    at async dispatch (https://jsr.io/@hono/hono/4.4.5/src/compose.ts:74:17)
    at async handler (https://jsr.io/@hono/hono/4.4.5/src/hono-base.ts:224:12)
    at async dispatch (https://jsr.io/@hono/hono/4.4.5/src/compose.ts:74:17)
    at async dispatch (https://jsr.io/@hono/hono/4.4.5/src/compose.ts:74:17)

How I worked around the issue

By manually creating a site.yml file containing the following:

title: ""
oscarotero commented 3 months ago

@Steffo99 Thanks for the feedback!

Unlike Collections, Documents cannot create or remove files, only edit the existing one. But maybe I can relax this restriction and allow to create it if it doesn't exist.

Steffo99 commented 2 months ago

Forgive me if I ask, but... why is the restriction there?

It feels a bit counter-intuitive, is there a technical reason for it?

oscarotero commented 2 months ago

No technical reason. It's just that the CMS has been designed to edit an already created website. And while collections can grow over time (because you can create new posts in a blog, for example), documents are intended to edit files already existing (like a json file with settings, a special page like the homepage, etc).

Steffo99 commented 2 months ago

Thanks for implementing this!