life-itself / web3

Making sense of web3 & crypto. Introduction to key concepts and ideas. Rigorous, constructive analysis of key claims pro and con. A look at the deeper hopes and aspirations.

Home Page:https://web3.lifeitself.org/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

RHS table of contents

olayway opened this issue · comments

Priority over #153


User story

A user can quickly eyeball the contents of the current page by looking at the table of contents (ToC) on the right-hand side. He can also quickly navigate to different sections of the current page by clicking on a section title in the ToC and see where he's currently at thanks to highlighting of the currently focused section.

Inspiration

Tailwind page: https://tailwindcss.com/docs/installation

image

Acceptance

  • ToC on the right-hand side that lists all the headings of the current page
  • subheadings of different levels should be accordingly indented
  • ToC should always be visible (doesn't hide on scrolling)
  • page should smooth-scroll to a given section upon clicking on its title in the ToC
  • title of the currently focused section should be highlighted

References

Original issue: #93

Notes from discussion on ~ 14 June 2022


Analaysis

Key features

  • RHS table of contents shows content from current page (excluding the main/page heading??)
  • Updates as we scroll the page to highlight
  • Quesitons
    • What happens on non-markdown pages?
    • Can we disable toc generation?
    • How does this connect to generating "toc" for entire site?

Aside: does this connect with anchor links for headings - #99

Note this was supposed to include nice anchor hovers but not sure that was implemented - note that issue is "bad" as no acceptance criteria, description or anything!

Comment from Ola: have implemented colored hover which may be just as good UX.

Broken word wrapping bug

As per the closed issue #99, the rehype plugin rehype-autolink-headings added anchor tags to headings. However, since there was no behavior: wrap option set to it, the anchor tags were added next to the spans with heading's text, like so:

  • rehype plug in added in april and everything fine
  • ola tweaked plugin so that we can have behaviour to click on headings and update anchor
    • Added option behaviour: wrap so that heading text was inside anchor rather than sibling to it
  • led to bug because ... (something in css of rehype or otherwise)
  • fixed this by adding css in our globals

Now we have this in contentlayer.config:

[ rehypeAutolinkHeadings, { behavior: 'wrap' } ],

<h2 id="the-politics-and-economics-of-daos-crypto-and-blockchain" class="c-heading scroll-mt-16 cursor-pointer">
<a href="#the-politics-and-economics-of-daos-crypto-and-blockchain">
The politics and economics of DAOs, crypto and blockchain
</a>
</h2>

We used to have this:

[ rehypeAutolinkHeadings ],

<h2 id="the-politics-and-economics-of-daos-crypto-and-blockchain" class="c-heading scroll-mt-16 cursor-pointer">
  <a aria-hidden="true" tabindex="-1" href="#the-politics-and-economics-of-daos-crypto-and-blockchain"><span class="icon icon-link"></span></a>
  The politics and economics of DAOs, crypto and blockchain
</h2>

Brainstorming

How can we do this?

Proposed solution

  • rehype-toc to generate a toc as html or in the syntax tree

Options

  • Use rehype autolink headings etc => we hve to do heading extraction in rehype after this as this is where slugs get generated
    • Why? quick
  • parse the markdown ourselves (use existing remark tooling) and take care of adding slugs there (so don't use rehype-autolink-headings and rehype-toc)
    • Why do this?
    • Because we have more control over extraction of ToC and its use in the page

@olayway one issue with making the heading itself into a link is that you can't have links in the heading ... (i think this is the reason most people have a hover effect with actual link item outside of the text e.g. on the left as an icon). Examples of this behaviour on the news page https://web3.lifeitself.us/notes/news