diff options
author | Spencer Williams <spnw@plexwave.org> | 2025-07-12 17:35:04 -0400 |
---|---|---|
committer | Spencer Williams <spnw@plexwave.org> | 2025-07-13 13:58:17 -0400 |
commit | 33528bcc8ddace06674f84ef5c6962069c2d3971 (patch) | |
tree | fd638d6fb24e739d1551fc37d5fd951203399b15 /lisp/seam-export.el | |
parent | 3793bef659479acb1179ea1b21ba4e960bbd17ce (diff) |
Add new props and vars for file mod/create time
Diffstat (limited to 'lisp/seam-export.el')
-rw-r--r-- | lisp/seam-export.el | 117 |
1 files changed, 78 insertions, 39 deletions
diff --git a/lisp/seam-export.el b/lisp/seam-export.el index 49cc46a..e1b646c 100644 --- a/lisp/seam-export.el +++ b/lisp/seam-export.el @@ -176,6 +176,16 @@ interpolate it as-is. A list (<ul>) of notes that link to the given note. + `created' + + The human-readable date that the note was created. See + `seam-export-time-format'. + + `created-dt' + + The machine-readable date that the note was created. See + `seam-export-time-format-dt'. + `modified' The human-readable date that the note was last modified. See @@ -183,8 +193,8 @@ interpolate it as-is. `modified-dt' - The machine-readable date that the note was last modified. See - `seam-export-time-format-dt'.") + The machine-readable date that the note was last modified. + See `seam-export-time-format-dt'.") (defcustom seam-export-template-string seam-export-default-template-string "The HTML template string to be used by the exporter. The template @@ -289,6 +299,14 @@ notes)." (seam-export--export-to-text-string (insert s)))) +(defun seam-export--get-props (file props) + (with-temp-buffer + (insert-file-contents file) + (when (re-search-forward "^\\* " nil t) + (org-mode) + (cl-loop for prop in props + collect (org-element-property prop (org-element-at-point)))))) + (defun seam-export--generate-backlinks (file) (seam-export--export-to-html-string (let ((files (cl-sort @@ -303,43 +321,64 @@ notes)." (defun seam-export--note-to-html (note-file html-directory) (seam-ensure-directory-exists html-directory) - (let ((html-file (file-name-concat html-directory - (concat (seam-get-slug-from-file-name note-file) ".html"))) - (modified (file-attribute-modification-time - (file-attributes note-file)))) - (with-temp-buffer - (insert - (mustache-render - seam-export--template - (append - seam-export--template-values - seam-export-template-values - `(("title" . - ,(seam-export--org-to-text - (seam-get-title-from-file note-file))) - ("raw-title" . - ,(seam-export--org-to-html - (seam-get-title-from-file note-file))) - ("modified" . - ,(format-time-string - seam-export--time-format - modified - seam-export--time-zone)) - ("modified-dt" . - ,(format-time-string - seam-export--time-format-dt - modified - seam-export--time-zone)) - ("contents" . - ,(seam-export--export-to-html-string - (insert-file-contents note-file) - (re-search-forward "^\\* ") - (org-mode) ;Needed for `org-set-property'. - (org-set-property "seam-title-p" "t"))) - ("backlinks" . - ,(seam-export--generate-backlinks note-file))) - nil))) - (write-file html-file)))) + (cl-destructuring-bind (created-prop modified-prop) + (seam-export--get-props note-file '(:SEAM_CREATED :SEAM_MODIFIED)) + (let* ((html-file (file-name-concat html-directory + (concat (seam-get-slug-from-file-name note-file) ".html"))) + (modified + (or (ignore-errors (parse-iso8601-time-string modified-prop)) + (file-attribute-modification-time + (file-attributes note-file)))) + (created + (or (ignore-errors (parse-iso8601-time-string created-prop)) + modified))) + (with-temp-buffer + (insert + (mustache-render + seam-export--template + (append + seam-export--template-values + seam-export-template-values + `(("title" . + ,(seam-export--org-to-text + (seam-get-title-from-file note-file))) + ("raw-title" . + ,(seam-export--org-to-html + (seam-get-title-from-file note-file))) + ("created" . + ,(format-time-string + seam-export--time-format + created + seam-export--time-zone)) + ("created-dt" . + ,(format-time-string + seam-export--time-format-dt + created + seam-export--time-zone)) + ("modified" . + ,(format-time-string + seam-export--time-format + modified + seam-export--time-zone)) + ("modified-dt" . + ,(format-time-string + seam-export--time-format-dt + modified + seam-export--time-zone)) + ("modified?" . + ,(lambda (template context) + (unless (equal created modified) + (mustache-render template context)))) + ("contents" . + ,(seam-export--export-to-html-string + (insert-file-contents note-file) + (re-search-forward "^\\* ") + (org-mode) ;Needed for `org-set-property'. + (org-set-property "seam-title-p" "t"))) + ("backlinks" . + ,(seam-export--generate-backlinks note-file))) + nil))) + (write-file html-file))))) (defun seam-export--file-string (file) (with-temp-buffer |