-
-
Notifications
You must be signed in to change notification settings - Fork 55
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
Date format needs to be in RFC3339 format if setting front-matter to YAML #7
Comments
Oh, I see. Maybe we should turn |
+1 This, because if using YAML or TOML, we need to use the correct date/time type. Otherwise, if the user processes that Markdown file by a static site generator, the YAML/TOML parser in that tool would complain. |
I implemented this but have not pushed the change yet. Diff below: Notice in particular:
denote.el | 24 +++++++++++++++++++++---
1 file changed, 21 insertions(+), 3 deletions(-)
diff --git a/denote.el b/denote.el
index fef2910..ee3999a 100644
--- a/denote.el
+++ b/denote.el
@@ -143,7 +143,14 @@ (defcustom denote-front-matter-date-format nil
If a string, use it as the argument of `format-time-string'.
Read the documentation of that function for valid format
-specifiers."
+specifiers.
+
+When `denote-file-type' specifies one of the Markdown flavors, we
+ignore this user option in order to enforce the RFC3339
+specification (markdown is typically employed in static site
+generators as source code for web pages). However, when
+`denote-front-matter-date-format' has a string value, this rule
+is suspended: we use whatever the user wants."
:type '(choice
(const :tag "Just the date like 2022-06-08" nil)
(const :tag "An inactive Org timestamp like [2022-06-08 Wed 06:19]" org-timestamp)
@@ -419,14 +426,25 @@ (defun denote--path (title keywords)
(denote--sluggify title)
(denote--file-extension))))
+;; Adapted from `org-hugo--org-date-time-to-rfc3339' in Kashual Modi's
+;; `ox-hugo' package: <https://github.com/kaushalmodi/ox-hugo>.
+(defun denote--date-rfc3339 ()
+ "Format date using the RFC3339 specification."
+ (replace-regexp-in-string
+ "\\([0-9]\\{2\\}\\)\\([0-9]\\{2\\}\\)\\'" "\\1:\\2"
+ (format-time-string "%FT%T%z")))
+
(defun denote--date ()
"Expand the date for a new note's front matter."
(let ((format denote-front-matter-date-format))
(cond
- ((eq format 'org-timestamp)
- (format-time-string "[%F %a %R]"))
((stringp format)
(format-time-string format))
+ ((or (eq denote-file-type 'markdown-toml)
+ (eq denote-file-type 'markdown-yaml))
+ (denote--date-rfc3339))
+ ((eq format 'org-timestamp)
+ (format-time-string "[%F %a %R]"))
(t (format-time-string "%F")))))
(defun denote--prepare-note (title keywords &optional path) |
Thanks ot Kaushal Modi for the feedback in issue 7 over at the GitHub mirror: <#7>.
I'll haven't got a chance to get to a computer to try it out, but I looked at the 254a6cd and it looks great! Thank you for all your efforts. minor: My name got misspelled in a comment in that commit. But you don't need to mention my name in the code. Just the link to ox-hugo repo is OK. Thanks for the credit 😀. |
Per its author's request: <#7 (comment)>.
Sorry about that! Updated it to only mention |
Thanks to Anthony Chavez for the feedback in issue 7 over at the GitHub mirror: <protesilaos/denote#7>.
If I create a note after setting:
denote-front-matter-date-format
toorg-timestamp
denote-file-type
tomarkdown-yaml
, I get this:
The date format is illegal in YAML. It will need to be converted to RFC3339 format.
Corrected date format:
date = 2022-06-10T11:25:38-04:00
I use this to convert Org date/time to RFC3339:
(plist-get info :hugo-date-format)
will retrieve this by default:"%Y-%m-%dT%T%z"
.(reference)
References
RFC3339 date/time examples from the standard
More
The same RFC3339 format date/time will work for TOML too: https://toml.io/en/v1.0.0#offset-date-time
The text was updated successfully, but these errors were encountered: