Socket
Socket
Sign inDemoInstall

@borisschapira/eleventy-plugin-better-slug

Package Overview
Dependencies
3
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @borisschapira/eleventy-plugin-better-slug

A plugin to improve Eleventy slug filter


Version published
Weekly downloads
4
increased by300%
Maintainers
1
Created
Weekly downloads
 

Readme

Source

A Better Slug Filter for Eleventy (plugin)

In Eleventy v0.8.3, the slug filter don't remove reserved characters for URL and HTML ids. This plugin aims at fixing that, replacing the standard slug filter by a new one.

Use Cases

Uses the enhanced slug filter to convert a string into a URL slug. Can be used in pagination or permalinks.

Removed characters: .~\:,;/?=#[]{}()@!'*+

Examples:

  • John's car => johns-car
  • 10 O'Clock Live => 10-oclock-live
  • E! => e
  • Me, Myself & I => me-myself-and-i

Installation

Add the plugin to your project with:

npm add @borisschapira/eleventy-plugin-better-slug --save

Then, in you .eleventy.js file:

// At the begining of the file
const pluginBetterSlug = require("@borisschapira/eleventy-plugin-better-slug");
…

module.exports = function(eleventyConfig) {
  …
  eleventyConfig.addPlugin(pluginBetterSlug);
  …
}

Configuration

By design, this `slug' filter deletes all reserved characters but you can use a custom configuration to modify the characters to be deleted and even replace some characters.

const pluginBetterSlug = require("@borisschapira/eleventy-plugin-better-slug");
…

module.exports = function(eleventyConfig) {
  …
  const options = {
    extensions: {
      "'": "-"
    }
  }
  eleventyConfig.addPlugin(pluginBetterSlug, {});
  …
}

The options object is defined as follows:

  • removals (optional): a string containing the characters to remove (any value overwrites the default value)
  • extensions (optional): a charset of all the characters replacements (any new key-value pair is added to the default library)

Keywords

FAQs

Last updated on 17 Jun 2019

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc