|
|
@@ -609,6 +609,12 @@
|
|
|
(str (gp-property/colons-org "id") " " (:uuid block)))))]
|
|
|
(string/replace-first c replace-str ""))))))
|
|
|
|
|
|
+(defn block-exists-in-another-page?
|
|
|
+ [db block-uuid current-page-name]
|
|
|
+ (when (and db current-page-name)
|
|
|
+ (when-let [block-page-name (:block/name (:block/page (d/entity db [:block/uuid block-uuid])))]
|
|
|
+ (not= current-page-name block-page-name))))
|
|
|
+
|
|
|
(defn extract-blocks
|
|
|
"Extract headings from mldoc ast.
|
|
|
Args:
|
|
|
@@ -617,13 +623,14 @@
|
|
|
`with-id?`: If `with-id?` equals to true, all the referenced pages will have new db ids.
|
|
|
`format`: content's format, it could be either :markdown or :org-mode.
|
|
|
`options`: Options supported are :user-config, :block-pattern :supported-formats,
|
|
|
- :extract-macros, :date-formatter and :db"
|
|
|
- [blocks content with-id? format {:keys [user-config] :as options}]
|
|
|
+ :extract-macros, :extracted-block-ids, :date-formatter, :page-name and :db"
|
|
|
+ [blocks content with-id? format {:keys [user-config db page-name extracted-block-ids] :as options}]
|
|
|
{:pre [(seq blocks) (string? content) (boolean? with-id?) (contains? #{:markdown :org} format)]}
|
|
|
(let [encoded-content (utf8/encode content)
|
|
|
+ *block-ids (or extracted-block-ids (atom #{}))
|
|
|
+ ;; TODO: nbb doesn't support `Atom`
|
|
|
[blocks body pre-block-properties]
|
|
|
(loop [headings []
|
|
|
- block-ids #{}
|
|
|
blocks (reverse blocks)
|
|
|
timestamps {}
|
|
|
properties {}
|
|
|
@@ -639,22 +646,25 @@
|
|
|
(paragraph-timestamp-block? block)
|
|
|
(let [timestamps (extract-timestamps block)
|
|
|
timestamps' (merge timestamps timestamps)]
|
|
|
- (recur headings block-ids (rest blocks) timestamps' properties body))
|
|
|
+ (recur headings (rest blocks) timestamps' properties body))
|
|
|
|
|
|
(gp-property/properties-ast? block)
|
|
|
(let [properties (extract-properties (second block) (assoc user-config :format format))]
|
|
|
- (recur headings block-ids (rest blocks) timestamps properties body))
|
|
|
+ (recur headings (rest blocks) timestamps properties body))
|
|
|
|
|
|
(heading-block? block)
|
|
|
(let [block' (construct-block block properties timestamps body encoded-content format pos-meta with-id? options)
|
|
|
block'' (assoc block' :macros (extract-macros-from-ast (cons block body)))
|
|
|
- [block-ids block] (if (block-ids (:uuid block''))
|
|
|
- [block-ids (fix-duplicate-id block'')]
|
|
|
- [(conj block-ids (:uuid block'')) block''])]
|
|
|
- (recur (conj headings block) block-ids (rest blocks) {} {} []))
|
|
|
+ block-uuid (:uuid block'')
|
|
|
+ fixed-block (if (or (@*block-ids block-uuid)
|
|
|
+ (block-exists-in-another-page? db block-uuid page-name))
|
|
|
+ (fix-duplicate-id block'')
|
|
|
+ block'')]
|
|
|
+ (swap! *block-ids conj (:uuid fixed-block))
|
|
|
+ (recur (conj headings fixed-block) (rest blocks) {} {} []))
|
|
|
|
|
|
:else
|
|
|
- (recur headings block-ids (rest blocks) timestamps properties (conj body block))))
|
|
|
+ (recur headings (rest blocks) timestamps properties (conj body block))))
|
|
|
[(-> (reverse headings)
|
|
|
sanity-blocks-data)
|
|
|
body
|