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

Ignore files from collection (hugo _index.md) #2727

Open
panakour opened this issue Oct 5, 2019 · 16 comments
Open

Ignore files from collection (hugo _index.md) #2727

panakour opened this issue Oct 5, 2019 · 16 comments

Comments

@panakour
Copy link

panakour commented Oct 5, 2019

I have a hugo site in which I have a content called "project".
My config file:

collections:
  - name: "project" 
    editor:
      preview: false
    label: "Project"
    folder: "site/content/project"
    create: true
    fields:
      - {label: "Featured", name: "featured", widget: "boolean", default: false}
      - {label: "Title", name: "title", widget: "string"}
      - {label: "Publish Date", name: "date", widget: "datetime"}
      - {label: "Project Date", name: "project_date", widget: "datetime"}
      - {label: "Head Image (Recommended 1920x1080)", name: "head_image", widget: "image", required: false}
      - {label: "Thumbnail Image (Recommended 360x560)", name: "thumb_image", widget: "image", required: false}
      - {label: "Images", name: "images", widget: list, field:
        {label: "Image (Recommended 800x500)", name: "image", widget: "image"}}
      - {label: "Description", name: "body", widget: "markdown"}

The admin is working fine and I can create/edit my projects. The issue is that the admin also show the _index.md file which is used from hugo for the list page. Also this file has different front-matter (I have a file collection for this to edit from the cms).

The solution you'd like
For hugo site should automatically excludes this file from the collection.

alternatives you've considered
Maybe a better and more generic solution for all SSGs is to have a config option to let us give an array with some files to be ignored

@panakour panakour changed the title Ignore files from collection Ignore files from collection (hugo _index.md) Oct 5, 2019
@erquhart
Copy link
Contributor

Should be possible, agreed.

@panakour
Copy link
Author

maybe this issue #1472 would minimize the needed of this feature

@GabriFila
Copy link

Hi everyone!
Have there been any updates on this issue? I've looked at #1472 but I didn't find any solution or talk related to this. I'm interested in this feature to show only the actual collection content with a Hugo site and not "collection metadata" files.
I'd be happy to help implement this

@erezrokah
Copy link
Contributor

Hi @GabriFila, the current workaround is to use https://www.netlifycms.org/docs/collection-types#filtered-folder-collections
e.g. have a show field on entries and add a filter entries with that value set to true.
Also related #1000

@GabriFila
Copy link

Thank you @erezrokah, I'll try that.
Is there an interest to implement this without a workaround but with an actual ignore field, maybe with a regex inside or a glob pattern? Would it create problems?

@erezrokah
Copy link
Contributor

erezrokah commented Jul 1, 2020

I'm going to have a look at the suggestion to add a type: exclude/include to filter and also to support entry meta data like filename.
Feels like it shouldn't be much of an effort, but I'll have to verify it.
Using a regex/glob might be a bit tricky to do without a breaking change

@GabriFila
Copy link

Thank you! I have little experience with React, I don't know if I could help but if you need me I'd be happy to do it!

@OdairTrujillo
Copy link

OdairTrujillo commented Jul 14, 2020

Hi @GabriFila, the current workaround is to use https://www.netlifycms.org/docs/collection-types#filtered-folder-collections
e.g. have a show field on entries and add a filter entries with that value set to true.
Also related #1000

I used this workaround, it's easy and clean. Just do something like this in your collection config and your md files to be ignored or included:

Front matter of a file to be included (I removed some lines from your example for clarity):

---
featured: true
title: Some title
date: 2020-07-14T22:49:10.427Z
visible: true
---

Front matter of a file to be excluded or filtered:

---
featured: true
title: A title for an _index.md
date: 2020-07-14T22:49:10.427Z
visible: false
---

Option and fields to use into your collection config:

collections:
  - name: "project" 
    editor:
       preview: false
    label: "Project"
    folder: "site/content/project"
    create: true
    filter: {field: "visible", value: true}
    fields:
      - {label: "Featured", name: "featured", widget: "boolean", default: false}
      - {label: "Title", name: "title", widget: "string"}
      - {label: "Publish Date", name: "date", widget: "datetime"}
      - {label: "Visible", name: "visible", widget: hidden, default: true}

