Skip to content

Commit 6f3423e

Browse files
move ToC headings section to markdown plugin
1 parent 34b8c4e commit 6f3423e

2 files changed

Lines changed: 61 additions & 61 deletions

File tree

src/pages/docs/content-as-data/pages-data.md

Lines changed: 0 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -54,66 +54,6 @@ This is the data you would get back:
5454
}
5555
```
5656

57-
## Table of Contents
58-
59-
Additionally for markdown pages, you can add a frontmatter property called `tocHeading` that will read all the HTML heading tags that match that number, and provide that as a subset of the data object. This is most useful for generating the table of contents for a page.
60-
61-
Taking our previous example, if we were to configure this for `<h2>` tags:
62-
63-
<!-- prettier-ignore-start -->
64-
65-
<app-ctc-block variant="snippet" heading="src/pages/blog/first-post.md">
66-
67-
```md
68-
---
69-
author: Project Evergreen
70-
published: 2024-01-01
71-
tocHeading: 2
72-
---
73-
74-
# First Post
75-
76-
This is my first post.
77-
78-
## Overview
79-
80-
Lorum Ipsum
81-
82-
## First Point
83-
84-
Something something...
85-
```
86-
87-
</app-ctc-block>
88-
89-
<!-- prettier-ignore-end -->
90-
91-
We would get this additional content as data out:
92-
93-
```json
94-
{
95-
"id": "blog-first-post",
96-
"title": "First Post",
97-
"label": "First Post",
98-
"route": "/blog/first-post/",
99-
"data": {
100-
"author": "Project Evergreen",
101-
"published": "2024-01-01",
102-
"tocHeading": 2,
103-
"tableOfContents": [
104-
{
105-
"content": "Overview",
106-
"slug": "overview"
107-
},
108-
{
109-
"content": "First Point",
110-
"slug": "first-point"
111-
}
112-
]
113-
}
114-
}
115-
```
116-
11757
## External Content
11858

11959
Using our [Source plugin](/docs/reference/plugins-api/#source), just as you can get your content as data _out_ of Greenwood, so can you provide your own sources of content (as data) _to_ Greenwood. This is great for pulling content from a headless CMS, database, or anything else you can imagine!

src/pages/docs/plugins/markdown.md

Lines changed: 61 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ tocHeading: 2
66

77
# Markdown
88

9-
For authoring in markdown, Greenwood provides a plugin that you can install, which by default supports the [CommonMark](https://commonmark.org/help/) specification and uses [**unifiedjs**](https://unifiedjs.com/) as the markdown / content framework. See the [plugin's README](https://github.com/ProjectEvergreen/greenwood/tree/master/packages/plugin-markdown) for additional information, like standalone usage.
9+
For authoring in markdown, Greenwood provides a plugin that you can install which by default supports the [CommonMark](https://commonmark.org/help/) specification and uses [**unifiedjs**](https://unifiedjs.com/) as the markdown / content framework. See the [plugin's README](https://github.com/ProjectEvergreen/greenwood/tree/master/packages/plugin-markdown) for additional information, like standalone usage.
1010

1111
## Installation
1212

@@ -351,6 +351,66 @@ You can also define any custom frontmatter property you want and that will be ma
351351

352352
<!-- prettier-ignore-end -->
353353

354+
## Table of Contents
355+
356+
You can add a frontmatter property called `tocHeading` that will read all the HTML heading tags that match that number in your markdown, and provide that as a subset of the data object in your [pages data schema](/docs/content-as-data/pages-data/#schema). This is most useful for generating the table of contents for a page.
357+
358+
For example:
359+
360+
<!-- prettier-ignore-start -->
361+
362+
<app-ctc-block variant="snippet" heading="src/pages/blog/first-post.md">
363+
364+
```md
365+
---
366+
author: Project Evergreen
367+
published: 2024-01-01
368+
tocHeading: 2
369+
---
370+
371+
# First Post
372+
373+
This is my first post.
374+
375+
## Overview
376+
377+
Lorum Ipsum
378+
379+
## First Point
380+
381+
Something something...
382+
```
383+
384+
</app-ctc-block>
385+
386+
<!-- prettier-ignore-end -->
387+
388+
We would get this additional content as data:
389+
390+
```json
391+
{
392+
"id": "blog-first-post",
393+
"title": "First Post",
394+
"label": "First Post",
395+
"route": "/blog/first-post/",
396+
"data": {
397+
"author": "Project Evergreen",
398+
"published": "2024-01-01",
399+
"tocHeading": 2,
400+
"tableOfContents": [
401+
{
402+
"content": "Overview",
403+
"slug": "overview"
404+
},
405+
{
406+
"content": "First Point",
407+
"slug": "first-point"
408+
}
409+
]
410+
}
411+
}
412+
```
413+
354414
## Active Frontmatter
355415

356416
With [`activeContent`](/docs/reference/configuration/#active-content) enabled, any of these properties would be available in your HTML or markdown through Greenwood's [content as data features](/docs/content-as-data/).

0 commit comments

Comments
 (0)