### Install the plugin via npm Source: https://github.com/11ty/docs/blob/main/src/docs/plugins/syntaxhighlight.md Install the @11ty/eleventy-plugin-syntaxhighlight package from npm. ```bash npm install @11ty/eleventy-plugin-syntaxhighlight ``` -------------------------------- ### Install @11ty/eleventy-server-browsersync Source: https://github.com/11ty/docs/blob/main/src/docs/dev-server.md Install the Browsersync server package for Eleventy. ```bash npm install @11ty/eleventy-server-browsersync ``` -------------------------------- ### Install eleventy-navigation with npm Source: https://github.com/11ty/docs/blob/main/src/docs/plugins/navigation.md Install the plugin package from npm. Run this command in your project directory. ```bash npm install @11ty/eleventy-navigation ``` -------------------------------- ### Run Eleventy locally Source: https://github.com/11ty/docs/blob/main/README.md Install dependencies, fetch new data, and start the Eleventy dev server. The server defaults to port 8080 but will use another port if 8080 is taken. ```bash npm install npm run get-new-data npx @11ty/eleventy --serve ``` -------------------------------- ### Install Upgrade Helper for v3 Source: https://github.com/11ty/docs/blob/main/src/docs/plugins/upgrade-help.md Install the helper plugin version matching Eleventy v3. ```bash npm install @11ty/eleventy-upgrade-help@3 ``` -------------------------------- ### Install Eleventy 1.0 Beta via npm Source: https://github.com/11ty/docs/blob/main/src/blog/2021-10-06-eleventy-v1-beta.md Install the latest Eleventy 1.0 beta locally or globally using npm. The local install is recommended for project-specific dependencies, while the global install makes the CLI available system-wide. ```bash # Local project npm install @11ty/eleventy@beta # Global install npm install @11ty/eleventy@beta -g ``` -------------------------------- ### Install Upgrade Helper for v1 Source: https://github.com/11ty/docs/blob/main/src/docs/plugins/upgrade-help.md Install the helper plugin version matching Eleventy v1. ```bash npm install @11ty/eleventy-upgrade-help@1 ``` -------------------------------- ### Install Upgrade Helper for v2 Source: https://github.com/11ty/docs/blob/main/src/docs/plugins/upgrade-help.md Install the helper plugin version matching Eleventy v2. ```bash npm install @11ty/eleventy-upgrade-help@2 ``` -------------------------------- ### Install Eleventy globally with npm Source: https://github.com/11ty/docs/blob/main/src/docs/global-installation.md Run this command to install Eleventy globally. It adds an 'eleventy' command usable in any directory. Not recommended; prefer package.json installation. ```bash npm install -g @11ty/eleventy ``` -------------------------------- ### Install Eleventy v2.0 beta locally Source: https://github.com/11ty/docs/blob/main/src/blog/2023-01-18-eleventy-v2-beta.md Install the beta version of Eleventy in a local project using npm. This command installs the latest beta release from the @beta tag. ```sh npm install @11ty/eleventy@beta ``` -------------------------------- ### Install the plugin via npm Source: https://github.com/11ty/docs/blob/main/src/docs/plugins/inclusive-language.md Install the plugin package from npm. ```bash npm install @11ty/eleventy-plugin-inclusive-language ``` -------------------------------- ### Install Eleventy v2.0.0 locally and globally Source: https://github.com/11ty/docs/blob/main/src/blog/2023-02-08-eleventy-v2.md Use npm to install the latest Eleventy version. The first command installs locally in a project, the second installs globally with the -g flag. ```sh # Local project npm install @11ty/eleventy@latest ``` ```sh # Global install npm install @11ty/eleventy@latest -g ``` -------------------------------- ### Install eleventy-plugin-directory-output Source: https://github.com/11ty/docs/blob/main/src/docs/plugins/directory-output.md Install the plugin via npm. Compatible with Eleventy 1.0.0 and newer. ```bash npm install @11ty/eleventy-plugin-directory-output npm install @11ty/eleventy-plugin-directory-output ``` -------------------------------- ### Default Collection Sorting Example Source: https://github.com/11ty/docs/blob/main/src/docs/collections.md An example of how files are ordered based on creation date and path. ```text posts/postA.md (created on 2008-01-01) posts/postB.md (created on 2008-01-01) posts/post3.md (created on 2007-01-01) another-posts/post1.md (created on 2011-01-01) ``` -------------------------------- ### GraphQL example Source: https://github.com/11ty/docs/blob/main/src/docs/data-js.md A 'Hello World' GraphQL example that works out of the box with Eleventy. Uses the `graphql` and `buildSchema` from the 'graphql' package. ```javascript import { graphql, buildSchema } from "graphql"; // this could also be `async function` export default function () { // if you want to `await` for other things here, use `async function` var schema = buildSchema(`type Query { hello: String }`); var root = { hello: () => "Hello world async!", }; return graphql(schema, "{ hello }", root); }; ``` -------------------------------- ### Use TOML in Front Matter (sample.md) Source: https://github.com/11ty/docs/blob/main/src/docs/data-frontmatter-customize.md After configuring the TOML engine (see the .eleventy.js snippet), you can use TOML syntax in front matter as shown. The example includes the front matter delimiters and a starting HTML template. ```markdown ---toml title = "My page title using TOML" --- … ``` -------------------------------- ### Sample site JSON with business_url Source: https://github.com/11ty/docs/blob/main/src/blog/2021-02-26-espbn.md A minimal valid example showing the required business_url property alongside existing site fields. ```json { "url": "https://www.zachleat.com/", "name": "Zach Leatherman", "twitter": "zachleat", "business_url": "https://www.zachleat.com/hire-me/" } ``` -------------------------------- ### Install @11ty/eleventy-plugin-pug Source: https://github.com/11ty/docs/blob/main/src/docs/languages/pug.md Install the Pug plugin for Eleventy v3 and newer, as Pug was moved out of core. ```bash npm install @11ty/eleventy-plugin-pug ``` -------------------------------- ### Install Eleventy Vite plugin with npm Source: https://github.com/11ty/docs/blob/main/src/docs/server-vite.md Install the plugin using npm. Run this command in your project root. ```bash npm install @11ty/eleventy-plugin-vite ``` -------------------------------- ### Example layout file _includes/my-layout.webc Source: https://github.com/11ty/docs/blob/main/src/docs/languages/webc.md This is the referenced layout file for the front matter example. It uses the @raw attribute to output the page content. The file should be placed in _includes/ as an Eleventy layout. ```html WebC Example ``` -------------------------------- ### Sample MDX file with front matter and component Source: https://github.com/11ty/docs/blob/main/src/docs/languages/mdx.md Example .mdx file demonstrating front matter and a custom React component. Renders as

