feat: support Arweave URLs for links and images

Adds ar://<tx> URL support for both links and images. The Arweave
gateway used can be configured with the :arweave/gateway config key. It
defaults to "https://arweave.net" if not configured.
This commit is contained in:
David Whittington
2021-11-19 12:07:27 -06:00
committed by Tienson Qin
parent 40b315de6b
commit 46ac685474
2 changed files with 23 additions and 0 deletions

View File

@@ -262,6 +262,10 @@
(when @src
(resizable-image config title @src metadata full_text true))))
(defn ar-url->http-url
[href]
(string/replace href #"^ar://" (str (state/get-arweave-gateway) "/")))
;; TODO: safe encoding asciis
;; TODO: image link to another link
(defn image-link [config url href label metadata full_text]
@@ -280,6 +284,9 @@
(util/starts-with? href "http")
href
(util/starts-with? href "ar")
(ar-url->http-url href)
config/publishing?
(subs href 1)
@@ -991,6 +998,16 @@
(state/set-state! :pdf/current current)))}
(get-label-text label)]
(= protocol "ar")
(->elem
:a.external-link
(cond->
{:href (ar-url->http-url href)
:target "_blank"}
title
(assoc :title title))
(map-inline config label))
:else
(->elem
:a.external-link