Let date param override date derived from file name

Hi!

I organize a large set of articles using file name with dates like 2019-10-05-my-post.

1) The config file contains these lines:

frontmatter:
  date:
    - :filename
    - :default

This works perfectly.

Yet, articles with future date file names do get published.

2) Therefore I added

  publishDate:
    - :filename
    - :default

Hugo now does not deploy future posts.

But now the date param does not override file name dates, which worked in 1). The date param is important e.g. if the time of publishing plays a role or to be able to change dates without renaming files.

What I need is actually a combination:

  1. Get date from file names,
  2. yet, do not publish future posts (date from file name).
  3. If date param is provided it always wins.

Is that possible?

By the way: I also tested

frontmatter:
  date:
    - :date
    - :filename
    - :default
  publishDate:
    - :date
    - :filename
    - :default

and some other combinations.

Thanks for your help!

You know the defaults?

:default stands for

[frontmatter]
date = ["date", "publishDate", "lastmod"]
lastmod = [":git", "lastmod", "date", "publishDate"]
publishDate = ["publishDate", "date"]
expiryDate = ["expiryDate"]

best way is to set publishDate in the content files :wink:

You have to define the parameters in the order you want to work, first come - first used

try

  publishDate:
    - :filename
    - :default

:default contains publishDate and date, no need to use it twice

Thanks a lot for your help, @ju52.

Yes, I read a lot about the defaults and I tested what you suggested.

No matter whether I use date or publishDate, front matter does not win over file name dates.

An example:

file name is `2000-01-01-test.md`
`date` and/or `publishDate` is `2019-10-06`
-->
`{{ .Date }}` is `2000-01-01`

(Yet, {{ .Lastmod }} is 2019-10-06.)

It would be excellent to be able to just overwrite the file name date with front matter.

If this is not possible I could try to override {{ .Date }} with {{ .Lastmod }}.

you have to use date and not :date

1 Like

Oh shoot! I just did not pay attention.

Thank you very much! Solved.

According to you name you probably know this proverb:

Wer lesen kann, ist klar im Vorteil :wink: