Skip to content

mikinho/active-links

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

@mikinho/active-links

Copyright (c) 2025 Michael Welter me@mikinho.com

NPM Version GitHub Release File Size License

A lightweight, high-performance script that automatically adds is-active and is-ancestor classes to your navigation links.

Features

  • Fast: Uses document.links, cached loops, and skips non-HTTP protocols.
  • Smart: Handles query strings (?a=1&b=2 == ?b=2&a=1) and normalizes trailing slashes.
  • Zero Dependencies: Drop it in and it works.

Installation & Usage

Option 1: CDN (Easiest)

Place this at the end of your <body> tag:

jsdelivr

<script src="https://cdn.jsdelivr.net/gh/mikinho/active-links@latest/dist/active-links.min.js" defer></script>

unpkg

<script src="https://unpkg.com/@mikinho/active-links@latest/dist/active-links.min.js" defer></script>

Option 2: NPM

npm install @mikinho/active-links

Usage with Fastify

const path = require("node:path");
const fastify = require("fastify")();

fastify.register(require("@fastify/static"), {
    root: path.join(__dirname, "node_modules/@mikinho/active-links/dist"),
    prefix: "/s/js/",
    decorateReply: false
});

Usage with Express

const express = require("express");
const app = express();
const path = require("path");

app.use("/s/js", express.static(path.join(__dirname, "node_modules/@mikinho/active-links/dist")));

Publishing

git commit -sam "Blah blah blah"
npm version patch
git push --tags