Converting a list of JS objects into a parent-child tree
My previous approach to displaying my notes on this site was to render them as a tree of infinitely nested topics and subtopics:
Parents and children
To achieve that nesting, my solution was to manually give each note that represented a subtopic (or subsubsubtopic) a parent value (via markdown frontmatter) and then move any child notes (i.e. notes with a parent value) into their parent’s children array:
Incremental left padding
My solution for visually indicating how those notes related to each other was to multiply each note’s left-padding by 1.4x its descendent level:
Maintaining note hierarchies is a chore
That was a fun programming puzzle to solve, but unfortunately it made my note-taking more difficult by forcing me to decide where each new thought belonged in the hierarchy before I could jot it down.
To remove that friction, I’ve adopted to a flat (and eventually searchable and filterable) approach to note-taking instead. But I wanted to share this former nested-topics solution in case anyone else finds it useful.