• Stars
    star
    496
  • Rank 88,807 (Top 2 %)
  • Language Liquid
  • Created over 7 years ago
  • Updated 11 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A GitHub Pages compatible Table of Contents generator without a plugin or JavaScript :octocat:

Jekyll Pure Liquid Table of Contents

Unit Tests Latest release ko-fi Buy me a coffee

GitHub Pages can't run custom Jekyll plug-ins so when generating Tables of Contents (TOCs), you're stuck with either a JavaScript solution or using kramdown's {:toc} option. However, by using {:toc}, you are forced to have that code next to your actual markdown and you can't place it in a layout. This means every. single. post. will need to have the snippet. If you choose the JavaScript approach, that's perfectly fine but what if JS is disabled on someone's browser or your page is just really long and it becomes inefficient.

Instead, I wrote this solution entirely in Liquid and can be used as an {% include %} in any website you want, in any layout you want. Want to see it in action? Here are some awesome websites that I know of using this solution ❤️.

For more information regarding how this include works, read the blog post.

Want anchors next to your Jekyll headings without JavaScript or a plug-in?

Check out the sister project over at allejo/jekyll-anchor-headings.

Usage

Alright, so how do you use it?

  1. Download the toc.html file from the latest release or the master branch

  2. Toss that file in your _includes folder.

  3. Use it in your template layout where you have {{ content }} which is the HTML rendered from the markdown source with this liquid tag:

    {% include toc.html html=content %}

Parameters

This snippet is highly customizable. Here are the available parameters to change the behavior of the snippet.

Parameter Type Default Description
html string * the HTML of compiled markdown generated by kramdown in Jekyll
sanitize bool false when set to true, the headers will be stripped of any HTML in the TOC
class string '' a CSS class assigned to the TOC; concat multiple classes with '.'
id string '' an ID to be assigned to the TOC
h_min int 1 the minimum TOC header level to use; any heading lower than this value will be ignored
h_max int 6 the maximum TOC header level to use; any heading greater than this value will be ignored
ordered bool false when set to true, an ordered list will be outputted instead of an unordered list
item_class string '' add custom class for each list item; has support for %level% placeholder, which is the current heading level
submenu_class string '' add custom class(es) for each child group of headings; has support for %level% placeholder which is the current "submenu" heading level
base_url string '' add a base url to the TOC links for when your TOC is on another page than the actual content
anchor_class string '' add custom class(es) for each anchor element
skip_no_ids bool false skip headers that do not have an id attribute

* This is a required parameter

Deprecated Variables

  • baseurl has been deprecated since 1.1.0, use base_url instead
  • skipNoIDs has been deprecated since 1.1.0, use skip_no_ids instead

Performance

The performance impact of this snippet on your site is pretty negligible. The stats below were gotten from Jekyll's --profile option.

Filename                              | Count |      Bytes |    Time
--------------------------------------+-------+------------+--------

# performance on docs.docker.com from ~Feb 2017
_includes/toc.html                    |   813 |    524.17K |  6.422

# performance on the "Minimal Mistakes" Jekyll theme
_includes/toc.html                    |    94 |     29.43K |  0.413

License

This snippet may be redistributed under either the BSD-3 or MIT licenses.

More Repositories

1

jekyll-anchor-headings

A GitHub Pages compatible way of adding anchors to your headings without a plug-in or JavaScript :octocat:
Liquid
185
star
2

jekyll-docs-theme

A mediocre Jekyll theme for writing documentation websites based Bootstrap's old website design
SCSS
101
star
3

bzion

A League Management System designed for BZFlag leagues and tournaments.
PHP
20
star
4

PhpSoda

A Socrata Open Data API (SODA) client library for PHP
PHP
17
star
5

php-vcr-sanitizer

Bring privacy to php-vcr and erase any sensitive information. Gone are the days for hoping no one steals your API keys.
PHP
15
star
6

WebBZEdit

🚧 🧪 A web-based editor for BZFlag world files under very heavy construction
TypeScript
11
star
7

PhpPulse

A monday.com (formerly DaPulse) API v1 wrapper in PHP
PHP
10
star
8

json-reshaper

An online utility that lets you reshape your JSON into CSV files with using jq-like queries
TypeScript
8
star
9

LeagueOverseer

A BZFlag plug-in to relay information from BZFlag servers to a website, such as player info or match reports
C++
5
star
10

bzflag-rendering.php

A library for rendering thumbnails of BZFlag worlds
PHP
5
star
11

gha-workflows

A super simple script to manage building Workflows for GitHub Actions
JavaScript
5
star
12

bzflagPluginStarter3

A React website to generate the skeleton for a BZFlag 2.4 compatible plug-in
TypeScript
4
star
13

bzflagPluginStarter2

A Vue.js website to generate the skeleton for a BZFlag 2.4 compatible plug-in
Vue
4
star
14

