fix ends-with nil issue

pull/6112/head
Peng Xiao 2022-07-13 19:28:22 +08:00
parent 0b1119a61f
commit 2d4e0bef18
4 changed files with 19 additions and 14 deletions

View File

@ -24,7 +24,8 @@
(defn whiteboard?
[path]
(and (string/includes? path (str "/" default-whiteboards-directory "/"))
(and path
(string/includes? path (str default-whiteboards-directory "/"))
(string/ends-with? path ".edn")))
;; TODO: rename

View File

@ -186,17 +186,17 @@
[file content {:keys [verbose] :or {verbose true} :as options}]
(let [_ (when verbose (println "Parsing start: " file))
{:keys [pages blocks]} (gp-util/safe-read-string content)
page-block (first pages)]
(when (:block/whiteboard? page-block)
(let [page-name (filepath->page-name file)
page-entity (build-page-entity {} file page-name page-name nil options)
page-block (merge page-block page-entity {:block/uuid (d/squuid)})
blocks (->> blocks
(map #(merge % {:block/level 1
:block/uuid (gp-block/get-custom-id-or-new-id (:block/properties %))}))
(gp-block/with-parent-and-left {:block/name page-name}))]
{:pages [page-block]
:blocks blocks}))))
page-block (first pages)
page-name (filepath->page-name file)
page-entity (build-page-entity {} file page-name page-name nil options)
page-block (merge page-block page-entity {:block/uuid (d/squuid)})
blocks (->> blocks
(map #(merge % {:block/level 1
:block/uuid (gp-block/get-custom-id-or-new-id (:block/properties %))}))
(gp-block/with-parent-and-left {:block/name page-name}))
_ (when verbose (println "Parsing finished: " file))]
{:pages [page-block]
:blocks blocks}))
(defn- with-block-uuid
[pages]

View File

@ -32,7 +32,7 @@
[repo page-db-id]
(let [page-block (db/pull repo '[* {:block/file [:file/path]}] page-db-id)
file-path (get-in page-block [:block/file :file/path])
edn? (string/ends-with? file-path ".edn")
edn? (and file-path (string/ends-with? file-path ".edn"))
blocks (model/get-page-blocks-no-cache repo (:block/name page-block)
{:pull-keys (if edn? blocks-pull-keys-with-persisted-ids '[*])})]
(when-not (and (= 1 (count blocks))

View File

@ -1,6 +1,7 @@
(ns frontend.modules.whiteboard.core
(:require [frontend.db :as db]
[frontend.db.model :as model]
[clojure.pprint :as pprint]
[goog.object :as gobj]))
(defn- get-page-block [page-name]
@ -8,7 +9,8 @@
(defn- block->shape [block]
(let [properties (:block/properties block)]
(merge properties
(merge block
properties
;; Use the block's id as the shape's id.
{:id (str (:block/uuid block))})))
@ -47,3 +49,5 @@
blocks {})
blocks (map #(shape->block blocks-by-uuid %) shapes)]
[page-block blocks]))
(js/console.log (page-name->tldr "edn-test"))