57 lines
1.6 KiB
Markdown
57 lines
1.6 KiB
Markdown
|
---
|
||
|
title: "TOC Disable Example"
|
||
|
description: "Example showing how to disable the table of contents in markdown files"
|
||
|
date: 2025-01-27
|
||
|
draft: false
|
||
|
categories: ['examples']
|
||
|
tags: ['toc', 'markdown', 'hugo']
|
||
|
disableToc: true # This disables the table of contents for this page
|
||
|
---
|
||
|
|
||
|
{{< lead >}}
|
||
|
This page demonstrates how to disable the table of contents in markdown files.
|
||
|
{{< /lead >}}
|
||
|
|
||
|
## How to Disable TOC
|
||
|
|
||
|
To disable the table of contents in any markdown file (including `index.md` files), simply add the `disableToc: true` parameter to the front matter:
|
||
|
|
||
|
```yaml
|
||
|
---
|
||
|
title: "Your Page Title"
|
||
|
description: "Your page description"
|
||
|
disableToc: true # This disables the TOC
|
||
|
---
|
||
|
```
|
||
|
|
||
|
## Usage Examples
|
||
|
|
||
|
### For Individual Pages
|
||
|
Add `disableToc: true` to the front matter of any markdown file to disable the TOC for that specific page.
|
||
|
|
||
|
### For Index Pages
|
||
|
For `index.md` files that serve as list pages, you can also use the `cascade` parameter to apply the setting to all pages in that section:
|
||
|
|
||
|
```yaml
|
||
|
---
|
||
|
title: "Section Title"
|
||
|
cascade:
|
||
|
disableToc: true # Disables TOC for all pages in this section
|
||
|
---
|
||
|
```
|
||
|
|
||
|
## How It Works
|
||
|
|
||
|
When `disableToc: true` is set:
|
||
|
|
||
|
1. The table of contents will not be displayed on the page
|
||
|
2. The TOC JavaScript will not be loaded (improving performance)
|
||
|
3. The TOC highlighting functionality will be disabled
|
||
|
|
||
|
## Note
|
||
|
|
||
|
This feature works for both:
|
||
|
- Individual article pages (using the `single.html` template)
|
||
|
- List/index pages (using the `list.html` template)
|
||
|
|
||
|
The TOC will still be generated by Hugo, but it won't be displayed or have JavaScript functionality when disabled.
|