Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generate TOC in side-bar #344

Open
SoumayaMauthoorMOJ opened this issue Oct 7, 2024 · 1 comment
Open

Generate TOC in side-bar #344

SoumayaMauthoorMOJ opened this issue Oct 7, 2024 · 1 comment
Labels
question Further information is requested

Comments

@SoumayaMauthoorMOJ
Copy link

Hello

I know that you can generate toc inline using [[toc]]

Is it possible to generate a toc in the side bar?

For example modify the front matter in https://github.com/x-govuk/govuk-eleventy-plugin/blob/main/docs/example-layouts/post.md?plain=1 with something like:

eleventyComputed:
  aside:
    toc
@paulrobertlloyd paulrobertlloyd added the question Further information is requested label Dec 27, 2024
@paulrobertlloyd
Copy link
Collaborator

paulrobertlloyd commented Dec 27, 2024

Sorry for taking so long to respond. There’s not an easy answer unfortunately, but I can suggest some alternatives.

It’s not possible to generate an automated table of contents in the aside block, and any usage of the [[toc]] syntax in the content area would only relate to it’s own block of Markdown.

So, while this wouldn’t work:

---
layout: post
title: Getting started
aside:
  title: Contents
  content: |
    [[toc]]
---

## Requirements

There are some

## Installation

Is easy

## Usage

Is up to you

if you weren’t expecting the headings in your document to change frequently, you could do the following:

---
layout: post
title: Getting started
aside:
  title: Contents
  content: |
    - [Requirements](#requirements)
    - [Installation](#installation)
    - [Usage](#usage)
---

## Requirements

There are some

## Installation

Is easy

## Usage

Is up to you

Alternatively, you could use [[toc]] in your main content, and then use custom CSS to position it on the page.

Both approaches are a bit of a hack, granted. It would be cool to be able to show contents in the sidebar, although most GOV.UK services show a table of contents at the top of the page. That, and if you wanted side navigation, content and a sidebar, space would get a bit tight.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants