#+begin_src elisp %org-level-0%

;;; mirwiki.el --- generate a website just as it appears in Emacs. also vimwiki flow features -*- lexical-binding: t; -*- %org-level-0% %org-level-0%

%org-level-0%

;; Copyright (C) 2024 Miranda Marquez %org-level-0%

%org-level-0%

;; Author: Miranda Marquez <mir@knockout> %org-level-0%

;; Keywords: outlines, convenience %org-level-0%

%org-level-0%

;; This program is free software; you can redistribute it and/or modify %org-level-0% %org-level-0%

;; it under the terms of the GNU General Public License as published by %org-level-0% %org-level-0%

;; the Free Software Foundation, either version 3 of the License, or %org-level-0%

;; (at your option) any later version. %org-level-0%

%org-level-0%

;; This program is distributed in the hope that it will be useful, %org-level-0%

;; but WITHOUT ANY WARRANTY; without even the implied warranty of %org-level-0% %org-level-0%

;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the %org-level-0% %org-level-0%

;; GNU General Public License for more details. %org-level-0%

%org-level-0%

;; You should have received a copy of the GNU General Public License %org-level-0% %org-level-0%

;; along with this program. If not, see <https://www.gnu.org/licenses/>. %org-level-0% %org-level-0%

%org-level-0%

;;; Commentary: %org-level-0%

%org-level-0%

;; this is like the 3rd rewrite %org-level-0%

%org-level-0%

;;; Code: %org-level-0%

%org-level-0%

