Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/brob/nested-toc-json-generator
https://github.com/brob/nested-toc-json-generator
Last synced: 10 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/brob/nested-toc-json-generator
- Owner: brob
- License: mit
- Created: 2022-11-11T18:43:42.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2023-12-15T02:47:00.000Z (about 1 year ago)
- Last Synced: 2024-12-23T10:39:40.388Z (13 days ago)
- Language: JavaScript
- Size: 4.88 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Gets a nested ToC data structure from heading data
This is currently tested against Hygraph data, but should work for most data if you follow the following structure:
```js
[
{
"type": "heading-one", // or h1
"id": "some-id-here" // ID for jumplink
// ...additionalData
},
{
"type": "heading-two", // or h2
"id": "some-other-id-here" // ID for jumplink
// ...additionalData
}
]
```
Given that structure, it will return a nested structure for frontend loops and nested lists.```js
[
{
"type": "heading-one",
"id": "some-id-here"
// ...additionalData,
"tocChildren": [
{
"type": "heading-two",
"id": "some-other-id-here",
"tocChildren": [/*additional nests */],
// ...additionalData
}
]
}
]
```## Installation
```bash
npm i nested-toc-json-generator
```## Usage
```js
const generateJSON = require("nested-toc-json-generator")const data = [
{
"type": "heading-one", // or h1
"id": "some-id-here" // ID for jumplink
// ...additionalData
},
{
"type": "heading-two", // or h2
"id": "some-other-id-here" // ID for jumplink
// ...additionalData
}
]const headerJson = generateJSON(headerJson)
```