有没有人考虑“org这类远程包含”特性,把数据分散地存储在各种论坛、textboard、博客、甚至对任何评论提供外链的网站?
比如,用下面函数将 https://emacs-china.org/ 的帖子转为纯文本(这类无关紧要的格式转换函数随机随意地存储于某网站中,即使丢失,也可以快速恢复):
#+begin_src emacs-lisp
(lambda (url)
(let* ((dom (with-temp-buffer
(shell-command (concat "curl -s " url) (current-buffer))
(libxml-parse-html-region (point-min) (point-max)))))
(s-join "\n"
(-map #'dom-texts
(dom-non-text-children (dom-by-class dom "^post$"))))))
#+end_src
再增加一个类似#+include的扩展(这函数能否也随机存在某个论坛中?):
#+begin_src emacs-lisp
(defun x-include (url &optional extract-url src-blk-name)
(let* ((extract-url (or extract-url url))
;; url -> lisp function
(dom (with-temp-buffer
(shell-command
(concat "curl -s " extract-url) (current-buffer))
(libxml-parse-html-region (point-min) (point-max))))
(efunc (with-temp-buffer
(org-mode)
(insert (dom-texts dom "\n@@@\n"))
(let* ((src-blks (org-element-map
(org-element-parse-buffer)
`(src-block)
#'identity))
(src-blks (if src-blk-name
(--filter
(string= (org-element-property :name it)
src-blk-name)
src-blks)
src-blks)))
(ignore-errors
(read (org-element-property :value (car src-blks))))))))
;; url -> org text
(or (ignore-errors (funcall efunc url)) "")))
#+end_src
于是,这个帖子本身的内容在本地系统中成为:
#+begin_src emacs-lisp
(x-include "https://emacs-china.org/t/org-include-url/29242")
#+end_src
再抽象些:
从 src_org{(org-babel-call "~/org/a.org:format-convert" content-url)}
到 src_org{(org-babel-call "url:format-convert" content-url)}"
。
现在,format-convert可以随便存在某朵“云”上了。(:
25/3/25,2339注:不知道归档在web.archive.org的网站数据是否依赖原网站的状态? `用 elisp 手搓 gptel tools - Emacs-general - Emacs China
#+name: this-is-a-test-func
#+begin_src emacs-lisp :var a="world"
(concat "hello " a "!")
#+end_src