• Stars
    star
    185
  • Rank 208,271 (Top 5 %)
  • Language Liquid
  • License
    MIT License
  • Created over 6 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 way of adding anchors to your headings without a plug-in or JavaScript :octocat:

Jekyll Pure Liquid Heading Anchors

Unit Tests Latest release ko-fi Buy me a coffee

GitHub Pages can't run custom Jekyll plug-ins so when generating anchors for your headings (i.e. h1 - h6), you're stuck with JavaScript solutions that will inject anchors. But what if your users don't have JavaScript enabled on their browsers? If you're building a static website, why not make your anchors static as well?

Sample anchor next to heading

As a part of my "Pure Liquid" series of Jekyll snippets, here is a Liquid snippet that will modify your generated HTML to inject anchors. Want to see it in action? Here are some awesome websites that I know of using this solution ❤️.

Want a Table of Contents in your Jekyll layouts without JavaScript or a plug-in?

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

Usage

Alright, so how do you use it?

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

  2. Toss that file in your _includes folder

  3. Where you typically would put {{ content }} in your layout, you would instead use this Liquid tag to output your page's content:

    {% include anchor_headings.html html=content anchorBody="#" %}

♿ Link Accessibility

Accessibility is hard and there are many different ways someone may want to handle it. For that reason, this project does not force onto developers any method of handling accessibility. That being said, this project can be configured to be accessible as seen in examples in the wiki.

⚠️ Layout Inheritance

If this snippet is used in a layout that is inherited by a child layout, it will apply to the child layout as well. If the child layout uses this snippet in addition to the parent layout, then heading anchors will be duplicated. You should only use this snippet in one layout.

🎨 Customization

You may remove anchorBody and add an icon via CSS' content property instead. You may also use HTML in anchorBody and add screen reader friendly markup.

Take a look at the unit tests directory and the wiki page for more examples of how to use this script.

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
beforeHeading bool false Set to true if the anchor should be placed before the heading's content
headerAttrs string '' Any custom HTML attributes that will be added to the heading tag; you may NOT use id; the %heading% and %html_id% placeholders are available
anchorAttrs string '' Any custom HTML attributes that will be added to the <a> tag; you may NOT use href, class or title; the %heading% and %html_id% placeholders are available
anchorBody string '' The content that will be placed inside the anchor; the %heading% placeholder is available
anchorClass string '' The class(es) that will be used for each anchor. Separate multiple classes with a space
anchorTitle string '' The title attribute that will be used for anchors; the %heading% placeholder is available
h_min int 1 The minimum header level to build an anchor for; any header lower than this value will be ignored
h_max int 6 The maximum header level to build an anchor for; any header greater than this value will be ignored
bodyPrefix string '' Anything that should be inserted inside of the heading tag before its anchor and content
bodySuffix string '' Anything that should be inserted inside of the heading tag after its anchor and content
generateId bool false Set to true if a header without id should generate an id to use.

* This is a required parameter

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.travis-ci.com from ~Aug 2018
_includes/anchor_headings.html                   |   193 | 1667.96K | 0.695

License

This snippet may be redistributed under the MIT license.

More Repositories

1

jekyll-toc

A GitHub Pages compatible Table of Contents generator without a plugin or JavaScript :octocat:
Liquid
496
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