Skip to content

Commit 004f250

Browse files
author
Mike Travers
committed
remove old sidenote mechanism
1 parent 04652e3 commit 004f250

File tree

4 files changed

+65
-49
lines changed

4 files changed

+65
-49
lines changed

Diff for: src/goddinpotty/core.clj

+5-1
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,14 @@
5353
;;; BTW I want this available in all namespaces and it should be easy to do that.
5454
(defonce last-bm (atom nil))
5555

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

60+
(defn pages
61+
[]
62+
(map @last-bm (page-ids)))
63+
6064
(defn dump
6165
[bm]
6266
(ju/schppit "dump.edn" bm))

Diff for: src/goddinpotty/curation.clj

+58
Original file line numberDiff line numberDiff line change
@@ -316,3 +316,61 @@
316316
(set (repo-images @goddinpotty.core/last-bm))))
317317

318318
;;: TODO for remote-hosted images, copy them locally and update links
319+
320+
;;; Converting old sidenotes
321+
;;; find block-refs to blocks on same page (repurpose old code)
322+
323+
324+
;;; Block has a :block-ref, this determines if it is a sidenote or not
325+
(defn block-block-refs
326+
[block]
327+
(->> block
328+
:parsed
329+
(u/walk-collect #(and (sequential? %)
330+
(= :block-ref (first %))
331+
(second %)
332+
))
333+
(map utils/remove-double-delimiters)
334+
))
335+
336+
(defn block-has-sidenote?
337+
[block]
338+
(some (fn [ref]
339+
(some (fn [child]
340+
(= ref (get-in child [:properties :id])))
341+
(:dchildren block)))
342+
(block-block-refs block)))
343+
344+
(defn sidenote-pages
345+
[bm]
346+
(let [sidenote-blocks
347+
(->> bm
348+
vals
349+
(filter block-has-sidenote?))
350+
sidenote-pages
351+
(distinct (map (partial bd/block-page bm) sidenote-blocks))]
352+
(prn [(count sidenote-blocks) :sidenotes (count sidenote-pages) :pages])
353+
(map :title sidenote-pages)))
354+
355+
;;; Not that many
356+
#_
357+
("__Materialism__, Terry Eagleton"
358+
"Media Science"
359+
"Patterns of Refactored Agency"
360+
"Introduction to __Inventive Minds__"
361+
"LWMap/What Motivated Rescuers During the Holocaust?"
362+
"Demeney Voting"
363+
"nihilism"
364+
"Buddhism"
365+
"nebulosity"
366+
"Urizen"
367+
"Nihilism and Agency"
368+
"Notes on __Daybreak__"
369+
"LWMap/Meta-honesty"
370+
"Vimalakirti Sutra"
371+
"Goddinpotty"
372+
"Mastery of Non-Mastery in the Age of Meltdown"
373+
"Labor and Embodiment"
374+
"__On Purpose__")
375+
376+
;;; Alright easier to just hand edit.

Diff for: src/goddinpotty/rendering.clj

+1-47
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@
1515
)
1616
)
1717

18-
;;; Sidenotes are a complete hairy mess, see logseq://graph/doc?page=sidenotes
19-
2018
;;; Turn parsed content into hiccup.
2119

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

201199
(declare block-hiccup)
202200

203-
;;; Blocks used as sidenotes get recorded here so they skip their normal render
204-
;;; Yes this is global state and bad practice. Shoot me.
205-
;;; TODO should get reset like u/memoizers
206-
(def sidenotes (atom #{}))
207-
208-
(defn sidenote?
209-
[id]
210-
(contains? @sidenotes id))
211201

212-
;;; TODO flush all this kludgey machinery, new way is much simpler. Need to convert existing files
213-
;;; This is used to suppress sidenotes in the Incoming links panel
214-
;;; TODO now misnamed, we now just supress RENDERING them as sidenotes, still want them
215-
(def ^{:dynamic true} *no-sidenotes* false)
216-
217-
;;; Render a sidenote (and both *s)
218-
(defn sidenote
219-
[block-map sidenote-block]
220-
(swap! sidenotes conj (:id sidenote-block))
221-
[:span.sidenote-container
222-
[:span.superscript]
223-
[:div.sidenote ;TODO option to render on left/right
224-
[:span.superscript.side]
225-
(block-full-hiccup-guts (:id sidenote-block) block-map)]])
226202

227203

228204
;;; A much easier way to do sidenotes
@@ -335,18 +311,8 @@
335311
:block-ref (let [ref-block (get (uid-indexed block-map) (-> ele-content
336312
str/trim
337313
utils/remove-double-delimiters))]
338-
(try
339-
;; :block-ref is repurposed for sidenotes, see doc
340-
(if (and block
341-
(= (bd/block-page block-map ref-block) ;if ref and block are on the same page
342-
(bd/block-page block-map block)))
343-
(when-not *no-sidenotes*
344-
(sidenote block-map ref-block)) ;render the sidenote
345314
[:div.block-ref ;render a real blockref
346315
(block-hiccup ref-block block-map)])
347-
;; Specifically, bad block refs will cause this.
348-
(catch Throwable e
349-
[:div.error "Couldn't render: " (str ast-ele)])))
350316
:hashtag (let [ht (utils/parse-hashtag ele-content)]
351317
(or (bd/special-hashtag-handler block-map ht block)
352318
(page-link-by-name block-map ht)))
@@ -399,7 +365,6 @@
399365
parsed))
400366

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

447-
(defn sidenote?
448-
[id]
449-
(contains? @sidenotes id))
450-
451412
;;; The real top-level call
452413
(defn block-full-hiccup
453414
[block-id block-map & [depth]]
454-
;; This logic is very squirelly...we want sidenote blocks to render normally when they are in the linked-ref pane
455-
(when (or *no-sidenotes* (not (sidenote? block-id)))
456-
(block-full-hiccup-guts block-id block-map depth)))
457-
458-
(defn block-full-hiccup-no-sidenotes
459-
[& args]
460-
(binding [*no-sidenotes* true]
461-
(apply block-full-hiccup args)))
415+
(block-full-hiccup-guts block-id block-map depth))
462416

463417
(defn page-hiccup
464418
[block-id block-map]

Diff for: src/goddinpotty/templating.clj

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
;; TODO this might want to do an expand thing like in recent-changes page? Does't actually seem necessary here
2626
;; 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!
2727
;; See bd/expand-to, but we want to shrink in this case
28-
[:div (render/block-full-hiccup-no-sidenotes r block-map)]])))
28+
[:div (render/block-full-hiccup r block-map)]])))
2929

3030
(defn linked-references-template
3131
[references block-map]

0 commit comments

Comments
 (0)