supybot-notification-action

An Action for GitHub Actions to push messages to a Supybot instance on IRC
TypeScript
4
star
15

roconut

A Symfony based pastebin website for BZFlag /savemsgs log files
PHP
3
star
16

bzelectron

A quick BZFlag group perms compiler
Python
3
star
17

VPNBlocker

A BZFlag plug-in used to query VPN detection services to auto-kick players on VPNs
C++
2
star
18

techtonica-react-router-auth0-template

A template for Techtonica participants who need a functional react-router and auth0 template to work off of
JavaScript
2
star
19

Rosetta-PhpScript

A blasphemous AST converter from JS to PHP that should never be used in production
PHP
2
star
20

allejo

2
star
21

dotfiles

Please don't steal my API keys
Shell
2
star
22

react-position-sticky

Trigger a React component callback when a `position: sticky` element gets stuck/unstuck.
TypeScript
2
star
23

Intro-To-Web

CSS
2
star
24

responsive-viewer-29

Ruby
1
star
25

pure-liquid-utils

Python
1
star
26

relativeBZDBValues

A BZFlag plugin to change BZDB settings based on the amount of non-observer players
C++
1
star
27

bzfPluginGen

The core logic for generating a BZFlag C++ plug-in source from JSON
TypeScript
1
star
28

ctfOverseer

A BZFlag plug-in to oversee the fairness and features of CTF
C++
1
star
29

rrlog

A PHP command-line tool for translating BZFlag replays to JSON or other formats
PHP
1
star
30

react-sticky-playground

Created with CodeSandbox
JavaScript
1
star
31

neutralZones

A BZFlag plug-in to disallow specified flags from certain areas on a map
C++
1
star
32

.github

Centralized .github folder for all of my personal repositories
1
star
33

bzflag-plugin-manager

A command-line utility for managing plugins in your local BZFlag build system
TypeScript
1
star
34

aws-parameter-store-to-object

A simple function to pull values from AWS Parameter Store and make them accessible as an object
TypeScript
1
star
35

BZFSBigBrother

PHP
1
star
36

postgame

A Symfony 4 application to summarize BZFlag replay files and perform analysis on them
PHP
1
star
37

jekyll-yamlify

🚧 A GitHub Pages compatible way of introducing pretty printing YAML in your Jekyll site
Liquid
1
star
38

bzflagPluginTemplate

A template for creating BZFlag plugin folders ready for distribution via git
Shell
1
star
39

dev-null

My junk repository just to keep things safe & to test github features
JavaScript
1
star
40

jekyll-pure-liquid-template

A template repository for my Pure Liquid Jekyll snippets
Ruby
1
star
41

pure-liquid.allejo.org

A website to showcase my Liquid-only projects (possibly made under the influence of something)
HTML
1
star
42

lastTankStanding

A BZFlag game mode where the last tank standing wins the match
C++
1
star
43

setup-dasel

Similar to jq, dasel is a CLI tool to handle more like YAML, TOML, CSV, etc. This action downloads and installs dasel in your workflow.
1
star
44

ScoreRestorer

A BZFlag plug-in that restores a player's score whenever they rejoin within a set amount of time.
C++
1
star
45

AllHandsOnDeck

A BZFlag plug-in that implements the All Hands On Deck game mode
C++
1
star
46

beatrice

A highly experimental tool to automate generating "since" annotations for your PHP libraries
TypeScript
1
star
47

matchTrainerAssistant

A BZFlag plug-in that adds commands to help players train on league servers
C++
1
star
48

bzflag-networking.php

A PHP library for reading and unpacking BZFlag network packets
PHP
1
star
49

nami

A basic Socrata dataset visualizer built with React; my final project for my WebGIS class
JavaScript
1
star
50

allejo.io

The stakx source for my personal website
Twig
1
star
51

aclovis

A Typescript library for programmatically generating C++ code
TypeScript
1
star
52

advent-of-code

My mediocre solutions to Advent of Code
PHP
1
star
53

autoTeamBalance

A BZFlag plugin that will switch players to another team during gameplay without the need for a respawn or rejoin. Also allows for auto team balancing.
C++
1
star
54

bztoolkit

An external BZFlag plug-in API that consists of functions that are not in the official API.
C++
1
star
55

UselessMine

A BZFlag plug-in that allows players to place mines by grabbing the Useless flag
C++
1
star
56

eyeglass-sassy-data

Read JSON and YAML into Sass maps
CSS
1
star
57

simple-livereload-server

A stupid simple Express web server that auto injects livereload
JavaScript
1
star
58

repo-readme

A WordPress plugin which will access the README file of a repository and parse the markdown into HTML to be included in any page
PHP
1
star
59

bzdbLock

A BZFlag plug-in that allows server owners to lock BZDB variables from being changed by admins
C++
1
star