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 🙏

© 2026 – Pkg Stats / Ryan Hefner

eleventy-plugin-relat11ve

v1.0.1

Published

An Eleventy (11ty) plugin to safely and automatically transform absolute paths to relative paths in HTML and CSS.

Readme

eleventy-plugin-relat11ve

npm version License: MIT

🌎 English | 🇯🇵 日本語


🌎 English

An Eleventy (11ty) plugin to safely and automatically transform absolute paths to relative paths in HTML and CSS.

Write your code comfortably using root-relative paths (/assets/...) during development, and output perfectly linked relative paths (../assets/...) for your build. Ideal for local viewing or decentralized hosting like IPFS.

✨ Features

  • Zero Dependencies: Just 11ty and this plugin. No bloated parsers.
  • CSS Support: Transforms src, href, data-* in HTML, as well as url(/...) inside <style> tags and style="" attributes.
  • Safe for Tech Blogs: Automatically ignores contents inside <pre> and <code> blocks to prevent accidental path replacement in your code snippets.
  • Manual Ignore: Explicitly protect specific blocks from transformation using HTML comments.

📦 Installation

npm install eleventy-plugin-relat11ve

🚀 Usage

Add the plugin to your .eleventy.js config.

const relat11ve = require("eleventy-plugin-relat11ve");

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

Input / Output Example

Input (Development):

<img src="/img/hero.jpg">
<style>.bg { background: url(/img/bg.png); }</style>

Output (Built as /news/detail/index.html):

<img src="../../img/hero.jpg">
<style>.bg { background: url(../../img/bg.png); }</style>

⚙️ Configuration

By default, safety protections are enabled. You can disable them if you are building a simple LP or corporate site.

module.exports = function(eleventyConfig) {
  eleventyConfig.addPlugin(relat11ve, {
    ignoreCodeBlocks: false, // Disable auto-ignore for <pre> and <code> (Default: true)
    ignoreComments: false    // Disable manual comment ignore (Default: true)
  });
};

Manual Ignore

When ignoreComments is true, wrap content in these comments to protect it from transformation. Useful for rendering raw JSON from an API.

<!-- RELATIVE_IGNORE_START -->
<pre>
{
  "user_profile": "/assets/img/avatar.png"
}
</pre>
<!-- RELATIVE_IGNORE_END -->

Working with <script> tags

For JavaScript, it is best practice to pass paths via HTML data-* attributes:

<section id="hero" data-bg-pc="/assets_2026/img/hero.png"></section>
<script>
  const paths = {
      bgPc: document.getElementById('hero').dataset.bgPc
  };
  const bgTexturePC = loader.load(paths.bgPc); // Path is safely resolved!
</script>

🇯🇵 日本語

Eleventy (11ty) でビルドされたHTMLやCSS内の絶対パス(/assets/...)を、ディレクトリ階層に応じた正しい相対パス(../assets/...)へ自動的かつ安全に変換するプラグインです。

開発時はルート相対パスで快適にコーディングしつつ、ビルド結果は「ローカルのPCで直接開いても」「IPFSなどの分散型ホスティングに上げても」絶対にリンク切れしない、最強のポータビリティを実現します。

✨ 特徴

  • 依存関係ゼロ: 11ty + このプラグインのみ。他に必須なプラグインは無いです。
  • CSSにも対応: HTMLタグの src href data-* だけでなく、<style> タグや style="" 属性内の url(/...) も正確に変換します。
  • 技術ブログ向けの安全設計: <pre><code> ブロック内のテキストは自動で変換対象から除外(退避)されるため、ソースコードが勝手に書き換わる誤爆バグが起きません。
  • 手動での保護機能: 特定のブロックを変換させたくない場合は、HTMLコメントで明示的に保護することができます。

📦 インストール

npm install eleventy-plugin-relat11ve

🚀 使い方

あなたの .eleventy.js にプラグインを追加するだけです。

const relat11ve = require("eleventy-plugin-relat11ve");

module.exports = function(eleventyConfig) {
  // 基本的な使い方(デフォルト設定)
  eleventyConfig.addPlugin(relat11ve);
};

変換の挙動

開発時のコード(Input):

<img src="/img/hero.jpg">
<style>.bg { background: url(/img/bg.png); }</style>

/news/detail/index.html としてビルドされた結果(Output):

<img src="../../img/hero.jpg">
<style>.bg { background: url(../../img/bg.png); }</style>

⚙️ オプション設定

デフォルトでは、ソースコードの誤変換を防ぐための保護機能がすべてONになっています。コーポレートサイトやLP制作など、保護機能が不要な場合はオプションでオフにすることができます。

module.exports = function(eleventyConfig) {
  eleventyConfig.addPlugin(relat11ve, {
    // <pre> と <code> ブロック内の自動保護を無効にする(デフォルト: true)
    ignoreCodeBlocks: false, 
    
    // 手動コメントによる保護機能を無効にする(デフォルト: true)
    ignoreComments: false
  });
};

手動でのパス保護(Manual Ignore)

ignoreComments: true の場合、以下のHTMLコメントで囲まれた範囲はパス変換の対象外となります。REST APIの生のJSONを画面に出力したい場合などに便利です。

<!-- RELATIVE_IGNORE_START -->
<pre>
{
  "user_profile": "/assets/img/avatar.png"
}
</pre>
<!-- RELATIVE_IGNORE_END -->

Scriptタグ内でも使う場合

下記のようにScriptタグ内で使う時は、HTMLの dataset プロパティを経由して受け取ることで安全に回避できます。

<section id="hero" data-bg-pc="/assets_2026/img/hero.png"></section>
<script>
  const paths = {
      bgPc: document.getElementById('hero').dataset.bgPc
  };
  const bgTexturePC = loader.load(paths.bgPc);
</script>

📄 License

MIT