Pay attention to the filter option, visible label, and the visible fields in the frontmatter of the files. Now all your new files created with the CMS will include the visible label, hiding the files with visible: false for the CMS, and without any interaction with the user.

@GabriFila
Copy link

Thank you for mentioning the hidden widget, I used with the filter but it was still visible to the end user, now it will be much better

@erezrokah erezrokah self-assigned this Jul 15, 2020
@OdairTrujillo
Copy link

OdairTrujillo commented Jul 15, 2020

Thank you for mentioning the hidden widget, I used with the filter but it was still visible to the end user, now it will be much better

Let us know if you resolved the problem. ¿Did you notice the filter option?

@GabriFila
Copy link

Yes yes I solved my problem, it's still a workaround but is fine for me. If and when there will be another way I'll change it.
Thank you

@erezrokah erezrokah removed their assignment Aug 18, 2020
TechplexEngineer added a commit to TechplexEngineer/Rokenbok-Archive that referenced this issue Sep 30, 2020
@LorenzBischof
Copy link

LorenzBischof commented Jan 25, 2021

I really dislike this workaround, because it requires additional frontmatter in every page. It would be better if we could define: filter: {field: "visible", value: "!false"} or ignore: {field: "visible", value: "false"} or something similiar, so we only need to edit the hidden pages.

@andreasbalevik
Copy link

andreasbalevik commented Jan 29, 2022

I really dislike this workaround, because it requires additional frontmatter in every page. It would be better if we could define: filter: {field: "visible", value: "!false"} or ignore: {field: "visible", value: "false"} or something similiar, so we only need to edit the hidden pages.

Agreed. To exclude one pages, you have to define additional frontmatter for all other pages. The workaround is also not compatible with the i18n support (beta feature). Having a default value result in creating index.md for all language types even though you only edited one language..

Would really like a fix for this. All my sites are using Hugo, and im using the i18n beta feature. So the workaround is not working for me.

The problem is, as mentioned. I want to edit all my articles, but not the article list view.(since it has different fields)

@martinjagodic
Copy link
Member

I use Hugo with i18n too and this workaround works fine.

The fiter setting on collection:
filter: {field: visibleInCMS, value: true}

The field in collection:
{name: visibleInCMS, widget: hidden, default: true, i18n: duplicate}

If you set it correctly, you should see visibleInCMS: true on every page that you save with CMS.

I noticed that adding this only to default language is enough.

@andreasbalevik
Copy link

andreasbalevik commented Jan 31, 2022

"If you set it correctly, you should see visibleInCMS: true on every page that you save with CMS."

And thats the problem. If you have configures 2 languages with i18n (nb, en). Since a default value visibleInCMS: true is provided in the config.yml, the CMS will create index.nb.md and index.en.md (even though you only added content to nb, and left en blank). In some cases you only want to create a page for a specific language.

EDIT: adding required: true to a field also does not work as intented. (Adding content to nb, leaving en blank. Allowed to save / publish content).

i18n:
  structure: multiple_files
  locales: [nb,en]
  default_locale: nb

media_folder: static/img
public_folder: /img
collections:
  - name: 'blog'
    i18n: true
    label: 'Blog'
    folder: 'content/blog'
    create: true
    path: '{{slug}}/index'
    slug: '{{year}}-{{month}}-{{day}}-{{slug}}'
    fields:
      - { label: 'Title', name: 'title', widget: 'string', i18n: true, required: true }
      - { label: 'Body', name: 'body', widget: 'markdown', i18n: true}
      - { name: visibleInCMS, widget: hidden, default: true, i18n: duplicate}

@egf-ch
Copy link

egf-ch commented Aug 7, 2024

I have stumbled upon the same issue. The _index.md is showing up in my collection.

Has somebody found a better solution than setting an extra field since this was last discussed?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

9 participants