PROJECTS NOTES HOME

Convert denote links to org links for html export

So when making this status update I have faced a problem and decided to attempt to fix it right away.

I am using Denote in emacs to take notes, so today, when writing the mentioned status update post there was a need for me to list all the notes that were created over the past month. So I pressed C-c n I command in emacs (denote-add-links) and got a list with links to all of posts that were created this month. Great! In emacs, I can click on that link and be directed to the note. Great! But I know that if I try to export this .org file(denote note) to a .html file (needed for the website you are reading now) - I will get an error saying that it can not find a link to file.

"denote-add-links" as well as "denote-link" commands currently create links that look like such:

[[denote:20240102T100605][Reach django project from anywhere] ]

When the regular link made to the same file with built in "org-insert-link" gives a link that looks like this:

[[20240102T100605--reach-django-project-from-anywhere__django.html][reach-django-project-from-anywhere] ]

Denote way is not understandable for emacs html exporter, but file: link is understandable.

So when I have a list of denote links and I have to manually convert them to org links I do this:

I evaluate this piece of code in my scrach buffer:

(defun extract-link-text-and-hyphenate ()
  (interactive)
  (when (region-active-p)
    (let ((selected-text (buffer-substring (region-beginning) (region-end))))
      (if (string-match "\\[\\[.*?\\]\\[\\(.*?\\)\\]\\]" selected-text)
          (replace-region-contents (hyphenate-link-text (match-string 1 selected-text)))
        (message "No valid org-mode link found in the selected text")))))

(defun hyphenate-link-text (text)
  (replace-regexp-in-string " " "-" (downcase text)))

(defun replace-region-contents (new-text)
  (delete-region (region-beginning) (region-end))
  (insert new-text))

Basically what it does is:

What I then manually do create a macro with F3 (kmacro-start-macro-or-insert-counter):

  1. I mark the denote link, execute extract-link-text-and-hyphenate on it
  2. I then mark the whole title, now it is with dashes between words
  3. Then copy the whole title
  4. do org-insert-link
  5. file link
  6. paste the title with dashes
  7. it finds the link(since all of the denote notes of mine are in the same folder)

Close macro with F4(kmacro-end-or-call-macro ARG &optional NO-REPEAT)

Now press F4 on each denote link and it gets transformed to a regular org link that org html exporter can understand.

A lot of work, but it is what it is. If I knew elisp better, perhaps I could find a better workaround :)