Code Monkey home page Code Monkey logo

eleventy-plugin-page-assets's Introduction

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:

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

eleventy-plugin-page-assets's People

Contributors

maxboeck avatar victornpb avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.