Weihua 4 лет назад
Родитель
Сommit
ec30d2be2c
2 измененных файлов с 38 добавлено и 18 удалено
  1. 14 1
      src/main/frontend/components/block.cljs
  2. 24 17
      src/main/frontend/extensions/pdf/assets.cljs

+ 14 - 1
src/main/frontend/components/block.cljs

@@ -937,9 +937,22 @@
                      (map-inline config label))))))
 
             ;; image
-            (show-link? config metadata href full_text)
+            (and (show-link? config metadata href full_text)
+                 (not (contains? #{"pdf"} (util/get-file-ext href))))
             (image-link config url href label metadata full_text)
 
+            ;; pdf link
+            (and
+             (util/electron?)
+             (= (util/get-file-ext href) "pdf")
+             (show-link? config metadata href full_text))
+            [:a.asset-ref.is-pdf
+             {:href "javascript:void(0);"
+              :on-mouse-down (fn [e]
+                               (when-let [current (pdf-assets/inflate-asset href)]
+                                 (state/set-state! :pdf/current current)))}
+             (get-label-text label)]
+
             (and
              (util/electron?)
              (= protocol "zotero")

+ 24 - 17
src/main/frontend/extensions/pdf/assets.cljs

@@ -24,23 +24,30 @@
 
 (defn inflate-asset
   [full-path]
-  (let [filename (util/node-path.basename full-path)
-        url (cond
-              (util/absolute-path? full-path)
-              (str "file://" full-path)
-
-              (string/starts-with? full-path "file:/")
-              full-path
-
-              :else
-              (util/node-path.join
-                "file://"                                   ;; TODO: bfs
-                (config/get-repo-dir (state/get-current-repo))
-                "assets" filename))
-        ext-name (util/get-file-ext filename)]
-    (when-let [key (and
-                     (= ext-name "pdf")
-                     (subs filename 0 (- (count filename) 4)))]
+  (let [filename  (util/node-path.basename full-path)
+        web-link? (string/starts-with? full-path "http")
+        ext-name  (util/get-file-ext filename)
+        url       (cond
+                    web-link?
+                    full-path
+
+                    (util/absolute-path? full-path)
+                    (str "file://" full-path)
+
+                    (string/starts-with? full-path "file:/")
+                    full-path
+
+                    :else
+                    (util/node-path.join
+                     "file://"                                  ;; TODO: bfs
+                     (config/get-repo-dir (state/get-current-repo))
+                     "assets" filename))]
+    (when-let [key
+               (if web-link?
+                 (str (hash url))
+                 (and
+                  (= ext-name "pdf")
+                  (subs filename 0 (- (count filename) 4))))]
       {:key      key
        :identity (subs key (- (count key) 15))
        :filename filename