1
0
Эх сурвалжийг харах

fix: skip export if page/name not found

rcmerci 4 жил өмнө
parent
commit
d9afcd69e0

+ 2 - 1
src/main/frontend/components/header.cljs

@@ -215,4 +215,5 @@
                        :default-home default-home})
 
        [:a#download-as-html.hidden]
-       [:a#download-as-zip.hidden]])))
+       [:a#download-as-zip.hidden]
+       [:a#export-as-markdown.hidden]])))

+ 17 - 7
src/main/frontend/handler/export.cljs

@@ -113,8 +113,7 @@
   (let [conn (db/get-conn repo)]
     (->>
      (filterv (fn [[path _]]
-                (or (string/ends-with? path ".md")
-                    (string/ends-with? path ".org")))
+                (or (string/ends-with? path ".md")))
               (db/get-file-contents repo))
      (mapv (fn [[path content]] {:path path :content content
                                    :names (d/q '[:find [?n ?n2]
@@ -205,8 +204,19 @@
   [repo]
   (when-let [repo (state/get-current-repo)]
     (when-let [files (get-file-contents-with-suffix repo)]
-      (mapv (fn [{:keys [path content names format]}]
-              [path (fp/exportMarkdown f/mldoc-record content
-                                       (f/get-default-config format)
-                                       (js/JSON.stringify
-                                        (clj->js (get-embed-and-refs-blocks-pages repo (first names)))))]) files))))
+      (let [files
+            (->> files
+                 (mapv (fn [{:keys [path content names format]}]
+                         (when (first names)
+                           [path (fp/exportMarkdown f/mldoc-record content
+                                                    (f/get-default-config format)
+                                                    (js/JSON.stringify
+                                                     (clj->js (get-embed-and-refs-blocks-pages repo (first names)))))])
+                         ) )
+                 (remove nil?))]
+        (p/let [zipfile (zip/make-zip repo files)]
+          (when-let [anchor (gdom/getElement "export-as-markdown")]
+            (.setAttribute anchor "href" (js/window.URL.createObjectURL zipfile))
+            (.setAttribute anchor "download" (.-name zipfile))
+            (.click anchor)))
+        ))))