From f0d8f8a38cc9334eb2783e8aa583bb28b4fae3e4 Mon Sep 17 00:00:00 2001 From: Correl Roush Date: Sun, 25 Aug 2024 19:20:54 -0400 Subject: [PATCH] Build and publish to home directory on Reason --- .forgejo/workflows/example.yaml | 22 ++++++++- org-roam-export.el | 83 +++++++++++++++++++++++++++++++++ publish.el | 56 ++++++++++++++++++++++ 3 files changed, 159 insertions(+), 2 deletions(-) create mode 100644 org-roam-export.el create mode 100644 publish.el diff --git a/.forgejo/workflows/example.yaml b/.forgejo/workflows/example.yaml index 8809e4f..83ae371 100644 --- a/.forgejo/workflows/example.yaml +++ b/.forgejo/workflows/example.yaml @@ -3,7 +3,25 @@ on: branches: - main jobs: - test: + build: runs-on: docker + container: + image: silex/emacs:29.1-alpine-ci steps: - - run: echo "Oh hi there" + - uses: actions/checkout@v4 + - run: emacs --batch --no-init-file --load publish.el --funcall org-publish-all + - run: apk add rsync + - run: | + mkdir -p ~/.ssh + cat < ~/.ssh/config + Host reason + HostName reason.sailmaker.fenix.lgbt + User correlr + IdentityFile ~/.ssh/id_rsa + StrictHostKeyChecking no + EOF + cat < ~/.ssh/id_rsa + $SSH_PRIVATE_KEY + EOF + chmod 600 ~/.ssh/id_rsa + - run: rsync -avz --delete ./public/ reason:Public/roam/ diff --git a/org-roam-export.el b/org-roam-export.el new file mode 100644 index 0000000..d7ce9cd --- /dev/null +++ b/org-roam-export.el @@ -0,0 +1,83 @@ +;;; org-roam-export.el --- Description -*- lexical-binding: t; -*- +;; +;; Copyright (C) 2022 Correl Roush +;; +;; Author: Correl Roush +;; Maintainer: Correl Roush +;; Created: June 10, 2022 +;; Modified: June 10, 2022 +;; Version: 0.0.1 +;; Keywords: abbrev bib c calendar comm convenience data docs emulations extensions faces files frames games hardware help hypermedia i18n internal languages lisp local maint mail matching mouse multimedia news outlines processes terminals tex tools unix vc wp +;; Homepage: https://github.com/correlr/org-roam-export +;; Package-Requires: ((emacs "25.1") (org-roam "2.2.1")) +;; +;; This file is not part of GNU Emacs. +;; +;;; Commentary: +;; +;; Description +;; +;;; Code: + +(require 'org-roam) + +(defun org-roam-export-backlink-title (backlink) + "Get exportable title of BACKLINK." + (mapconcat #'identity + (append + (list (org-roam-node-title (org-roam-backlink-source-node backlink))) + (plist-get (org-roam-backlink-properties backlink) :outline)) + " > ")) + +(defun org-roam-export-backlink-link (backlink) + "Get Org link to BACKLINK." + (concat "id:" (org-roam-node-id (org-roam-backlink-source-node backlink)))) + +(defun org-roam-export--excerpt (&optional buffer element) + "Extract an excerpt from ELEMENT in BUFFER." + (with-current-buffer (or buffer (current-buffer)) + (let ((element (or element (org-element-at-point)))) + (if (eq 'headline (org-element-type element)) + (progn (org-mark-subtree) + (buffer-substring (point) (mark))) + (if-let ((begin (org-element-property :contents-begin element)) + (end (org-element-property :contents-end element))) + (buffer-substring begin end) + ""))))) + +(defun org-roam-export-backlink-excerpt (backlink) + "Get the Org element containing the link from BACKLINK as an excerpt." + (with-temp-buffer + (insert-file-contents (org-roam-node-file (org-roam-backlink-source-node backlink))) + (goto-char (org-roam-backlink-point backlink)) + (org-roam-export--excerpt))) + +(defun org-roam-export--format-backlink (link title excerpt) + "Format a backlink with TITLE and EXCERPT for inclusion in an Org document." + (with-temp-buffer + (org-mode) + (insert "** " (org-make-link-string link title) "\n\n") + (if (string-match-p "^\*+ " excerpt) (org-paste-subtree 3 excerpt) + (insert excerpt)) + (buffer-string))) + +(defun org-roam-export-format-backlink (backlink) + "Format a BACKLINK for inclusion in an Org document." + (org-roam-export--format-backlink + (org-roam-export-backlink-link backlink) + (org-roam-export-backlink-title backlink) + (org-roam-export-backlink-excerpt backlink))) + +(defun org-roam-export-preprocessor (backend) + "Append org-roam backlinks with content when applicable before +passing to the org export BACKEND." + (when-let ((node (org-roam-node-at-point))) + (let ((backlinks (org-roam-backlinks-get node))) + (when backlinks + (save-excursion + (goto-char (point-max)) + (insert (concat "\n* Backlinks\n" + (string-join (mapcar #'org-roam-export-format-backlink backlinks))))))))) + +(provide 'org-roam-export) +;;; org-roam-export.el ends here diff --git a/publish.el b/publish.el new file mode 100644 index 0000000..14877e5 --- /dev/null +++ b/publish.el @@ -0,0 +1,56 @@ +(require 'package) +(package-initialize) +(add-to-list 'package-archives '("melpa" . "https://melpa.org/packages/") t) +(add-to-list 'package-archives '("gnu" . "https://elpa.gnu.org/packages/") t) +(package-refresh-contents) +(package-install 'org) +(package-install 'htmlize) +(package-install 'org-roam) + +(require 'org) +(require 'ox-publish) + +(load-file "org-roam-export.el") + +(setq org-confirm-babel-evaluate nil) + +(defun password-store-get (&rest args) + "Dummy implementation of password-store-get." + nil) + + +(add-hook 'org-export-before-processing-hook 'org-roam-export-preprocessor) + +(setq my/org-base-url (or (getenv "BASE_URL") "/")) + +(setq org-publish-project-alist + `(("roam-html" + :base-directory "." + :base-extension "org" + :publishing-directory "./public" + :recursive t + :html-link-home ,my/org-base-url + :html-doctype "html5" + :html-html5-fancy t + :with-toc nil + :with-sub-superscript nil + :section-numbers nil + :auto-sitemap t + :sitemap-filename "sitemap.org" + :sitemap-title "Document Index" + :sitemap-sort-folders last + :publishing-function org-html-publish-to-html + :html-head "") + + ("roam-assets" + :base-directory "." + :exclude "public/" + :base-extension "html\\|css\\|gif\\|jpe?g\\|js\\|json\\|png\\|svg\\|pdf" + :publishing-directory "./public" + :publishing-function org-publish-attachment + :recursive t) + ("roam" :components ("roam-html" "roam-assets")))) + +(setq org-roam-directory (expand-file-name ".")) +(org-roam-db-sync) +(org-roam-update-org-id-locations)