Hello, World!!!

. ```jsx --- key: World --- export function Exclaim(props) { return <>{props.target}!!! } # Hello from ``` -------------------------------- ### Install @11ty/eleventy-plugin-handlebars Source: https://github.com/11ty/docs/blob/main/src/docs/languages/handlebars.md Install the Handlebars plugin package via npm. ```bash npm install @11ty/eleventy-plugin-handlebars ``` -------------------------------- ### Install @11ty/eleventy-img with npm Source: https://github.com/11ty/docs/blob/main/src/docs/plugins/image.md Run this npm command to install the Eleventy Image plugin. Version 7.0.0 requires Node 22+ and ESM support. ```bash npm install @11ty/eleventy-img ``` -------------------------------- ### Install Eleventy v3.0 canary with npm Source: https://github.com/11ty/docs/blob/main/src/blog/2023-12-17-canary-eleventy-v3.md Use this command to install the latest canary release of Eleventy v3.0. The --save-exact flag ensures you get the exact version (e.g., 3.0.0-alpha.2) rather than a caret range. ```sh npm install @11ty/eleventy@canary --save-exact ``` -------------------------------- ### Install eleventy-fetch Source: https://github.com/11ty/docs/blob/main/src/docs/quicktips/cache-api-requests.md Install the @11ty/eleventy-fetch package via npm to enable caching of API requests in your Eleventy project. ```bash npm install @11ty/eleventy-fetch ``` -------------------------------- ### Install @11ty/eleventy-plugin-webc Source: https://github.com/11ty/docs/blob/main/src/docs/languages/webc.md Install the official Eleventy WebC plugin via npm. Requires Eleventy 2.0.0-canary.16 or newer. ```bash npm install @11ty/eleventy-plugin-webc ``` -------------------------------- ### Paired Shortcode Example (Nunjucks) Source: https://github.com/11ty/docs/blob/main/src/docs/shortcodes.md Shows the syntax for a paired shortcode in a Nunjucks template, with a start and end tag that can wrap nested template content. ```njk {% include "snippets/shortcodes/paired.njk" %} ``` -------------------------------- ### Asset bundling output: _site/page.html Source: https://github.com/11ty/docs/blob/main/src/docs/languages/webc.md Rendered output for the asset bundling example. The component tag is kept, and the style is removed. ```html WebC Example Components don’t need a root element, y’all. ``` -------------------------------- ### starter.11ty.js: Accessible Pagination Navigation (JavaScript) Source: https://github.com/11ty/docs/blob/main/src/docs/pagination/nav.md JavaScript template for a starter pagination navigation. This example is the JavaScript equivalent of starter.liquid and starter.njk, producing the same accessible HTML structure. ```js {%- include "snippets/pagination/nav/starter.js" %} ``` -------------------------------- ### Install @11ty/is-land with npm Source: https://github.com/11ty/docs/blob/main/src/docs/plugins/is-land.md Install the is-land plugin via npm. This is the first step before adding is-land.js to your primary bundle. ```bash npm install @11ty/is-land ``` -------------------------------- ### Sample site JSON with business_url and business_name Source: https://github.com/11ty/docs/blob/main/src/blog/2021-02-26-espbn.md A valid example that adds the optional business_name property to customize the displayed business name. ```json { "url": "https://www.zachleat.com/", "name": "Zach Leatherman", "twitter": "zachleat", "business_url": "https://www.zachleat.com/hire-me/", "business_name": "zachleat Web Design Company" } ``` -------------------------------- ### Install Eleventy v2.0 beta globally Source: https://github.com/11ty/docs/blob/main/src/blog/2023-01-18-eleventy-v2-beta.md Install the beta version of Eleventy globally using npm with the -g flag. This makes the eleventy command available system-wide. ```sh npm install @11ty/eleventy@beta -g ``` -------------------------------- ### Bundle ordering example: header.webc Source: https://github.com/11ty/docs/blob/main/src/docs/languages/webc.md Component used by index.webc, its CSS appears first in the bundle. ```html ``` -------------------------------- ### Install @11ty/eleventy-plugin-haml Source: https://github.com/11ty/docs/blob/main/src/docs/languages/haml.md Install the HAML plugin for Eleventy v3 and newer. This package is required because HAML support was moved out of Eleventy core. ```bash npm install @11ty/eleventy-plugin-haml ``` -------------------------------- ### Enable Browsersync in Eleventy configuration Source: https://github.com/11ty/docs/blob/main/src/docs/dev-server.md Configuration example using setServerOptions to enable Browsersync with default options. ```javascript export default function(eleventyConfig) { eleventyConfig.setServerOptions({ module: "@11ty/eleventy-server-browsersync", // Default Browsersync options shown: port: 8080, open: false, notify: false, ui: false, ghostMode: false, // Opt-out of the Browsersync snippet // snippet: false, }); }; ``` -------------------------------- ### starter.njk: Accessible Pagination Navigation (Nunjucks) Source: https://github.com/11ty/docs/blob/main/src/docs/pagination/nav.md Nunjucks template for a starter pagination navigation. This example is the Nunjucks equivalent of starter.liquid and produces the same accessible HTML structure with aria-labelledby and aria-current. ```html {%- include "snippets/pagination/nav/starter.njk" %} ``` -------------------------------- ### Install @11ty/eleventy-plugin-mustache Source: https://github.com/11ty/docs/blob/main/src/docs/languages/mustache.md Install the Mustache plugin for Eleventy v3 and newer, as the templating language was moved out of core. ```bash npm install @11ty/eleventy-plugin-mustache ``` -------------------------------- ### Re-run Eleventy when you save with --serve and --watch Source: https://github.com/11ty/docs/blob/main/src/docs/usage.md Use --serve to start a web server that automatically applies changes and refreshes the browser. Use --port to change the server port. Use --watch to re-run Eleventy when files change without starting a server. ```bash npx @11ty/eleventy --serve ``` ```bash npx @11ty/eleventy --serve --port=8081 ``` ```bash npx @11ty/eleventy --watch ``` -------------------------------- ### Install terser with npm Source: https://github.com/11ty/docs/blob/main/src/docs/quicktips/inline-js.md Run this command to install the terser minifier as a dependency in your project. ```bash npm install terser ``` -------------------------------- ### Install @11ty/eleventy-plugin-ejs Source: https://github.com/11ty/docs/blob/main/src/docs/languages/ejs.md Install the EJS plugin from npm to use EJS with Eleventy v3 and newer. ```bash npm install @11ty/eleventy-plugin-ejs ``` -------------------------------- ### Check Eleventy version globally Source: https://github.com/11ty/docs/blob/main/src/docs/global-installation.md Run this command to check the installed Eleventy version when using global installation. The output shows the latest version. ```bash $ eleventy --version {% latestVersion versions, config, "" %} ``` -------------------------------- ### init function for one-time setup Source: https://github.com/11ty/docs/blob/main/src/docs/languages/custom.md Runs once before any compilation or rendering. Does not re-run on watch/serve mode; use the eleventy.before event for per-build setup. ```javascript // some configuration truncated … init: async function() { // has access to current configuration settings in `this.config` }, ``` -------------------------------- ### Install Sass npm package Source: https://github.com/11ty/docs/blob/main/src/docs/languages/sass.md Install the 'sass' npm package, which is required for Eleventy to compile .scss files. ```bash npm install sass ``` -------------------------------- ### Get one branch with eleventyNavigation in Liquid Source: https://github.com/11ty/docs/blob/main/src/docs/plugins/navigation.md Pass a key to eleventyNavigation to get only the children of a specific branch. The example uses the key "Mammals". ```liquid {% assign navPages = collections.all | eleventyNavigation: "Mammals" %} {{ navPages | json }} ``` -------------------------------- ### starter.11ty.cjs: Accessible Pagination Navigation (CommonJS) Source: https://github.com/11ty/docs/blob/main/src/docs/pagination/nav.md CommonJS template for a starter pagination navigation. This example is the CommonJS equivalent of the previous starter templates, producing the same accessible HTML structure. ```js {%- include "snippets/pagination/nav/starter.cjs" %} ``` -------------------------------- ### Bundle ordering example: index.webc Source: https://github.com/11ty/docs/blob/main/src/docs/languages/webc.md Page component that uses a header component, demonstrating bundle code ordering from most specific to least specific. ```html
``` -------------------------------- ### Get one branch with eleventyNavigation in Nunjucks Source: https://github.com/11ty/docs/blob/main/src/docs/plugins/navigation.md Pass a key to eleventyNavigation in Nunjucks to get only the children of a specific branch. The example uses the key "Mammals". ```jinja2 {% set navPages = collections.all | eleventyNavigation("Mammals") %} {{ navPages | dump | safe }} ``` -------------------------------- ### Example output of stargazers count Source: https://github.com/11ty/docs/blob/main/src/docs/quicktips/eliminate-js.md Example output showing the rendered result of the template: '1515 GitHub Stars'. ```text 1515 GitHub Stars ``` -------------------------------- ### Install Eleventy RSS plugin with npm Source: https://github.com/11ty/docs/blob/main/src/docs/create-plugin.md Use this command to install the official RSS plugin for Eleventy. The --save flag adds it to your package.json dependencies. ```bash npm install @11ty/eleventy-plugin-rss --save ``` -------------------------------- ### Example: Heading with generated id Source: https://github.com/11ty/docs/blob/main/src/docs/plugins/id-attribute.md The same heading after the plugin adds the id attribute. ```html

