Procházet zdrojové kódy

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.
David Whittington před 4 roky
rodič
revize
46ac685474

+ 17 - 0
src/main/frontend/components/block.cljs

@@ -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

+ 6 - 0
src/main/frontend/state.cljs

@@ -236,6 +236,12 @@
   ([repo-url]
    (get-in @state [:config repo-url])))
 
+(def default-arweave-gateway "https://arweave.net")
+
+(defn get-arweave-gateway
+  []
+  (:arweave/gateway (get-config) default-arweave-gateway))
+
 (defonce built-in-macros
   {"img" "[:img.$4 {:src \"$1\" :style {:width $2 :height $3}}]"})