Open panakour opened 5 years ago
Should be possible, agreed.
maybe this issue #1472 would minimize the needed of this feature
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
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 https://github.com/netlify/netlify-cms/issues/1000
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?
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
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!
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 totrue
. 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.
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
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?
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
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.
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"}
orignore: {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)
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.
"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}
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?
I have a hugo site in which I have a content called "project". My config file:
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