Skip to content

Commit

Permalink
Add graph-parser deps and rebuild
Browse files Browse the repository at this point in the history
  • Loading branch information
logseq-cldwalker committed Jun 20, 2022
1 parent 31b2f4e commit d8ebd1d
Show file tree
Hide file tree
Showing 23 changed files with 2,782 additions and 5 deletions.
4 changes: 3 additions & 1 deletion action.cljs
@@ -1,9 +1,11 @@
(ns action
(:require [nbb.core :as nbb]))
(:require [nbb.core :as nbb]
[logseq.graph-parser.cli :as gp-cli]))

(defn action
;; deps passed by index.mjs
[deps]
(prn :CLI gp-cli/parse-graph)
(let [{:strs [actionsCore actionsGithub]} (js->clj deps)]
(try
(let [name-to-greet (.getInput actionsCore "who-to-greet")
Expand Down
4 changes: 3 additions & 1 deletion dist/action.cljs
@@ -1,9 +1,11 @@
(ns action
(:require [nbb.core :as nbb]))
(:require [nbb.core :as nbb]
[logseq.graph-parser.cli :as gp-cli]))

(defn action
;; deps passed by index.mjs
[deps]
(prn :CLI gp-cli/parse-graph)
(let [{:strs [actionsCore actionsGithub]} (js->clj deps)]
(try
(let [name-to-greet (.getInput actionsCore "who-to-greet")
Expand Down
5 changes: 4 additions & 1 deletion dist/index.mjs
Expand Up @@ -8930,6 +8930,8 @@ __nccwpck_require__.a(__webpack_module__, async (__webpack_handle_async_dependen

const __dirname = (0,path__WEBPACK_IMPORTED_MODULE_1__.dirname)(".");
const theFile = __nccwpck_require__.ab + "action.cljs";
(0,_logseq_nbb_logseq__WEBPACK_IMPORTED_MODULE_0__/* .addClassPath */ .YO)(__nccwpck_require__.ab + "src");
(0,_logseq_nbb_logseq__WEBPACK_IMPORTED_MODULE_0__/* .addClassPath */ .YO)(__nccwpck_require__.ab + "src1");
const { action } = await (0,_logseq_nbb_logseq__WEBPACK_IMPORTED_MODULE_0__/* .loadFile */ .xl)(__nccwpck_require__.ab + "action.cljs");
action( { actionsCore: /*#__PURE__*/ (_actions_core__WEBPACK_IMPORTED_MODULE_2___namespace_cache || (_actions_core__WEBPACK_IMPORTED_MODULE_2___namespace_cache = __nccwpck_require__.t(_actions_core__WEBPACK_IMPORTED_MODULE_2__, 2))), actionsGithub: /*#__PURE__*/ (_actions_github__WEBPACK_IMPORTED_MODULE_3___namespace_cache || (_actions_github__WEBPACK_IMPORTED_MODULE_3___namespace_cache = __nccwpck_require__.t(_actions_github__WEBPACK_IMPORTED_MODULE_3__, 2)))} );

Expand All @@ -8944,10 +8946,11 @@ __webpack_handle_async_dependencies__();

// EXPORTS
__nccwpck_require__.d(__webpack_exports__, {
"YO": () => (/* reexport */ ex_nbb_api_addClassPath),
"xl": () => (/* reexport */ ex_nbb_api_loadFile)
});

// UNUSED EXPORTS: $APP, $jscomp, addClassPath, getClassPath, loadString, shadow$provide, version
// UNUSED EXPORTS: $APP, $jscomp, getClassPath, loadString, shadow$provide, version

;// CONCATENATED MODULE: external "module"
const external_module_namespaceObject = __WEBPACK_EXTERNAL_createRequire(import.meta.url)("module");
Expand Down
74 changes: 74 additions & 0 deletions dist/src/logseq/graph_parser.cljs
@@ -0,0 +1,74 @@
(ns logseq.graph-parser
"Main ns used by logseq app to parse graph from source files"
(:require [datascript.core :as d]
[logseq.graph-parser.extract :as extract]
[logseq.graph-parser.util :as gp-util]
[logseq.graph-parser.date-time-util :as date-time-util]
[logseq.graph-parser.config :as gp-config]
[clojure.string :as string]
[clojure.set :as set]))

(defn- db-set-file-content!
"Modified copy of frontend.db.model/db-set-file-content!"
[conn path content]
(let [tx-data {:file/path path
:file/content content}]
(d/transact! conn [tx-data] {:skip-refresh? true})))

(defn parse-file
"Parse file and save parsed data to the given db. Main parse fn used by logseq app"
[conn file content {:keys [new? delete-blocks-fn extract-options]
:or {new? true
delete-blocks-fn (constantly [])}
:as options}]
(db-set-file-content! conn file content)
(let [format (gp-util/get-format file)
file-content [{:file/path file}]
{:keys [tx ast]}
(if (contains? gp-config/mldoc-support-formats format)
(let [extract-options' (merge {:block-pattern (gp-config/get-block-pattern format)
:date-formatter "MMM do, yyyy"
:supported-formats (gp-config/supported-formats)}
extract-options
{:db @conn})
{:keys [pages blocks ast]}
(extract/extract file content extract-options')
delete-blocks (delete-blocks-fn (first pages) file)
block-ids (map (fn [block] {:block/uuid (:block/uuid block)}) blocks)
block-refs-ids (->> (mapcat :block/refs blocks)
(filter (fn [ref] (and (vector? ref)
(= :block/uuid (first ref)))))
(map (fn [ref] {:block/uuid (second ref)}))
(seq))
;; To prevent "unique constraint" on datascript
block-ids (set/union (set block-ids) (set block-refs-ids))
pages (extract/with-ref-pages pages blocks)
pages-index (map #(select-keys % [:block/name]) pages)]
;; does order matter?
{:tx (concat file-content pages-index delete-blocks pages block-ids blocks)
:ast ast})
{:tx file-content})
tx (concat tx [(cond-> {:file/path file}
new?
;; TODO: use file system timestamp?
(assoc :file/created-at (date-time-util/time-ms)))])]
{:tx
(d/transact! conn (gp-util/remove-nils tx) (select-keys options [:new-graph? :from-disk?]))
:ast ast}))

(defn filter-files
"Filters files in preparation for parsing. Only includes files that are
supported by parser"
[files]
(let [support-files (filter
(fn [file]
(let [format (gp-util/get-format (:file/path file))]
(contains? (set/union #{:edn :css} gp-config/mldoc-support-formats) format)))
files)
support-files (sort-by :file/path support-files)
{journals true non-journals false} (group-by (fn [file] (string/includes? (:file/path file) "journals/")) support-files)
{built-in true others false} (group-by (fn [file]
(or (string/includes? (:file/path file) "contents.")
(string/includes? (:file/path file) ".edn")
(string/includes? (:file/path file) "custom.css"))) non-journals)]
(concat (reverse journals) built-in others)))

0 comments on commit d8ebd1d

Please sign in to comment.