Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RHS table of contents #152

Closed
5 tasks done
olayway opened this issue May 10, 2022 · 2 comments · Fixed by #167
Closed
5 tasks done

RHS table of contents #152

olayway opened this issue May 10, 2022 · 2 comments · Fixed by #167
Assignees
Labels
enhancement New feature or request Tech

Comments

@olayway
Copy link
Contributor

olayway commented May 10, 2022

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

@olayway olayway added Tech enhancement New feature or request labels May 10, 2022
@olayway olayway added this to web3 May 10, 2022
@olayway olayway moved this to Backlog in web3 May 10, 2022
@olayway olayway moved this from Backlog to Prioritized in web3 May 10, 2022
This was referenced May 10, 2022
@rufuspollock rufuspollock mentioned this issue May 20, 2022
2 tasks
@olayway olayway assigned olayway and unassigned khalilcodes May 22, 2022
@olayway olayway moved this from Prioritized to In Progress in web3 May 22, 2022
@olayway olayway mentioned this issue May 26, 2022
Repository owner moved this from In Progress to Done in web3 Jun 7, 2022
@rufuspollock
Copy link
Member

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

@rufuspollock
Copy link
Member

@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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request Tech
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

3 participants