Export org-roam backlinks with Gohugo

March 7, 2021 | emacs, orgroam, orgmode

tags Org-mode Emacs Org-roam Since Org-roam export backlinks on Hugo no longer works, I found a solution to handle backlinks in Hugo itself. The following Hugo partial template will add backlinks to a note if any. {{ $re := $.File.BaseFileName }} {{ $backlinks := slice }} {{ range .Site.AllPages }} {{ if and (findRE $re .RawContent) (not (eq $re .File.BaseFileName)) }} {{ $backlinks = $backlinks | append . }} {{ end }} {{ end }} <hr> {{ if gt (len $backlinks) 0 }} <div class="bl-section"> <h4>Links to this note</h4> <div class="backlinks"> <ul> {{ range $backlinks }} <li><a href="{{ . ...

Emacs - Search and replacing versioned controled files

September 26, 2020 | emacs

tags Emacs Programming I had to search and replace many files in a git repository, for some reason dired-do-find-regexp-and-replace, but I found using counsel-git-grep with wgre much easier. Here is on you do it: M-x counsel-git-grep Search for the string Press ivy-occur key on ivy's search prompt result, which is set to C-c C-o by default. This will open the search results in a new buffer On your new buffer, run wgrep-change-to-wgrep-mode (C-c C-p) and do your editing. ...

Using macros in Emacs

July 29, 2020 | emacs

tags Emacs Emacs macros allows us to record sequence of keyboard keystrokes, mouse actions, menu actions that is bound to an Emacs command. It allows us to record these actions and repeat them when needed. Creating a new macro # C-x ( starts recording a macro C-x ) stops recording a macro C-x e executes the macro C-u 37 C-x e executes the macro 37 times C-u 0 C-x e executes the macro an infinite number of times until EOF. ...

Ox-hugo export all roam to Hugo

June 4, 2020 | emacs, orgmode, hugo, orgroam, roam

tags Emacs Org-mode Org-roam Export all org-roam files to Hugo markdown (this might take some time) From: jethrokuan/dots (defun benmezger/org-roam-export-all () "Re-exports all Org-roam files to Hugo markdown." (interactive) (dolist (f (org-roam--list-all-files)) (with-current-buffer (find-file f) (when (s-contains? "SETUPFILE" (buffer-string)) (org-hugo-export-wim-to-md))))) Adding an empty #+SETUPFILE: forces benmezger/org-roam-export-all to export the file.

Org-roam export backlinks on Hugo

June 4, 2020 | orgmode, emacs

tags Org-mode Emacs Org-roam ❗️*Note:* This no longer applies (probably due to an upstream update). See the following note for another approach: Export org-roam backlinks with Gohugo Insert roam backlinks URL when exporting orgmode to HTML From: jethrokuan/dots (defun benmezger/org-roam-export-all () "Re-exports all Org-roam files to Hugo markdown." (interactive) (dolist (f (org-roam--list-all-files)) (with-current-buffer (find-file f) (when (s-contains? "SETUPFILE" (buffer-string)) (org-hugo-export-wim-to-md))))) (defun benmezger/org-roam--backlinks-list (file) (when (org-roam--org-roam-file-p file) (mapcar #'car (org-roam-db-query [:select :distinct [from] :from links :where (= to $s1) :and from :not :like $s2] file "%private%")))) (defun benmezger/org-export-preprocessor (_backend) (when-let ((links (benmezger/org-roam--backlinks-list (buffer-file-name)))) (insert "\n** Backlinks\n") (dolist (link links) (insert (format "- [[file:%s][%s]]\n" (file-relative-name link org-roam-directory) (org-roam--get-title-or-slug link)))))) (add-hook 'org-export-before-processing-hook #benmezger/org-export-preprocessor))

Org-roam Firefox bookmark

May 30, 2020 | emacs, orgmode, roam, firefox

tags Org-mode Emacs Org-roam Org-roam has roam-protocol, which we can call throughout the system just like Org-mode Firefox bookmarks. Org-roam protocol supports specifying the roam template to use. Template is the template key for a template in org-roam-capture-ref-templates. More documentation on the templating system can be found here. These templates should contain a #+ROAM_KEY: ${ref} in it. Roam-ref protocol # Find and creates from with a specific ROAM_KEY ...

Org-mode Firefox bookmarks

May 30, 2020 | emacs, orgmode, firefox

tags Org-mode Emacs Add the following scripts to call org-capture from Firefox Call capture template # The following calls capture template key n javascript: location.href = "org-protocol://capture?template=n" + "&url=" + encodeURIComponent(window.location.href) + "&title=" + encodeURIComponent(document.title) + "&body=" + encodeURIComponent(window.getSelection()); Without a capture template # If unspecified, the template key is set in the variable org-protocol-default-template-key. The following template placeholders are available: %:link The URL %:description The webpage title %:annotation Equivalent to [[%:link][%:description]] %i The selected text See: https:orgmode. ...