HomeAboutCodePastes
(defun d/paste-region-or-buffer ()
  (interactive)
  ;; TODO: page title?
  (let ((str (if (region-active-p)
                 (buffer-substring-no-properties (region-beginning) (region-end))
               (buffer-substring-no-properties (point-min) (point-max))))
        (mode major-mode)
        (basename (format-time-string "%Y-%m-%dT%H-%M-%S"))
        (remote-path "/sshx:dieggsy@firefly:/srv/http/dieggsy.com/paste/"))
    (with-temp-buffer
      (let ((buffer-file-name "/tmp/paste.dieggsy.com"))
        (insert "#+OPTIONS: timestamp:nil num:nil toc:nil\n")
        (insert (format "#+EXPORT_FILE_NAME: %shtml/%s.html\n" remote-path basename))
        (insert "#+HTML_HEAD: <link rel=\"stylesheet\" type=\"text/css\" href=\"https://dieggsy.com/css/org.css\"/>\n")
        (insert "#+HTML_HEAD: <link rel=\"stylesheet\" type=\"text/css\" href=\"https://dieggsy.com/css/paste.css\"/>\n")
        (insert (format "#+begin_src %s\n" (string-remove-suffix "-mode" (symbol-name mode))))
        (insert str)
        (insert (format "%s#+end_src\n"
                        (if (string-suffix-p "\n" str)
                            ""
                          "\n")))
        (insert (format "[[./%s/raw][raw]]" basename))
        (org-mode)
        (setq-local org-html-preamble-format d/org-preamble-site-header)
        (org-html-export-to-html)
        (org-babel-tangle nil (format "%sraw/%s.txt" remote-path basename))))
    (kill-new (format "https://paste.dieggsy.com/%s" basename))))

plain