Skip to content

page.date should be undefined for non-posts #115

@sampsyo

Description

@sampsyo

In "original" Jekyll, it seems like page.date is only defined when it comes from the filename or front matter. In gojekyll, page.date always appears to be defined—even for ordinary, non-post pages that don't have an explicit date. This date comes from the source file's mtime. I believe that seems from the final fallback case here:

gojekyll/pages/page.go

Lines 166 to 177 in f7b210e

func (f *file) PostDate() time.Time {
switch value := f.fm["date"].(type) {
case time.Time:
return value
case string:
t, err := evaluator.ParseDate(value)
if err == nil {
return t
}
}
return f.modTime
}

Do you think it might be the right thing to do here to remove the final modTime case and to return some empty value instead? If so, I can put together a PR.

(The reason this came up for me is that I use {% if page.date %} in some templates to determine whether we're rendering a post. I could presumably use some other signal instead, but I'm not sure what. :)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions