npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

eleventy-plugin-urlify

v0.1.1

Published

Filters and maybe transforms to handle URLs.

Downloads

10

Readme

eleventy-plugin-urlify

An eleventy plugin for URL filters. Yes, there are already some… I know. This one is a bit different, trust me (or don't--as you like).

Ok, here is the pitch: The basic | url filter in eleventy doesn't compile an actual URL. It compiles an absolute path. The new htmlBaseUrl plugin transforms -- well -- everything without much control.

urlify is different: You can use the generic urlify tag on every URL. Absolute URLs are just passed through. And then you configure in the projects settings file what output you need. Make all URLs absolute (actually absolute), make them root-relative with eleventys pathPrefix or make the relative to that prefix -- whatever you want. Aaaand █ ███ ███ █████████ ████ ██ ██████ █ ███ ██ ███ ██████ ███ █████████ █████ ████ ████ █ ██████ ████████ ███ █████████ █████ ████ ████ █ ██████ ████████ (I didn't implement that yet).

Well, and what if you want to just have that one URL always be root-relative no matter what the other URLs are? Give it the rootRelativePath filter -- easy. You could also use the absoluteURL or relativePath (relative-to-the-pathPrefix filter but that was pretty long) filter. And as a goodie, I added the isAbsoluteURL and isRootRelative filters.

Installation

  • Tested with eleventy 2.0.0 but should work with 1.0, too (I guess)
  • Oh and I only used it with nunjucks. But it's just function and the default context.
npm install --save-dev eleventy-plugin-urlify

Then open your Eleventy config file (probably .eleventy.js) and use addPlugin:

const urlifyPlugin = require("eleventy-plugin-urlify");

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

You’re only allowed one module.exports in your configuration file, so make sure you only copy the require and the addPlugin lines above!

Options

There are a number of options to customize the tag and how the components are loaded. To get an overview here are all the settings at once:

const urlifyPlugin = require("eleventy-plugin-urlify");

module.exports = function(eleventyConfig) {
    eleventyConfig.addPlugin(urlifyPlugin, {
      // This is the path prefix. The default is eleventies pathPrefix but if
      // you must (don't) you could override it here for this plugin only.
      pathPrefix: "/",

      // This is the base URL to build absolute URLs. It should only be the
      // protocol and domain. No slash--use the pathprefix for that.
      baseURL: "http://example.com",

      // Sets the mode for the urlify filter 
      // Modes:
      // 	- **root-relative** make URLs relative to the site root.
      //	- **prefix-relative** make URLs relative to the pathPrefix
      //  - **absolute** make URLs absolute
      urlifyMode: "root-relative",

      // Here you could rename the filters if something would clash with filters
      // you already have installed (don't like the name urlify? 
      // Change it if you must).
      filterMapping: {
        // <filterName>: <functionName>"
        isAbsoluteURL: "isAbsoluteURL",
        isRootRelative: "isRootRelative",
        rootRelativePath: "rootRelativePath",
        relativePath: "prefixRelativePath",
        absoluteURL: "absoluteURL",
        urlify: "urlify"
      }

    });
};

Examples

The absoluteURL filter

The rootRelativePath filter

The relativePathfilter

The urlifyfilter

The isAbsolutePath filter

The isRootRelativePath filter