Welcome to Eleventy

``` -------------------------------- ### Slots example with page.webc and component Source: https://github.com/11ty/docs/blob/main/src/docs/languages/webc.md Child content optionally precompiles using and [slot]. This example uses an HTML-only component. The page.webc file uses the component, and the component file defines the slot with fallback content. ```html This is the default slot ``` ```html

Fallback slot content

``` -------------------------------- ### webc:scoped output HTML Source: https://github.com/11ty/docs/blob/main/src/docs/languages/webc.md The rendered output of the webc:scoped example. The component gets a class attribute with the generated hash-based class name. ```html Default slot ``` -------------------------------- ### Install cross-env for cross-platform environment variables Source: https://github.com/11ty/docs/blob/main/src/docs/environment-vars.md Install the cross-env package to set environment variables cross-platform in npm scripts. ```bash npm install cross-env ``` -------------------------------- ### Liquid diff-js Example: Show Changes Source: https://github.com/11ty/docs/blob/main/src/docs/plugins/syntaxhighlight.md Use the diff- prefix with the language name to show additions and removals. Lines starting with + are additions, - are removals. ```liquid {% highlight "diff-js" %} +function myFunction() { // … - return true; } {% endhighlight %} ``` -------------------------------- ### Configure directory output with options Source: https://github.com/11ty/docs/blob/main/src/docs/plugins/directory-output.md Configure the plugin with custom columns and a file size warning threshold. The benchmark column requires Eleventy 1.0.1 or newer. The warningFileSize is in bytes and shown in yellow when exceeded. ```javascript import dirOutputPlugin from "@11ty/eleventy-plugin-directory-output"; export default function (eleventyConfig) { eleventyConfig.setQuietMode(true); eleventyConfig.addPlugin(dirOutputPlugin, { // Customize columns columns: { filesize: true, // Use `false` to disable benchmark: true, // Use `false` to disable }, // Will show in yellow if greater than this number of bytes warningFileSize: 400 * 1000, }); }; ``` -------------------------------- ### Custom Date Parsing Example with IANA Time Zone Source: https://github.com/11ty/docs/blob/main/src/docs/dates.md Example front matter with a date string containing an IANA time zone, and a configuration callback that parses it using Luxon's DateTime.fromFormat. The callback returns a Luxon DateTime instance to short-circuit page.date. ```yaml --- date: 2019-08-31 23:59:56 America/New_York --- ``` ```javascript import { DateTime } from "luxon"; export default function(eleventyConfig) { eleventyConfig.addDateParsing(function(dateValue) { if (typeof dateValue === "string") { return DateTime.fromFormat(dateValue, "yyyy-MM-dd hh:mm:ss z"); } }); }; ``` -------------------------------- ### Petite Vue initialization Source: https://github.com/11ty/docs/blob/main/src/docs/plugins/is-land.md Define a petite-vue init type once, then use it on any number of islands. The example imports petite-vue from unpkg and mounts the app. ```html Hello from HTML ``` -------------------------------- ### HTML-only component output: _site/page.html Source: https://github.com/11ty/docs/blob/main/src/docs/languages/webc.md Rendered output for the HTML-only component example. The component tag is removed, leaving only the content. ```html WebC Example Components don’t need a root element, y’all. ``` -------------------------------- ### addTemplate API call example Source: https://github.com/11ty/docs/blob/main/src/docs/virtual-templates.md Shows the signature of eleventyConfig.addTemplate with virtualPath, content, and optional data object. ```javascript eleventyConfig.addTemplate(virtualPath, content, data = {}); ``` -------------------------------- ### Liquid: eleventyNavigationBreadcrumb basic usage Source: https://github.com/11ty/docs/blob/main/src/docs/plugins/navigation.md Use the eleventyNavigationBreadcrumb filter in Liquid to get an array of parent pages for a given key. The filter returns an array of parent entries, with the top-most parent first. The example assigns the result to navPages and outputs it as JSON. ```liquid {% assign navPages = collections.all | eleventyNavigationBreadcrumb: "Bats" %} {{ navPages | json }} ``` -------------------------------- ### Nunjucks: eleventyNavigationBreadcrumb basic usage Source: https://github.com/11ty/docs/blob/main/src/docs/plugins/navigation.md Use the eleventyNavigationBreadcrumb filter in Nunjucks to get an array of parent pages for a given key. The filter returns an array of parent entries, with the top-most parent first. The example assigns the result to navPages and outputs it using dump and safe filters. ```jinja2 {% set navPages = collections.all | eleventyNavigationBreadcrumb("Bats") %} {{ navPages | dump | safe }} ``` -------------------------------- ### Markdown syntax example in example.md Source: https://github.com/11ty/docs/blob/main/src/docs/languages/markdown.md Shows basic Markdown syntax for bold, italic, links, lists, and tables. This is the content of an example.md file. ```markdown **Markdown** is a great language for writing _content_. You can create [links](https://11ty.dev), lists, tables, and more. ``` -------------------------------- ### Run Eleventy with --serve and --incremental Source: https://github.com/11ty/docs/blob/main/src/docs/usage.md Use this command to serve the site with a local server and only rebuild changed files, ideal for local development with live reload. ```bash npx @11ty/eleventy --serve --incremental ``` -------------------------------- ### Skip initial build with --ignore-initial Source: https://github.com/11ty/docs/blob/main/src/docs/usage.md Use this command to skip the initial full build and only process files that change after Eleventy starts, useful when you want to avoid an initial build. ```bash npx @11ty/eleventy --serve --incremental --ignore-initial ``` -------------------------------- ### Basic addPreprocessor usage with drafts and content modification Source: https://github.com/11ty/docs/blob/main/src/docs/config-preprocessors.md Shows the basic usage of `eleventyConfig.addPreprocessor` with a comma-separated string of file extensions. The callback receives `data` and `content`, can return `false` to ignore the template (like `eleventyConfig.ignores`), return modified content to change the raw input, or return `undefined`/nothing for no effect. The example checks for a `draft` flag and appends a comment with the input path. ```javascript export default function (eleventyConfig) { eleventyConfig.addPreprocessor("drafts", "njk,md,liquid", (data, content) => { if(data.draft) { // Ignore this file. return false; } // You can also modify the raw input of the template here too, be careful! return `${content}`; // If you return nothing or `undefined`, no changes will be made to this template. }); }; ``` -------------------------------- ### Basic is-land usage Source: https://github.com/11ty/docs/blob/main/src/docs/plugins/is-land.md Minimal example of an is-land element. Add loading conditions to control initialization; all conditions must be satisfied. ```html This is an island. ``` -------------------------------- ### Run Eleventy programmatically and write to file system Source: https://github.com/11ty/docs/blob/main/src/docs/programmatic.md Creates a Node script that runs Eleventy and writes output to the file system. Requires Eleventy installed locally. Run with `node my-node-script.js`. ```javascript const Eleventy = require("@11ty/eleventy"); (async () => { const elev = new Eleventy(); // Custom directory locations: // let elev = new Eleventy("input", "output"); // Custom directory locations and options: // let elev = new Eleventy("input", "output", { // markdownTemplateEngine: "njk" // }); await elev.write(); })(); ``` ```bash node my-node-script.js ``` -------------------------------- ### Template with permalink and page.url (about.es.html) Source: https://github.com/11ty/docs/blob/main/src/docs/permalinks.md Example template that sets a permalink to about.es.html and outputs page.url. Used with the URL transform to map to /about/. ```markdown --- permalink: about.es.html --- {{ page.url }} ``` -------------------------------- ### Vue initialization Source: https://github.com/11ty/docs/blob/main/src/docs/plugins/is-land.md Define a vue init type once, then use it on any number of islands. The example imports Vue from unpkg and uses data attributes as component data. ```html Hello from ``` -------------------------------- ### Basic HTML Transform Plugin Setup Source: https://github.com/11ty/docs/blob/main/src/docs/plugins/image.md Adds the eleventyImageTransformPlugin to an Eleventy config. This is the easiest method to configure, transforming any or tags in HTML files as a post-processing step. ```javascript import { eleventyImageTransformPlugin } from "@11ty/eleventy-img"; export default function (eleventyConfig) { eleventyConfig.addPlugin(eleventyImageTransformPlugin); }; ``` -------------------------------- ### Install Render plugin with addPlugin Source: https://github.com/11ty/docs/blob/main/src/docs/plugins/render.md Adds the bundled Render plugin to your Eleventy configuration file (e.g., eleventy.config.js) using addPlugin. ```javascript const { EleventyRenderPlugin } = require("@11ty/eleventy"); module.exports = function(eleventyConfig) { eleventyConfig.addPlugin(EleventyRenderPlugin); }; ``` -------------------------------- ### Sample output of eleventy-plugin-directory-output Source: https://github.com/11ty/docs/blob/main/src/docs/plugins/directory-output.md Sample console output showing grouped files by directory with file size and benchmark columns. ```bash > eleventy-base-blog@6.0.0 build > eleventy ↘ _site/ -- -- -- → about/index.html about/index.md 1.8kB 2.7ms ↘ feed/ -- -- -- • .htaccess feed/htaccess.njk 0.1kB 0.2ms • feed.json feed/json.njk 106.8kB 17.3ms • feed.xml feed/feed.njk 109.8kB 9.8ms → page-list/index.html page-list.njk 3.2kB 1.1ms ↘ posts/ -- -- -- → firstpost/index.html posts/firstpost.md 3.5kB 1.0ms → fourthpost/index.html posts/fourthpost.md 101.0kB 27.2ms → secondpost/index.html posts/secondpost.md 3.2kB 5.6ms → thirdpost/index.html posts/thirdpost.md 4.5kB 7.5ms • index.html archive.njk 3.0kB 13.7ms ↘ tags/ -- -- -- → another-tag/index.html tags.njk 2.1kB 0.9ms → number-2/index.html tags.njk 2.1kB 0.4ms → posts-with-two-tags/index.html tags.njk 2.3kB 0.2ms → second-tag/index.html tags.njk 2.5kB 0.5ms • index.html tags-list.njk 2.0kB 0.4ms • 404.html 404.md 1.9kB 0.4ms • index.html index.njk 2.8kB 1.7ms • sitemap.xml sitemap.xml.njk 1.4kB 1.3ms [11ty] Copied 3 files / Wrote 18 files in 0.16 seconds (8.9ms each, v1.0.1) ``` -------------------------------- ### Eleventy --serve --ignore-initial Source: https://github.com/11ty/docs/blob/main/src/docs/usage.md Runs Eleventy's dev server, skipping the initial build and only building on file changes. ```bash npx @11ty/eleventy --serve --ignore-initial ``` -------------------------------- ### init Source: https://github.com/11ty/docs/blob/main/src/docs/languages/custom.md An optional async-friendly function that runs once at the beginning before any compilation or rendering. It is used for additional setup and does not re-run on watch/serve mode. ```APIDOC ## init ### Description An optional async-friendly function that runs once at the beginning before any compilation or rendering. It is used for additional setup and does not re-run on watch/serve mode. ### Parameters None (but has access to current configuration settings in `this.config`) ### Example ```js init: async function() { // has access to current configuration settings in `this.config` }, ``` ``` -------------------------------- ### In-memory cache reuse example (.eleventy.js) Source: https://github.com/11ty/docs/blob/main/src/docs/plugins/image.md Shows that calling Image() twice with the same source and options returns the same promise, demonstrating the in-memory cache. The assertion verifies the promises are identical. ```javascript import Image from "@11ty/eleventy-img"; let stats1 = Image("./test/bio-2017.jpg"); let stats2 = Image("./test/bio-2017.jpg"); console.assert(stats1 === stats2, "The same promise"); ``` -------------------------------- ### Basic Eleventy command with npm Source: https://github.com/11ty/docs/blob/main/src/docs/usage.md Runs Eleventy in the current directory, outputting to ./_site. The command is equivalent to specifying --input=. --output=_site. ```bash # Searches the current directory, outputs to ./_site npx @11ty/eleventy # `npx @11ty/eleventy` is the same as: npx @11ty/eleventy --input=. --output=_site ``` -------------------------------- ### Front matter for a blog post (posts/my-page-title.md) Source: https://github.com/11ty/docs/blob/main/src/docs/data-computed.md Example front matter for a blog post that defines title and parent properties, which are used by computed data to generate the eleventyNavigation object. ```markdown --- title: My Page Title parent: My Parent Key --- ``` -------------------------------- ### Nunjucks/Liquid template string example Source: https://github.com/11ty/docs/blob/main/src/docs/data-computed.md Shows using template syntax in eleventyComputed within YAML front matter. Must match the template syntax of the template (Nunjucks or Liquid). ```markdown --- title: My Page Title parent: My Parent Key eleventyComputed: eleventyNavigation: key: "{{ title }}" parent: "{{ parent }}" --- ``` -------------------------------- ### Command Line: Set Path Prefix with --pathprefix Source: https://github.com/11ty/docs/blob/main/src/docs/config.md Use the --pathprefix command line override to deploy to a subdirectory, such as GitHub pages. This does not affect the output folder structure. ```bash npx @11ty/eleventy --pathprefix=eleventy-base-blog ``` -------------------------------- ### Sample JavaScript file (sample.js) Source: https://github.com/11ty/docs/blob/main/src/docs/quicktips/inline-js.md A simple JavaScript file to be included and minified. Place this in your _includes directory. ```javascript // Hi console.log("Hi"); ``` -------------------------------- ### Write a bundle to the file system with getBundleFileUrl Source: https://github.com/11ty/docs/blob/main/src/docs/plugins/bundle.md Use the getBundleFileUrl shortcode to write the bundle content to a content-hashed file in the output directory and return the URL. This may be slower for first-time visitors but better for repeat views. ```html ``` -------------------------------- ### Configure netlify-plugin-cache in netlify.toml Source: https://github.com/11ty/docs/blob/main/src/docs/deployment.md Add this configuration to your netlify.toml file after installing netlify-plugin-cache with npm install netlify-plugin-cache. It persists the .cache directory across builds. ```toml [[plugins]] package = "netlify-plugin-cache" [plugins.inputs] paths = [ ".cache" ] ``` -------------------------------- ### Enable detailed benchmarks on Windows with set DEBUG Source: https://github.com/11ty/docs/blob/main/src/docs/debug-performance.md On Windows, use 'set DEBUG=Eleventy:Benchmark* &' to enable the same detailed performance output when running eleventy. ```bash set DEBUG=Eleventy:Benchmark* & npx @11ty/eleventy ``` -------------------------------- ### Command Line: Set Template Formats with --formats Source: https://github.com/11ty/docs/blob/main/src/docs/config.md Use the --formats command line override to specify which template formats to process. Accepts a comma-separated string of template engine short names. ```bash npx @11ty/eleventy --formats=html,liquid,njk ``` -------------------------------- ### Add markdown-it plugin using amendLibrary Source: https://github.com/11ty/docs/blob/main/src/docs/languages/markdown.md Install and use a markdown-it plugin (e.g., markdown-it-emoji) via the amendLibrary method. Requires npm install of the plugin first. ```js import { full as emoji } from "markdown-it-emoji"; export default function (eleventyConfig) { eleventyConfig.amendLibrary("md", (mdLib) => mdLib.use(emoji)); }; ``` -------------------------------- ### Configure plugin options (eleventy-plugin-syntaxhighlight) Source: https://github.com/11ty/docs/blob/main/src/docs/create-plugin.md Pass an options object as the second argument to addPlugin to customize plugin behavior. This example shows limiting template formats and adding a custom Prism init function. ```javascript import pluginSyntaxHighlight from "@11ty/eleventy-plugin-syntaxhighlight"; export default function (eleventyConfig) { eleventyConfig.addPlugin(pluginSyntaxHighlight, { // only install the markdown highlighter templateFormats: ["md"], init: function ({ Prism }) { // Add your own custom language to Prism! }, }); }; ``` -------------------------------- ### locale_links filter output example Source: https://github.com/11ty/docs/blob/main/src/docs/plugins/i18n.md Example JSON output from the locale_links filter, showing an array of objects with url, lang, and label properties for alternative language versions. ```json [{ "url": "/es/blog/", "lang": "es", "label": "Español" }] ``` -------------------------------- ### Example aggregate benchmark output lines Source: https://github.com/11ty/docs/blob/main/src/docs/debug-performance.md Sample output from the aggregate benchmarks category, showing higher-level timings like file system search, data file loading, template reads, and writes. Percentages may exceed 100% due to asynchronous tasks, especially passthrough copy. ```text Benchmark (Aggregate): Searching the file system took 40ms (0.5%, called 2×, 19.9ms each) +0ms Benchmark (Aggregate): Data File took 134ms (1.8%, called 405×, 0.3ms each) +0ms Benchmark (Aggregate): Template Read took 682ms (9.0%, called 600×, 1.1ms each) +0ms Benchmark (Aggregate): Passthrough Copy File took 924ms (12.2%, called 669×, 1.4ms each) +0ms Benchmark (Aggregate): Template Compile took 366ms (4.8%, called 1526×, 0.2ms each) +0ms Benchmark (Aggregate): Template Render took 1215ms (16.1%, called 949×, 1.3ms each) +0ms Benchmark (Aggregate): Template Write took 2088ms (27.6%, called 312×, 6.7ms each) +0ms ``` -------------------------------- ### Rendered output of 'This page also available in' example Source: https://github.com/11ty/docs/blob/main/src/docs/plugins/i18n.md HTML output rendered by the locale_links filter example, showing a link to the Spanish version with lang and hreflang attributes. ```html This page is also available in Español ``` -------------------------------- ### Execute plugin immediately with immediate option Source: https://github.com/11ty/docs/blob/main/src/docs/create-plugin.md By default, plugins run after the user's config file. Use the immediate: true option to execute the plugin's code immediately during configuration. This example shows the execution order. ```javascript export default function (eleventyConfig, pluginOptions) { console.log( "first" ); eleventyConfig.addPlugin(eleventyConfig => { console.log("fourth"); }); eleventyConfig.addPlugin(eleventyConfig => { console.log("second"); }, { immediate: true }); console.log("third"); }; ``` -------------------------------- ### Permalink starting page numbers at 1 (Nunjucks) Source: https://github.com/11ty/docs/blob/main/src/docs/pagination.md Adds 1 to `pagination.pageNumber` to start URLs at `page-1` instead of `page-0`. Nunjucks only; Liquid does not support the `+ 1` syntax. ```yaml --- permalink: "different/page-{{ pagination.pageNumber + 1 }}/index.html" --- ``` -------------------------------- ### Configure onRequest with URL patterns Source: https://github.com/11ty/docs/blob/main/src/docs/dev-server.md Sets up onRequest handlers for root, /empty, and /foo/:name paths. The / handler falls back to static files if it returns a falsy value other than an empty string. The /empty handler returns an empty string to render an empty page. The /foo/:name handler returns a response object with status, headers, and body, and patternGroups contains URLPattern matches. ```javascript export default function(eleventyConfig) { eleventyConfig.setServerOptions({ onRequest: { "/": function({ url }) { // will fallback to serve static files if we return any falsy value other than "" }, "/empty": function({ url }) { // render an empty page return ""; }, "/foo/:name": function({ url, pattern, patternGroups }) { // patternGroups will include URLPattern matches e.g. /foo/zach => { name: "zach" } return { status: 200, headers: { "Content-Type": "text/html", }, body: "Hello." }; } } }); }; ``` -------------------------------- ### Advanced JavaScript front matter example Source: https://github.com/11ty/docs/blob/main/src/docs/data-frontmatter.md Shows more advanced JavaScript front matter features: async/await, destructuring assignment, dynamic import, and access to Node.js globals. This example is inside a collapsible details section. ```js ---js // async-friendly const myAsyncString = await Promise.resolve("HELLO FROM THE OTHER SIDE"); // export via destructuring assignment const { myKey } = { myKey: "myValue" }; const [ first, second ] = [ "first", "second" ]; // export via dynamic import const { noop } = await import("@zachleat/noop"); // access Node.js globals like console.log console.log({ noop }); --- ``` -------------------------------- ### Sample CSS file (sample.css) Source: https://github.com/11ty/docs/blob/main/src/docs/quicktips/inline-css.md Sample CSS file to be placed in the _includes directory and used with the cssmin filter. ```css body { font-family: fantasy; } ``` -------------------------------- ### Install @11ty/eleventy-plugin-rss via npm Source: https://github.com/11ty/docs/blob/main/src/docs/plugins/rss.md Install the RSS plugin from npm. Version 3 is ESM-only and requires Eleventy v3.0 or newer; v2 also requires Eleventy v3.0 or newer, while v1 is compatible with Eleventy 0.11 or newer. ```bash npm install @11ty/eleventy-plugin-rss ``` -------------------------------- ### Skip files starting with underscore using compileOptions.permalink Source: https://github.com/11ty/docs/blob/main/src/docs/languages/custom.md Implements Sass’ underscore convention to skip writing the file to the output directory. Returns false for files whose basename starts with '_'. ```javascript // … some configuration truncated compileOptions: { permalink: function(contents, inputPath) { let parsed = path.parse(inputPath); if(parsed.name.startsWith("_")) { return false; } } }, ``` -------------------------------- ### Configure Eleventy Dev Server with setServerOptions Source: https://github.com/11ty/docs/blob/main/src/docs/dev-server.md Shows the default configuration options for the Eleventy Dev Server using the setServerOptions method. Includes options for liveReload, domDiff, port, watch, showAllHosts, https, encoding, showVersion, indexFileName, and onRequest. ```javascript export default function(eleventyConfig) { eleventyConfig.setServerOptions({ // Default values are shown: // Whether the live reload snippet is used liveReload: true, // Whether DOM diffing updates are applied where possible instead of page reloads domDiff: true, // The starting port number // Will increment up to (configurable) 10 times if a port is already in use. port: 8080, // Additional files to watch that will trigger server updates // Accepts an Array of file paths or globs (passed to `chokidar.watch`). // Works great with a separate bundler writing files to your output folder. // e.g. `watch: ["_site/**/*.css"]` watch: [], // Show local network IP addresses for device testing showAllHosts: false, // Use a local key/certificate to opt-in to local HTTP/2 with https https: { // key: "./localhost.key", // cert: "./localhost.cert", }, // Change the default file encoding for reading/serving files encoding: "utf-8", // Show the dev server version number on the command line showVersion: false, // Added in Dev Server 2.0+ // The default file name to show when a directory is requested. indexFileName: "index.html", // Added in Dev Server 2.0+ // An object mapping a URLPattern pathname to a callback function // for on-request processing (read more below). onRequest: {}, }); }; ``` -------------------------------- ### Return object from Eleventy Image Source: https://github.com/11ty/docs/blob/main/src/docs/plugins/image-js.md Example of the JavaScript object logged by the basic usage example. Shows the metadata structure for webp and jpeg formats, including width, height, filename, outputPath, url, sourceType, srcset, and size. ```javascript { webp: [ { format: 'webp', width: 300, height: 300, filename: '6dfd7ac6-300.webp', outputPath: 'img/6dfd7ac6-300.webp', url: '/img/6dfd7ac6-300.webp', sourceType: 'image/webp', srcset: '/img/6dfd7ac6-300.webp 300w', size: 10184 } ], jpeg: [ { format: 'jpeg', width: 300, height: 300, filename: '6dfd7ac6-300.jpeg', outputPath: 'img/6dfd7ac6-300.jpeg', url: '/img/6dfd7ac6-300.jpeg', sourceType: 'image/jpeg', srcset: '/img/6dfd7ac6-300.jpeg 300w', size: 15616 } ] } ``` -------------------------------- ### Full options list for setServerOptions Source: https://github.com/11ty/docs/blob/main/src/docs/dev-server.md Shows additional configuration options for the Eleventy Dev Server, including aliases for backwards compatibility. Options include injectedScriptsFolder, portReassignmentRetryCount, folder, enabled, and domdiff. ```javascript export default function(eleventyConfig) { eleventyConfig.setServerOptions({ // Change the name of the folder name used for injected scripts injectedScriptsFolder: ".11ty", // Number of times to increment a port is already in use portReassignmentRetryCount: 10, // Alias for backwards compatibility, renamed to `injectedScriptsFolder` in Dev Server 1.0+ folder: ".11ty", // Alias for backwards compatibility, renamed to `liveReload` in Dev Server 1.0+ enabled: true, // Alias for backwards compatibility, renamed to `domDiff` in Dev Server 1.0+ domdiff: true, }); }; ``` -------------------------------- ### HTML image example Source: https://github.com/11ty/docs/blob/main/src/docs/services/screenshots.md Example of using the Screenshot API in an HTML `` tag. The `src` attribute uses the URL format with a URI-encoded URL, size `small`, aspect ratio `9:16`, and zoom `bigger`. Includes `class`, `width`, `height`, `loading`, `decoding`, and `alt` attributes. ```html Screenshot of 11ty.dev ``` -------------------------------- ### Enable DEBUG mode Source: https://github.com/11ty/docs/blob/main/src/docs/plugins/fetch.md Run with DEBUG=Eleventy:Fetch to enable debug logging for the Fetch plugin. ```bash DEBUG=Eleventy:Fetch npx @11ty/eleventy ``` -------------------------------- ### locale_url filter usage examples Source: https://github.com/11ty/docs/blob/main/src/docs/plugins/i18n.md Examples of using the locale_url filter in Nunjucks templates. The filter transforms URLs based on the current page's locale, swapping language codes if present. It checks for the existence of the target file and throws an error if missing unless errorMode is changed. ```njk {{ "/blog/" | locale_url }} ``` ```njk {{ "/en/blog/" | locale_url }} ``` ```njk {{ "/es/blog/" | locale_url }} ``` -------------------------------- ### Example: Heading without id Source: https://github.com/11ty/docs/blob/main/src/docs/plugins/id-attribute.md A simple heading element before the plugin adds an id attribute. ```html

Welcome to Eleventy

```