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.

content filtering based on today's date and published date frontmatter (draft content)

See original GitHub issue

Is there some configuration available, to draft the content based on published date used as frontmatter?

By drafting content, I mean that the content is not visible on production build until marked published, while everything is visible in development mode.

I know that we can use a boolean published variable to filter content. But, just curious to know if there is some other way to publish content based on date variable and today’s date.

I couldn’t figure out how to avoid filtering in development mode.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

4reactions
khrome83commented, Jul 11, 2019

This worked great. I made one small change for anyone reading this -

api.loadSource(store => {
  if (process.env.NODE_ENV === "production") {
    const posts = store.getContentType('Post')

    posts.data().forEach(node => {
      if (node.published !== true) {
        posts.removeNode(node.id) // must remove by node id
      }
    }
  }

I wanted to see drafts locally. This way only my deployment server which I set NODE_ENV in build lambda too “production”.

3reactions
hjvedvikcommented, Jul 11, 2019

@khrome83 Sure 😃

As a workaround, for now, you can get the content type and remove the node in the loadSource hook. loadSource in your gridsome.server.js file will be executed after plugins so the content type should exist.

api.loadSource(store => {
  const posts = store.getContentType('Post')

  posts.data().forEach(node => {
    if (node.published !== true) {
      posts.removeNode(node.id) // must remove by node id
    }
  })
})
Read more comments on GitHub >

github_iconTop Results From Across the Web

Front Matter - Hugo
Hugo allows you to add front matter in yaml, toml, or json to your content files. Front matter allows you to keep metadata...
Read more >
How do I show a Jekyll Collection item on a specific date ...
My first thought was to add date: 2020-06-17 to the front matter then run a check to see if that matches today's date...
Read more >
Updates | Front Matter
#360: Define which content types can be used on your page folders ... #283: Added published date sorting options for the content dashboard ......
Read more >
Jekyll cheatsheet - Devhints
The one-page guide to Jekyll: usage, examples, links, snippets, and more.
Read more >
Creating Unlisted Content in Hugo - Brian P. Hogan
You can do this by adding a new piece of front matter to your pages, and then altering your themes to filter those...
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