Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
hugolib: Extract date and slug from filename #4494
This commit makes it possible to extract the date from the content filename. Also, the filenames in these cases will make for very poor permalinks, so we will also use the remaining part as the page
This should make it easier to move content from Jekyll to Hugo.
To enable, put this in your
[frontmatter] date = [":filename", ":default"]
This commit is also a spring cleaning of how the different dates are configured in Hugo. Hugo will check for dates following the configuration from left to right, starting with
So, if you want to use the
[frontmatter] date = [ "date",":fileModTime", ":default"] lastmod = ["lastmod" ,":fileModTime", ":default"]
[frontmatter] date = ["date","publishDate", "lastmod"] lastmod = ["lastmod", "date","publishDate"] publishDate = ["publishDate", "date"] expiryDate = ["expiryDate"]
The above will now be the same as:
[frontmatter] date = [":default"] lastmod = [":default"] publishDate = [":default"] expiryDate = [":default"]
An example of a custom configuration using a custom date front matter field:
[frontmatter] date = [ "myDate", ":default"]
changed the title from
WORK IN PROGRESS hugolib: Extract date and slug from filename
hugolib: Extract date and slug from filename
Mar 11, 2018
Mar 11, 2018
3 of 5 checks passed
@bep Thanks for the ping.
Sorry, but something feels wrong about this:
If someone wants to use the fileModTime, why would they want date to the first element? Also, :default already has the date element. Was that "date" element as the first one a typo?
I'm not saying they should. I just saying that this is how I would have configured it. I would not want the "last changed" timestamp if I had a date in front matter. As to the rest, I suggest you take it for a spin and see how it works.
If the user has date defined in the front-matter, it will never be set to the :fileModTime. Is that what you meant to do?
May be you meant to say: "So, if you want to use the file modification time as a fall-back in absence of date in front-matter, this can be a good configuration:"?
.. and of course, the same point for:
OK, that's what I meant by my alternative sentence above.. in that case, that config makes sense.
Your original description read as if the user wanted to use fileModTime as the higher precedence.
All in all, this feature looks great! This will really satisfy folks who want to sync pubdate with date or vice versa, or whatever :)