statiqdev / Statiq.Web

Statiq Web is a flexible static site generator written in .NET.

Home Page:https://statiq.dev/web

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Post is published even if the published date is only tomorrow

TechWatching opened this issue · comments

When running a deployment of my statiq website, articles planned for the next days are published.

For instance, I have an article with a published date to 18th December 2022. If I run dotnet run --preview the 17th December it will be available on my website. I first thought it has to do with time zone but I did it in the middle of the day and I am in UTC+1 (France).

My appsettings file is the following:

{
    "Host": "techwatching.dev",
    "LinksUseHttps": true,
    "SiteTitle": "Alexandre Nédélec",
    "GenerateSearchIndex": true,
    "DateTimeInputCulture": "fr-fr"
}

The front matter of my article looks like this:

Title: "When Pulumi met Nuke: a .NET love story"
Lead: Pushing an ASP.NET Core API to Azure using .NET from provisioning to deployment
Published: 18/12/2022
Image: /images/trees_1.jpg

Is it a bug or something I misconfigured?

What about the day after next (like if you had set the published date to the 19th in the scenario above)? If the behavior is correct in that case for more than a day in the future, then I'm guessing it's a bug - either the culture isn't applying correctly, the culture + timezone is doing something unexpected, or the date comparison isn't doing what it should.

Looking into this now to see if I can reproduce it.

I can reproduce without setting culture, so it's not a culture bug. One day in the future gets published while two or more does not. Now that I can play around with the behavior, I should be able to get a fix out momentarily once I figure out where the problem is.

Figured it out, definitely a bug. The issue is that the toggle to publish or not is actually based on the Excluded metadata value. That way, it can be set per-document independent of the published date, or overridden entirely with a different algorithm providing a lot of flexibility (I.e. "only publish things within the last month" or whatever).

When Excluded is not explicitly set, Statiq Web sets it to this:

Config.FromDocument(doc => doc.GetDateTime(WebKeys.Published) > DateTime.Today.AddDays(1))

So for a situation like your initial scenario, the document part doc.GetDateTime(WebKeys.Published) gets set to the start of the specified day, or 12:00 AM on 18th December 2022. Then the comparison part gets set to DateTime.Today.AddDays(1) which, if it's the 17th of December would end up being a DateTime.Today of 12:00 AM on 17th December plus one day to equal 12:00 AM on 18th December 2022 - which is the same value.

It occurs to me that I probably don't want to use DateTime.Today at all - that "rewinds" the current date/time to the previous midnight, which isn't helpful if you're trying to publish things at a specific time (as opposed to a specific day).

Fix will go out with the next release.

Great thanks a lot !