Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for native Org dates in frontmatter #7433

Merged
merged 1 commit into from
Jun 30, 2020

Conversation

sometimesfood
Copy link
Contributor

@sometimesfood sometimesfood commented Jun 27, 2020

When using Org mode with Hugo, it would be nice to have support for Org timestamps for the DATE header.

At the moment (hugo v0.72.0), DATE only supports Hugo's native syntax in Org files, therefore this is parsed correctly:

#+DATE: 2020-06-10

While this is not:

#+DATE: <2020-06-10 Wed>

Expected result

Using the following template to format a page's Date attribute should produce the correct date:

{{ dateFormat "January 2, 2006" .Date }}

Actual result

Output for #+DATE: 2020-06-10:

June 10, 2020

Output for #+DATE: <2020-06-10 Wed>:

January 1, 0001

Since Org mode defaults to the latter syntax, it would be great to have support for that in Hugo. Discussing this issue with @niklasfasching, he explained that this would fit better into Hugo than into go-org because of how Org frontmatter is handled by Hugo.

This pull request adds a simple parseORGDate function that does not touch the date value if it does not match an Org timestamp regexp, so that users who are currently using Hugo's native syntax do not experience any breakage.

@bep
Copy link
Member

bep commented Jun 27, 2020

This looks good to me. @niklasfasching ?

@sometimesfood
Copy link
Contributor Author

I just noticed I left a named capture in the regexp that is not used anymore (?P<date>). Sorry for that. I'll force-push an update to remove it and simplify the regexp.

@niklasfasching
Copy link
Contributor

LGTM

@sometimesfood
Copy link
Contributor Author

Thanks for your fast response!

Since I don't know if updated commits currently trigger a notification on GitHub: I removed the superfluous named capture in baa7a9d (replacing 96d4e13) and left the rest of the commit untouched.

@bep bep merged commit c66dc6c into gohugoio:master Jun 30, 2020
@sometimesfood sometimesfood deleted the org-date-header branch June 30, 2020 10:31
@github-actions
Copy link

This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 19, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants