mirror of https://github.com/logseq/logseq
wip, new version of add property test
parent
828e296f86
commit
adbf5a1674
|
@ -1,14 +1,15 @@
|
|||
(ns frontend.date
|
||||
(:require [cljs-time.core :as t]
|
||||
(:require ["chrono-node" :as chrono]
|
||||
[cljs-bean.core :as bean]
|
||||
[cljs-time.coerce :as tc]
|
||||
[cljs-time.core :as t]
|
||||
[cljs-time.format :as tf]
|
||||
[cljs-time.local :as tl]
|
||||
[frontend.state :as state]
|
||||
[cljs-bean.core :as bean]
|
||||
[frontend.util :as util]
|
||||
[clojure.string :as string]
|
||||
[frontend.state :as state]
|
||||
[frontend.util :as util]
|
||||
[goog.object :as gobj]
|
||||
["chrono-node" :as chrono]))
|
||||
[lambdaisland.glogi :as log]))
|
||||
|
||||
(defn nld-parse
|
||||
[s]
|
||||
|
@ -100,6 +101,14 @@
|
|||
([date]
|
||||
(format date)))
|
||||
|
||||
(defn journal-name-s [s]
|
||||
(try
|
||||
(journal-name (tf/parse s))
|
||||
(catch js/Error e
|
||||
(log/error :parse-journal-date {:message "Failed to parse date to journal name"
|
||||
:date-str s})
|
||||
nil)))
|
||||
|
||||
(defn today
|
||||
[]
|
||||
(journal-name))
|
||||
|
|
|
@ -44,7 +44,10 @@
|
|||
(get* config (str "/items/" key)))
|
||||
|
||||
(comment
|
||||
(get* config "/collections" {:limit 1})
|
||||
(get* config "/collections")
|
||||
(get* config "/items" {:limit 3})
|
||||
(get* config "/items" {:item-type "journalArticle"})
|
||||
(item "JZCIN4K5"))
|
||||
(item "JZCIN4K5")
|
||||
(item "RFYNAQTN")
|
||||
(item "3V6N8ECQ")
|
||||
)
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
(:require [clojure.string :as str]
|
||||
[frontend.util :as util]
|
||||
[frontend.extensions.zotero.schema :as schema]
|
||||
[frontend.date :as date]
|
||||
[frontend.extensions.zotero.api :as api]))
|
||||
|
||||
(defn item-type [item] (-> item :data :item-type))
|
||||
|
@ -44,14 +45,31 @@
|
|||
(mapv (fn [{:keys [tag]}] (util/format "[[%s]]" tag))))]
|
||||
(str/join ", " tags)))
|
||||
|
||||
(defn date->journal [item]
|
||||
(let [date (-> item :data :date)]
|
||||
(when-not (str/blank? date)
|
||||
(->> (date/journal-name-s date)
|
||||
(util/format "[[%s]]")))))
|
||||
|
||||
(defn wrap-in-doublequotes [m]
|
||||
(->> m
|
||||
(map (fn [[k v]]
|
||||
(if (str/includes? (str v) ",")
|
||||
[k (pr-str v)]
|
||||
[k v])))
|
||||
(into (array-map))))
|
||||
|
||||
(defn properties [item]
|
||||
(let [fields (schema/fields "journalArticle")
|
||||
authors (authors item)
|
||||
tags (tags item)
|
||||
data (-> item :data
|
||||
(let [fields (schema/fields "journalArticle")
|
||||
authors (authors item)
|
||||
tags (tags item)
|
||||
date (date->journal item)
|
||||
data (-> item :data
|
||||
(select-keys fields)
|
||||
(wrap-in-doublequotes)
|
||||
(assoc :authors authors
|
||||
:tags tags)
|
||||
:tags tags
|
||||
:date date)
|
||||
(dissoc :creators :extra))]
|
||||
(->> data
|
||||
(remove (comp str/blank? second))
|
||||
|
|
|
@ -2,20 +2,61 @@
|
|||
(:require [frontend.handler.page :as page-handler]
|
||||
[frontend.extensions.zotero.api :as zotero-api]
|
||||
[cljs.core.async :refer [go <!]]
|
||||
[frontend.util.property :as property-util]
|
||||
[frontend.handler.editor :as editor-handler]
|
||||
[frontend.state :as state]
|
||||
[frontend.db :as db]
|
||||
[frontend.extensions.zotero.extractor :as extractor]
|
||||
[clojure.string :as str]))
|
||||
|
||||
;; FIXME need to quote the property value
|
||||
(defn create-zotero-page [key]
|
||||
(go
|
||||
(let [item (<! (zotero-api/item key))
|
||||
{:keys [page-name properties]} (extractor/extract item)]
|
||||
(page-handler/create! page-name {:redirect? false :format :markdown})
|
||||
(doseq [[field value] properties]
|
||||
(page-handler/page-add-property! page-name field value))
|
||||
(editor-handler/api-insert-new-block!
|
||||
""
|
||||
{:page page-name
|
||||
:properties properties})
|
||||
(js/alert "finish"))))
|
||||
|
||||
|
||||
(comment
|
||||
(create-zotero-page "JAHCZRNB")
|
||||
(create-zotero-page "RFYNAQTN"))
|
||||
(create-zotero-page "RFYNAQTN")
|
||||
|
||||
(create-zotero-page "3V6N8ECQ")
|
||||
|
||||
(def page-name (:page-name (extractor/extract zotero-api/rr)))
|
||||
(def properties (:properties (extractor/extract zotero-api/rr)))
|
||||
|
||||
|
||||
;; this is good
|
||||
(editor-handler/api-insert-new-block!
|
||||
"abcabc"
|
||||
{:page page-name
|
||||
;; :properties properties
|
||||
})
|
||||
|
||||
;; outliner error
|
||||
(editor-handler/api-insert-new-block!
|
||||
""
|
||||
{:page page-name
|
||||
:properties properties})
|
||||
|
||||
#_
|
||||
(item "3V6N8ECQ")
|
||||
;; (db/get-page-blocks)
|
||||
;; (page-handler/page-add-property! )
|
||||
;; (editor-handler/insert-new-block-aux! )
|
||||
|
||||
;; (db/entity [:block/name (str/lower-case "@picardMITMediaLaboratory")])
|
||||
|
||||
;; (db/get-page-blocks "ccc")
|
||||
|
||||
;; (def block (state/get-edit-block))
|
||||
#_
|
||||
(editor-handler/save-block-if-changed!
|
||||
block
|
||||
(property-util/insert-property :markdown "xxx" :test "value")
|
||||
{:force? true}))
|
||||
|
|
|
@ -38,7 +38,7 @@
|
|||
#?(:cljs
|
||||
(defn transact!
|
||||
[txs opts]
|
||||
;; (util/pprint txs)
|
||||
(util/pprint txs)
|
||||
(when (and (seq txs)
|
||||
(not (:skip-transact? opts)))
|
||||
(try
|
||||
|
|
|
@ -7482,6 +7482,11 @@ react-grid-layout@^0.16.6:
|
|||
react-draggable "3.x"
|
||||
react-resizable "1.x"
|
||||
|
||||
react-icon-base@2.1.0:
|
||||
version "2.1.0"
|
||||
resolved "https://registry.yarnpkg.com/react-icon-base/-/react-icon-base-2.1.0.tgz#a196e33fdf1e7aaa1fda3aefbb68bdad9e82a79d"
|
||||
integrity sha1-oZbjP98eeqof2jrvu2i9rZ6Cp50=
|
||||
|
||||
react-icons@^2.2.7:
|
||||
version "2.2.7"
|
||||
resolved "https://registry.yarnpkg.com/react-icons/-/react-icons-2.2.7.tgz#d7860826b258557510dac10680abea5ca23cf650"
|
||||
|
|
Loading…
Reference in New Issue