3 ms·
This trick is particularly useful for rendering things that have somewhat of a hierarchy, but aren't implicitly hierarchal. Like a table of contents for a HTML
by paradox460 3y ago
This trick is particularly useful for rendering things that have somewhat of a hierarchy, but aren't implicitly hierarchal. Like a table of contents for a HTML page, targeting the various header (h1-h6) elements. They're not (generally) descendents of each other, and parsing them is simpler to just go as a list of items with a depth.
I used this for the table of contents on my personal site:
Parser:
https://github.com/paradox460/pdx.su/blob/main/lib/toc.ex https://github.com/paradox460/pdx.su/blob/main/lib/toc.ex
Renderer: https://github.com/paradox460/pdx.su/blob/main/lib/layouts/post_layout.ex#L20-L27 https://github.com/paradox460/pdx.su/blob/main/lib/layouts/p...