[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/denote 254a6cd0f3 112/355: Update date function; enforc
From: |
ELPA Syncer |
Subject: |
[elpa] externals/denote 254a6cd0f3 112/355: Update date function; enforce RFC3339 when needed |
Date: |
Sun, 26 Jun 2022 23:58:10 -0400 (EDT) |
branch: externals/denote
commit 254a6cd0f33dfc997be69bccb2a11bca80142ce9
Author: Protesilaos Stavrou <info@protesilaos.com>
Commit: Protesilaos Stavrou <info@protesilaos.com>
Update date function; enforce RFC3339 when needed
Thanks ot Kaushal Modi for the feedback in issue 7 over at the GitHub
mirror: <https://github.com/protesilaos/denote/issues/7>.
---
README.org | 10 +++++++++-
denote.el | 36 +++++++++++++++++++++++++++++++-----
2 files changed, 40 insertions(+), 6 deletions(-)
diff --git a/README.org b/README.org
index 7e497b6320..b6cd5f0137 100644
--- a/README.org
+++ b/README.org
@@ -292,13 +292,21 @@ The format of the date in the front matter is controlled
by the user
option ~denote-front-matter-date-format~:
- When the value is nil (the default), the date uses a plain
- =YEAR-MONTH-DAY= notation, like =2022-06-08=.
+ =YEAR-MONTH-DAY= notation, like =2022-06-08= (the ISO 8601 standard).
+
- When the value is the =org-timestamp= symbol, the date is recorded as
an inactive Org timestamp, such as =[2022-06-08 Wed 06:19]=.
+
- An arbitrary string value is interpreted as the argument for the
function ~format-time-string~. This gives the user maximum control
over how time is represented in the front matter.
+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.
+
* Linking notes
:PROPERTIES:
:CUSTOM_ID: h:fc913d54-26c8-4c41-be86-999839e8ad31
diff --git a/denote.el b/denote.el
index fef291060e..2616dfef32 100644
--- a/denote.el
+++ b/denote.el
@@ -136,14 +136,21 @@ Any other non-nil value is the same as the default."
"Date format in the front matter (file header) of new notes.
If the value is nil, use a plain date in YEAR-MONTH-DAY notation,
-like 2022-06-08.
+like 2022-06-08 (the ISO 8601 standard).
If the value is the `org-timestamp' symbol, format the date as an
inactive Org timestamp such as: [2022-06-08 Wed 06:19].
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,15 +426,34 @@ Format current time, else use optional ID."
(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-org-timestamp ()
+ "Format date using the Org inactive timestamp notation."
+ (format-time-string "[%F %a %R]"))
+
+(defun denote--date-iso-8601 ()
+ "Format date according to ISO 8601 standard."
+ (format-time-string "%F"))
+
(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))
- (t (format-time-string "%F")))))
+ ((or (eq denote-file-type 'markdown-toml)
+ (eq denote-file-type 'markdown-yaml))
+ (denote--date-rfc3339))
+ ((eq format 'org-timestamp)
+ (denote--date-org-timestamp))
+ (t (denote--date-iso-8601)))))
(defun denote--prepare-note (title keywords &optional path)
"Use TITLE and KEYWORDS to prepare new note file.
- [elpa] externals/denote 662a71d051 330/355: Remove development note about links, (continued)
- [elpa] externals/denote 662a71d051 330/355: Remove development note about links, ELPA Syncer, 2022/06/27
- [elpa] externals/denote 3b2db33812 322/355: Remove development note about backlinks, ELPA Syncer, 2022/06/27
- [elpa] externals/denote ed75652925 341/355: Remove the ref card from the manual, ELPA Syncer, 2022/06/27
- [elpa] externals/denote 8394280f95 317/355: Refine regexp for front-matter date extraction, ELPA Syncer, 2022/06/27
- [elpa] externals/denote b25235e93e 331/355: Add header links to the mailing list, ELPA Syncer, 2022/06/27
- [elpa] externals/denote 26069e8612 029/355: Add todo about alternative to seq-remove, ELPA Syncer, 2022/06/27
- [elpa] externals/denote 418a21dccb 052/355: Tweak file and defgroup descriptions, ELPA Syncer, 2022/06/27
- [elpa] externals/denote 20a915672e 056/355: Remove interactive-only from 'denote', ELPA Syncer, 2022/06/27
- [elpa] externals/denote 0519be74a9 121/355: Add PROOF-OF-CONCEPT denote-link-backlinks, ELPA Syncer, 2022/06/27
- [elpa] externals/denote a107fbf5d7 120/355: Make minor tweaks in the manual, ELPA Syncer, 2022/06/27
- [elpa] externals/denote 254a6cd0f3 112/355: Update date function; enforce RFC3339 when needed,
ELPA Syncer <=
- [elpa] externals/denote f1f9f757ef 109/355: Include markdown-toml sample in the manual, ELPA Syncer, 2022/06/27
- [elpa] externals/denote 24371b4c86 129/355: fix: Update the identifier regexp to recognize TOML identifier too, ELPA Syncer, 2022/06/27
- [elpa] externals/denote 0cb5c9f06e 122/355: Simplify attribution comment to ox-hugo, ELPA Syncer, 2022/06/27
- [elpa] externals/denote 79fbe2493b 135/355: Merge pull request #11 from kaushalmodi/update-identifier-regexp, ELPA Syncer, 2022/06/27
- [elpa] externals/denote 808a2c29f9 140/355: Acknowledge Peter Povinec for file-naming refinements, ELPA Syncer, 2022/06/27
- [elpa] externals/denote 083b3bfc89 144/355: Use better example for file renaming, ELPA Syncer, 2022/06/27
- [elpa] externals/denote 561553db8e 132/355: fix: Use the correct match subgroup in `denote-link--find-value`, ELPA Syncer, 2022/06/27
- [elpa] externals/denote e1c18f5f57 136/355: Remove potentially bad advice from the manual, ELPA Syncer, 2022/06/27
- [elpa] externals/denote 7b719e6274 152/355: Add user option to disable multi-word keywords, ELPA Syncer, 2022/06/27
- [elpa] externals/denote 25fa79e8d9 146/355: Refine denote-retrieve internals, ELPA Syncer, 2022/06/27