Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Setting content extension or filename to json allows editing but fails to list #13

Closed
gryzzly opened this issue Feb 24, 2024 · 6 comments

Comments

@gryzzly
Copy link

gryzzly commented Feb 24, 2024

Hey, awesome work on this!

I want to use .json to store the contents. Setting filename property works and correctly opens editor and saves files, however, the listing on collection subview is doesn’t pick up the titles and there is an error shown about front matter:

Screenshot 2024-02-24 at 14 29 42
@gryzzly
Copy link
Author

gryzzly commented Feb 24, 2024

My settings look like this:

content:
  - name: posts
    label: Posts
    path: content/posts
    format: json
    extension: json
    filename: '{year}-{month}-{day}-{primary}.json'
    type: collection
    view:
      fields: [ title, published, date ]
    fields:
      - name: published
        label: Published
        type: boolean
        default: true
      - name: date
        label: Date
        type: date
      - name: title
        label: Title
        type: string
      - name: body
        label: Body
        type: rich-text
      

@hunvreus
Copy link
Member

Can you give me a sample file that you'd like to save? I've just finished preparing a new release that I think should cover your use case. Right now collections assume you have a frontmatter format, it doesn't really allow you to have a collection of pure JSON files.

@hunvreus
Copy link
Member

BTW, extension will be deprecated in the next release, I'll be relying on the filename.

@gryzzly
Copy link
Author

gryzzly commented Feb 24, 2024

Hey, thanks for looking into this. Doesn’t frontmatter translate directly to JSON key value? And then there are also title and body? Smth like this:

{
  "published": true,
  "date": "2024-02-18",
  "title": "something",
  "body": "here is something"
}

I think specifying "format" as JSON should be enough for the filename to pick up saving it as json, but if it’s possible to set that via filename that’s enough of course

@hunvreus
Copy link
Member

0.3.0 is out and should fix a lot of the issues you've had before.

You can save JSON files now;

content:
  - name: posts
    label: Posts
    path: content/posts
    filename: '{year}-{month}-{day}-{primary}.json'
    type: collection
    view:
      fields: [ title, published, date ]
    fields:
      - name: published
        label: Published
        type: boolean
        default: true
      - name: date
        label: Date
        type: date
      - name: title
        label: Title
        type: string
      - name: body
        label: Body
        type: rich-text

Using this config I was able to save the following post:

{
  "published": true,
  "date": "2024-02-29",
  "title": "This is my first JSON entry",
  "body": "_Hello_ **world**!"
}

It shows properly in the collection as well.

@gryzzly
Copy link
Author

gryzzly commented Mar 1, 2024

Looks like it’s fixed! Thanks!

@gryzzly gryzzly closed this as completed Mar 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants