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-page-assets

v0.3.0

Published

Copy local page assets to permalink folder

Downloads

155

Readme

eleventy-plugin-page-assets

Copy local page assets to permalink folder

Instalation

Available on npm

npm install eleventy-plugin-page-assets --save-dev

Open up your Eleventy config file (probably .eleventy.js) and use addPlugin:

FILENAME .eleventy.js

const pageAssetsPlugin = require('eleventy-plugin-page-assets');

module.exports = function(eleventyConfig) {
    eleventyConfig.addPlugin(pageAssetsPlugin, {
        mode: "parse",
        postsMatching: "src/posts/*/*.md",
    });
};

How it works

This folder structure

📁 src/posts/
  📁 some-title/
    📄 index.md <-- when a template file is processed
    🖼 cover.png    assets relative to it are automatically
    🖼 image.jpg    copied to the permalink folder
  📁 good-title/
    📄 index.md 
    🖼 cover.png
  📁 bar-title/
    📄 index.md
    📁 icons/ 
      🖼 icon.png
  📄 my-post.md
  🖼 img.png

Will generate this output

📁 dist/
  📁 perma-some-title/
    📄 index.html 
    🖼 89509eae15a24c2276d54d4b7b28194a1391ee48.png 
    🖼 63d8ddb9ffadd92e3d9a95f0e49ae76e7201a672.jpg 
  📁 perma-good-title/
    📄 index.html 
    🖼 d0017352f4da463a61a83a1bc8baf539a4c921c1.png
  📁 perma-bar-title/
    📄 index.md
    🖼 faa22a543b2dcb21fdd9b7795095e364ef00d540.png
  📁 perma-my-post/
    📄 index.md
    🖼 faa22a543b2dcb21fdd9b7795095e364ef00d540.png

Directory mode

On directory mode the template is not parsed, assets on the same level as template are copied to the permalink folder, even if not used.

Note: Paths are not rewritten and folder structure is kept inside the perma folder.

This mode is cheaper as it does not parses the html or transforms it.

Options

| Option | Required | Type | Default | Description | |-----------------------|----------|---------|-----------------------|--------------------------------------------------------------------------------------------------------------------------------------------------| | mode | false | string | parse | Parse mode will resolve assets referenced inside the template. Directory mode blindly copies files on the folder as the template. | | postsMatching | false | string | ".md" | Pattern (glob) filtering which templates to process | | assetsMatching | false | string | ".png|.jpg|.gif" | Specify a pattern (glob) that matches which assets are going to be resolved | | recursive | false | boolean | false | Recursively scan assets under subdirectories (example src/posts/foo/bar/baz/img.jpg) (directory mode only) | | hashAssets | false | boolean | true | Rewrite filenames to hashes. This will flatten the paths to always be next to the post .html file. (parse mode only) | | hashingAlg | false | string | sha1 | Hashing algorithm sha1|md5|sha256|sha512 https://nodejs.org/api/crypto.html#crypto_crypto_createhash_algorithm_optionsetc (parse mode only) | | hashingDigest | false | string | hex | Digest of the hash hex|base64 (parse mode only) | | addIntegrityAttribute | false | boolean | false | Add a integrity attribute to the tag (parse mode only) | | | | | | |


TO-DO:

  • [x] Parse the rendered html files looking for assets, and only used imported assets (similat to how what webpack loaders work)
  • [x] Rewrite paths on the output files, possibly renaming files to md5 hashes, so images also have permalinks.
  • [ ] Write tests