0.1.3 • Published 1 year ago

astro-toc v0.1.3

Weekly downloads
-
License
ISC
Repository
github
Last release
1 year ago

astro-toc

license npm

Table of Contents (ToC) generator for Astro

Open in StackBlitz

Table of Contents

Install

npm install astro-toc

Usage

Classic

This render mode can render your ToC as <ul>, <ol> or <menu>; set the as property to select your flavour.

PropertyTypeDescription
toc{ depth: number; title: string; url?: string; [string]: any }[]depth and title are required.
as optionalstringbullet | number | menu
maxDepth optionalnumberHow many levels should be rendered
---
import { TOC } from "astro-toc";

const toc = [
  {depth: 1, title: "Tours", url: /* optional*/},
  {depth: 2, title: "Walking Tours"},
  {depth: 3, title: "City Walking Tours"},
  {depth: 3, title: "River Walking Tours"},
  {depth: 2, title: "Boat Tours"},
  {depth: 1, title: "Restaurants"},
  {depth: 2, title: "Fine Dining"},
  {depth: 2, title: "Gastropub"},
  {depth: 2, title: "Fast Food"},
  {depth: 1, title: "Hotels"},
  {depth: 2, title: "Spa Hotels"},
  {depth: 2, title: "Bed & Breakfast"},
];
---

<TOC toc={toc} />

Component

When using a custom component it uses the \<menu> element.

Unlike the classic render method title isn't required and the payload will be passed to the component.

PropertyTypeDescription
toc{ depth: number; [string]: any }[]depth is required.
use(props) => anyAstro component
maxDepth optionalnumber | stringHow many levels should be rendered
---
import { TOC } from "astro-toc";
import MyComponent from "path/to/MyComponent.astro";

const toc = [
  {depth: 1, title: "Tours"},
  {depth: 2, title: "Walking Tours"},
  {depth: 3, title: "City Walking Tours"},
  {depth: 3, title: "River Walking Tours"},
  {depth: 2, title: "Boat Tours"},
  {depth: 1, title: "Restaurants"},
  {depth: 2, title: "Fine Dining"},
  {depth: 2, title: "Gastropub"},
  {depth: 2, title: "Fast Food"},
  {depth: 1, title: "Hotels"},
];
---

<TOC toc={toc} use={MyComponent} />

License

ISC

0.1.3

1 year ago

0.1.2

2 years ago

0.1.1

2 years ago

0.1.0

2 years ago