2026-09-26
Daily Journal Migration and other changes
The following migration script provided by claude was used to migrated all journal entries to the new capture template. With this last outstanding issue in the site migration is completed. This also addressed a known technical debt in the older design.
(defun my/migrate-daily-journal-entry-at-point (dest-dir) "Migrate the day-entry subtree at point into its own file under DEST-DIR. Point must be on a level-3 '*** YYYY-MM-DD ...' heading. Returns the path written, or nil if a file with that name already exists (never overwrites)." (let* ((props (org-entry-properties)) (date-str (or (cdr (assoc "EXPORT_FILE_NAME" props)) (car (split-string (org-get-heading t t t t))))) (existing-id (cdr (assoc "ID" props))) (id (or existing-id (org-id-new))) (out-path (expand-file-name (concat date-str ".journal.org") dest-dir))) (if (file-exists-p out-path) (progn (message "SKIPPED (already exists): %s" out-path) nil) (let* ((subtree-beg (progn (org-back-to-heading t) (point))) (content-beg (save-excursion (goto-char subtree-beg) (forward-line 1) (when (looking-at-p "^[ \t]*:PROPERTIES:") (re-search-forward "^[ \t]*:END:[ \t]*$" nil t) (forward-line 1)) (point))) (subtree-end (save-excursion (org-end-of-subtree t t) (point))) (body (buffer-substring-no-properties content-beg subtree-end))) ;; Demote every real heading in the extracted body by exactly 3 ;; levels (**** -> *), using org-promote (org-aware: correctly ;; ignores comma-escaped example headings inside #+begin_src ;; blocks) rather than a naive text regex. (with-temp-buffer (org-mode) (insert body) (dotimes (_ 3) (goto-char (point-min)) (while (re-search-forward "^\\*+ " nil t) (goto-char (line-beginning-position)) (ignore-errors (org-promote)) (forward-line 1))) (setq body (buffer-substring-no-properties (point-min) (point-max)))) (with-temp-file out-path (insert (format ":PROPERTIES:\n:ID: %s\n:END:\n" id)) (insert (format "#+title: %s\n" date-str)) (insert (format "#+date: %sT00:00:00+05:30\n" date-str)) (insert "#+filetags: :journal:\n\n") (insert (string-trim body)) (insert "\n")) out-path)))) (defun my/migrate-daily-journal (source-file dest-dir) "Split SOURCE-FILE's org-roam-dailies datetree into one file per day under DEST-DIR. Never modifies or deletes SOURCE-FILE. Returns the list of files written." (unless (file-directory-p dest-dir) (make-directory dest-dir t)) (let (results) (with-current-buffer (find-file-noselect source-file) (org-with-wide-buffer (goto-char (point-min)) (while (re-search-forward "^\\*\\*\\* [0-9]\\{4\\}-[0-9]\\{2\\}-[0-9]\\{2\\}" nil t) (goto-char (line-beginning-position)) (let ((written (my/migrate-daily-journal-entry-at-point dest-dir))) (when written (push written results))) (org-end-of-subtree t t)))) (message "Migrated %d entries to %s" (length results) dest-dir) (nreverse results))) (my/migrate-daily-journal "/data/myhome/prabu/org/Resources/daily_journal.org" "/data/myhome/prabu/org/Resources/temp/")