Skip to content

Commit

Permalink
remove old sidenote mechanism
Browse files Browse the repository at this point in the history
  • Loading branch information
Mike Travers committed Jun 3, 2023
1 parent 04652e3 commit 004f250
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 49 deletions.
6 changes: 5 additions & 1 deletion src/goddinpotty/core.clj
Expand Up @@ -53,10 +53,14 @@
;;; BTW I want this available in all namespaces and it should be easy to do that.
(defonce last-bm (atom nil))

(defn pages
(defn page-ids
[]
(keys (u/dissoc-if (fn [[_ v]] (not (:page? v))) @last-bm)))

(defn pages
[]
(map @last-bm (page-ids)))

(defn dump
[bm]
(ju/schppit "dump.edn" bm))
Expand Down
58 changes: 58 additions & 0 deletions src/goddinpotty/curation.clj
Expand Up @@ -316,3 +316,61 @@
(set (repo-images @goddinpotty.core/last-bm))))

;;: TODO for remote-hosted images, copy them locally and update links

;;; Converting old sidenotes
;;; find block-refs to blocks on same page (repurpose old code)


;;; Block has a :block-ref, this determines if it is a sidenote or not
(defn block-block-refs
[block]
(->> block
:parsed
(u/walk-collect #(and (sequential? %)
(= :block-ref (first %))
(second %)
))
(map utils/remove-double-delimiters)
))

(defn block-has-sidenote?
[block]
(some (fn [ref]
(some (fn [child]
(= ref (get-in child [:properties :id])))
(:dchildren block)))
(block-block-refs block)))

(defn sidenote-pages
[bm]
(let [sidenote-blocks
(->> bm
vals
(filter block-has-sidenote?))
sidenote-pages
(distinct (map (partial bd/block-page bm) sidenote-blocks))]
(prn [(count sidenote-blocks) :sidenotes (count sidenote-pages) :pages])
(map :title sidenote-pages)))

;;; Not that many
#_
("__Materialism__, Terry Eagleton"
"Media Science"
"Patterns of Refactored Agency"
"Introduction to __Inventive Minds__"
"LWMap/What Motivated Rescuers During the Holocaust?"
"Demeney Voting"
"nihilism"
"Buddhism"
"nebulosity"
"Urizen"
"Nihilism and Agency"
"Notes on __Daybreak__"
"LWMap/Meta-honesty"
"Vimalakirti Sutra"
"Goddinpotty"
"Mastery of Non-Mastery in the Age of Meltdown"
"Labor and Embodiment"
"__On Purpose__")
;;; Alright easier to just hand edit.
48 changes: 1 addition & 47 deletions src/goddinpotty/rendering.clj
Expand Up @@ -15,8 +15,6 @@
)
)

;;; Sidenotes are a complete hairy mess, see logseq://graph/doc?page=sidenotes

;;; Turn parsed content into hiccup.

(declare block-content->hiccup) ;allow recursion on this
Expand Down Expand Up @@ -200,29 +198,7 @@

(declare block-hiccup)

;;; Blocks used as sidenotes get recorded here so they skip their normal render
;;; Yes this is global state and bad practice. Shoot me.
;;; TODO should get reset like u/memoizers
(def sidenotes (atom #{}))

(defn sidenote?
[id]
(contains? @sidenotes id))

;;; TODO flush all this kludgey machinery, new way is much simpler. Need to convert existing files
;;; This is used to suppress sidenotes in the Incoming links panel
;;; TODO now misnamed, we now just supress RENDERING them as sidenotes, still want them
(def ^{:dynamic true} *no-sidenotes* false)

;;; Render a sidenote (and both *s)
(defn sidenote
[block-map sidenote-block]
(swap! sidenotes conj (:id sidenote-block))
[:span.sidenote-container
[:span.superscript]
[:div.sidenote ;TODO option to render on left/right
[:span.superscript.side]
(block-full-hiccup-guts (:id sidenote-block) block-map)]])


;;; A much easier way to do sidenotes
Expand Down Expand Up @@ -335,18 +311,8 @@
:block-ref (let [ref-block (get (uid-indexed block-map) (-> ele-content
str/trim
utils/remove-double-delimiters))]
(try
;; :block-ref is repurposed for sidenotes, see doc
(if (and block
(= (bd/block-page block-map ref-block) ;if ref and block are on the same page
(bd/block-page block-map block)))
(when-not *no-sidenotes*
(sidenote block-map ref-block)) ;render the sidenote
[:div.block-ref ;render a real blockref
(block-hiccup ref-block block-map)])
;; Specifically, bad block refs will cause this.
(catch Throwable e
[:div.error "Couldn't render: " (str ast-ele)])))
:hashtag (let [ht (utils/parse-hashtag ele-content)]
(or (bd/special-hashtag-handler block-map ht block)
(page-link-by-name block-map ht)))
Expand Down Expand Up @@ -399,7 +365,6 @@
parsed))

;;; In lieu of putting this in the blockmap
;;; TODO memoization runs into *no-sidenotes* dynamic variable I think. So turned off. Shouldn't be calling this too many times I think?
;;; TODO turn it back on with old sidenote feature is history
(defn block-hiccup
"Convert Roam markup to Hiccup"
Expand Down Expand Up @@ -444,21 +409,10 @@
(map #(block-full-hiccup % block-map (inc depth))
(:children block))])))

(defn sidenote?
[id]
(contains? @sidenotes id))

;;; The real top-level call
(defn block-full-hiccup
[block-id block-map & [depth]]
;; This logic is very squirelly...we want sidenote blocks to render normally when they are in the linked-ref pane
(when (or *no-sidenotes* (not (sidenote? block-id)))
(block-full-hiccup-guts block-id block-map depth)))

(defn block-full-hiccup-no-sidenotes
[& args]
(binding [*no-sidenotes* true]
(apply block-full-hiccup args)))
(block-full-hiccup-guts block-id block-map depth))

(defn page-hiccup
[block-id block-map]
Expand Down
2 changes: 1 addition & 1 deletion src/goddinpotty/templating.clj
Expand Up @@ -25,7 +25,7 @@
;; TODO this might want to do an expand thing like in recent-changes page? Does't actually seem necessary here
;; TODO has been assuming this is in a low-level block, but that's not necessarily the case. For [[Introduction to [[Inventive Minds]]]], it includes the whole page!
;; See bd/expand-to, but we want to shrink in this case
[:div (render/block-full-hiccup-no-sidenotes r block-map)]])))
[:div (render/block-full-hiccup r block-map)]])))

(defn linked-references-template
[references block-map]
Expand Down

0 comments on commit 004f250

Please sign in to comment.