(require 'dash) %org-level-0%

%org-level-0%

(defvar mirwiki-source-dir "/unicron_shared/webbed-site/staging/" %org-level-0% %org-level-0% %org-level-0%

"working dir with orgs and such") %org-level-0% %org-level-0% %org-indent-0%

(defvar mirwiki-dest-dir "/unicron_shared/webbed-site/public/" %org-level-0% %org-level-0% %org-level-0%

"dir to export to") %org-level-0%

%org-level-0%

(defun mirwiki-equivalent-file (source &optional absolute html) %org-level-0% %org-level-0% %org-level-0%

"You know of SOURCE, this returneth its equivalent DEST. %org-level-0% %org-level-0% %org-level-0%

%org-level-0%

If ABSOLUTE is non-nil, give full filepath. otherwise relative to dest dir. %org-level-0% %org-level-0% %org-level-0%

%org-level-0%

If HTML is non-nil, end with index.html, otherwise trail directory." %org-level-0% %org-level-0% %org-level-0%

(--> source %org-level-0%

(file-relative-name it mirwiki-source-dir) %org-level-0% %org-level-0% %org-level-0%

(expand-file-name it mirwiki-dest-dir) ; raw equivalent %org-level-0% %org-level-0%

(string-replace ".org" ".html" it) ; equiv html ;TODO rx? didn't seem to work %org-level-0% %org-level-0%

(if html %org-level-0%

it %org-level-0%

(string-trim-right it "index.html")) %org-level-0% %org-level-0% %org-indent-0%

(if absolute %org-level-0%

it %org-level-0%

(f-relative it mirwiki-dest-dir)) %org-level-0% %org-level-0% %org-indent-0%

)) %org-level-0%

;; (mirwiki-equivalent-file "/unicron_shared/webbed-site/staging/index.org[[/../../../architecture/site/mirwiki.el/no link at point][nil]]") %org-level-0% %org-level-0% %org-level-0%

%org-level-0%

(defun mirwiki-replace-link (link) %org-level-0% %org-level-0% %org-indent-0%

"Replace the target of LINK with its export equivalent. text transformer." %org-level-0% %org-level-0% %org-level-0% %org-level-0%

;; TODO can we use C-c C-l for this? %org-level-0%

(let* ((old-link-components %org-level-0%

(--map (string-trim it (rx (+ "[")) (rx (+ "]"))) %org-level-0% %org-level-0% %org-level-0%

(split-string link "]\\[" t))) %org-level-0% %org-level-0% %org-indent-0%

(new-link-target %org-level-0%

(mirwiki-equivalent-file (car old-link-components)))) %org-level-0% %org-level-0% %org-level-0% %org-level-0%

(format "[[/%s][%s]]" new-link-target (cadr old-link-components))) %org-level-0% %org-level-0% %org-level-0% %org-level-0%

) %org-level-0%

;; (mirwiki-replace-link "[[/architecture/site/mirwiki.el/][index]]") %org-level-0%

%org-level-0%

(defun mir/org-link-at-point () %org-level-0% %org-level-0%

"this does in fact return what you think it does." %org-level-0% %org-level-0%

(let ((bounds %org-level-0%

;; from source of `org-insert-link' %org-level-0%

(org-in-regexp org-link-bracket-re 1))) %org-level-0% %org-level-0%

(if bounds %org-level-0%

(buffer-substring-no-properties (car bounds) (cdr bounds)) %org-level-0% %org-level-0% %org-level-0%

(error "no link at point")))) %org-level-0% %org-level-0% %org-indent-0%

(defun mir/kill-org-link-pt () %org-level-0% %org-level-0%

(let ((bounds %org-level-0%

(org-in-regexp org-link-bracket-re 1))) %org-level-0% %org-level-0%

(if bounds %org-level-0%

(kill-region (car bounds) (cdr bounds)) %org-level-0% %org-level-0% %org-indent-0% (error "no link at point")))) %org-level-0% %org-level-0% %org-indent-0% (defun mirwiki-replace-link-at-point () %org-level-0% %org-level-0% %org-indent-0%

(interactive) %org-level-0%

(save-excursion %org-level-0%

(let* ((bounds (org-in-regexp org-link-bracket-re 1)) %org-level-0% %org-level-0% %org-level-0%

(new-link-text (mirwiki-replace-link (mir/org-link-at-point)))) %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0%

(mir/kill-org-link-pt) %org-level-0%

(insert new-link-text)))) %org-level-0% %org-level-0%

(defun mirwiki-replace-all-links-in-buffer () %org-level-0% %org-level-0% %org-indent-0%

"Repeatedly run `mirwiki-replace-link-at-point' for every index.org[[/../../../architecture/site/mirwiki.el/no link at point][nil]]." %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0%

(interactive) %org-level-0%

(goto-char (point-min)) %org-level-0%

(while (re-search-forward "index.org[[/../../../architecture/site/mirwiki.el/no link at point][nil]]" nil 'noerr) %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0%

(mirwiki-replace-link-at-point))) %org-level-0% %org-level-0% %org-indent-0%

%org-level-0%

(defvar mir/custom-css) %org-level-0%

(setq mir/custom-css " %org-level-0%

* { %org-level-0%

text-wrap: wrap; %org-level-0%

font-size: 20pt; %org-level-0%

} %org-level-0%

body { %org-level-0%

margin: auto 5%; %org-level-0%

} %org-level-0%

") %org-level-0%

%org-level-0%

(defun mir/customize-css () %org-level-0%

"Add `mir/custom-css' to its proper place in the html." %org-level-0% %org-level-0% %org-level-0%

(goto-char (point-min)) %org-level-0%

(re-search-forward "<style type=\"text/css\">\n <!--") %org-level-0% %org-level-0% %org-level-0% %org-level-0%

(insert mir/custom-css)) %org-level-0%

(defun mirwiki-export-file (org) %org-level-0% %org-level-0% %org-indent-0%

"Run `mirwiki-replace-all-links-in-buffer' on ORG, and htmlize it. %org-level-0% %org-level-0% %org-level-0%

%org-level-0%

Result is written to the `mirwiki-equivalent-file'." %org-level-0% %org-level-0% %org-level-0%

;; debug %org-level-0%

;; (message (propertize (format "Exporting %s" org) %org-level-0% %org-indent-0% ;; :face '(:foreground "green"))) %org-level-0% %org-indent-0%

(save-window-excursion %org-level-0%

(with-current-buffer (find-file org) %org-level-0% %org-level-0% %org-indent-0%

(let ((title (or %org-level-0%

(org-get-title) %org-level-0% %org-level-0% %org-indent-0% (format "mir: %s" (car %org-level-0% %org-level-0% %org-indent-0%

(last %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0% %org-level-0%

(remove ""

(split-string

(file-name-directory org) %org-indent-0% "/")))))))) %org-indent-0%

(save-buffer)

(evil-with-single-undo

(save-excursion

(mirwiki-replace-all-links-in-buffer)

(with-current-buffer (htmlize-buffer)

(mir/customize-css)

(mir/fix-page-title title)

(write-file (mirwiki-equivalent-file org 'absolute 'html)) %org-indent-0% (kill-buffer)) %org-indent-0% )) %org-indent-0%

(ignore-errors

(evil-undo-pop))) %org-indent-0% ))) %org-indent-0%

;; (car (last (remove "" (split-string (file-name-directory (expand-file-name "index.org[[/../../../architecture/site/mirwiki.el/no link at point][nil]]" mirwiki-source-dir)) "/"))))

(defun mir/fix-page-title (title)

"Replace the tab/page title with the org file's TITLE."

(goto-char (point-min))

(re-search-forward "<title>index.org[[/../../../architecture/site/mirwiki.el/no link at point][nil]]</title>")

(delete-line)

(insert (format " <title>%s</title>\n" title))

) %org-indent-0%

;; (mir/fix-page-title "PlaceHolderDesu")

;; (mirwiki-export-file "/unicron_shared/webbed-site/staging/hyperbole/checked/index.org[[/../../../architecture/site/mirwiki.el/no link at point][nil]]")

(defun all-orgs-mds-in-dir (dir)

"Return a list of every markdown and org file in DIR."

(let ((default-directory dir))

(--remove

(or

(f-directory-p it)

(not (or

(string= (f-ext it) "md")

(string= (f-ext it) "org")

)) %org-indent-0% ) %org-indent-0% (f-entries dir nil t)))) %org-indent-0%

;; (all-orgs-mds-in-dir mirwiki-source-dir)

(defun mirwiki-export-all ()

"Export all files in `mirwiki-source-dir' to `mirwiki-dest-dir'." %org-indent-0%

(interactive)

(--map (mirwiki-export-file it)

(all-orgs-mds-in-dir mirwiki-source-dir))) %org-indent-0%

(provide 'mirwiki)

;;; mirwiki.el ends here

#+end_src