Skip to content

[Feature Request]: Improve or create a new toc component? #542

@LoganQiu

Description

@LoganQiu

The existing toc is good, but I can't know the chapter I'm reading in real time when reading an article. Can I consider fixing the toc on the right side of the article? But it seems that I can't use the remark-toc component? Since I'm a newbee in astro, I used AI to generate a component TOC.astro. Then add

  {hasSubHeadings && (
  <!-- mobile TOC -->
  <div class="toc-mobile xl:hidden mx-auto w-full max-w-4xl px-4 mb-6 mt-4">
    <details class="bg-background rounded-lg p-4 border">
      <summary class="cursor-pointer font-medium text-foreground">
        Table of Contents
      </summary>
      <div class="mt-3">
        <TOC headings={headings} />
      </div>
    </details>
  </div>
  <!-- desktop TOC -->
  <div class="toc-desktop hidden xl:block fixed top-24 right-8 w-64 max-h-[calc(100vh-8rem)] overflow-y-auto z-10">
    <div class="bg-background border rounded-md p-4">
      <h3 class="text-sm font-semibold text-foreground mb-2 pb-2 border-b">
        Table of Contents
      </h3>
      <div class="text-sm">
        <TOC headings={headings} />
      </div>
    </div>
  </div>
  )}

in PostDetails.astro.

The presentation style is probably like this https://zeratulqiu.me/posts/windows-skills/ (Sorry, the website is in Chinese).

I'm sure there should be a better way to do this, but due to my lack of skills, this is the only way I can do it right now.

Translated by Google.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions