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

Feature: Table of contents in blog articles #76

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

mharrend
Copy link
Contributor

One can activate a table of contents for blog articles if the word count gets larger than a specified parameter.

New parameters in config.toml:

  • tocIfNecessary = true
  • tocWordCount = 500 # Min. number of words in article after which toc gets generated

Additionally, one can deactivate the toc for single blog articles by adding tocActivated = false to the article config

Description

  • Added toc.html file containing functionality to partials
  • Updated content-single.html file to include toc functionality
  • Added two parameters to config.toml file of exampleSite

Motivation and Context

The code is based on the toc partial example from the Hugo documentation: https://gohugo.io/content-management/toc/

The change allows an user to automatically add a table of contents to a blog article if the article is longer than a defined word count and the corresponding tocIfNecessary option is switched on.
In addition a user can deactivate the toc generation for specific blog articles by adding a tocActivated = false setting.

How Has This Been Tested?

Tested on my own setup:

  • Tested with hugo server locally
  • Tested via a deployment to Gitlab pages with subdomain.

Hugo Version: 0.30.2

Browser(s): Firefox, Chromium, Chrome

Screenshots (if appropriate):

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

One can activate a table of contents for blog articles if the word count gets larger than a specified parameter.

Parameters in config.toml:
tocIfNecessary = true
  # Min. number of words in article after which toc gets generated
  tocWordCount = 500
Additionally, one can deactivate the toc for single blog articles by adding tocActivated = false to the article config
Copy link
Collaborator

@pacollins pacollins left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the idea, but there are a couple things:

  1. It needs to be styled to fit the theme a little better.
  2. For some reason it renders as aside nav ul li ul li, which is giving the first item an extra bullet point.
  3. The anchor links puts the heading behind the navbar. We need to figure out a way to fix this because it gives a disjunctive UX.
  4. It also probably needs a heading on it such as Table of Contents otherwise its odd.

@pacollins
Copy link
Collaborator

Sorry for the delay, its finals week so I have been/will be super busy. Plan to address all PRs next Saturday.

Are you still planning to make these adjustments?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants