question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Ignore files from collection (hugo _index.md)

See original GitHub issue

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

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:21
  • Comments:15 (4 by maintainers)

github_iconTop GitHub Comments

16reactions
jyniybinccommented, 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.

6reactions
OdairTrujillocommented, Jul 15, 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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Ignore .md files in build with particular param set - HUGO
I know that hugo has ignoreFiles variable in configuration that ignores files from rendering and are not included in build, but that's based...
Read more >
Hugo exclude file types from page bundle? - Stack Overflow
As per the documentation, you can exclude content files with the ignoreFiles directive. In your specific case, add the following to your config....
Read more >
Changelog — ox-hugo - Org to Hugo exporter
Provides another means of setting the Org-hugo base directory. ... Just as ox-md.el supports `#+​​md:` and ox-html.el supports `#+​​html:`.
Read more >
rstudio/blogdown: docs/02-hugo.Rmd - Rdrr.io
Basically, Hugo generates foo/index.html for foo.md by default instead of ... A Hugo theme\index{Themes} is a collection of template files and optional ...
Read more >
Hugo: ignore _index.md in list templates | kevingimbel.de
`` checks if the file name is not _index.md - this will ignore all _index.md files from being rendered with the article-preview.html template....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found