npx @11ty/eleventy
npm i -g @11ty/eleventy
Depends on your opinions about global modules, and how you manage node versions.
¯\_(ツ)_/¯
npm i --save @11ty/eleventy
{
"scripts": {
"build": "eleventy",
"start": "eleventy --serve"
}
}
.eleventy.js
Config Filemodule.exports = eleventyConfig => {
return {
dir: {}
};
};
---
title: My Page Title
author: My Name
permalink: /this-page-url/
layout: post
date: 2020-10-19
tags:
- news
---
Markdown content here.
Create an array from .md
Collections
eleventyConfig.addCollection(
'nav',
collection => collection.getAll()
.filter(item => {})
.sort((a, b) => {})
}
);
{% for link in collections.nav %}
<li>
<a href="{{ link.url }}">
{{ link.title }}
</a>
</li>
{% endfor %}
Get an array from an API Data from an API
// _data/posts.js
module.exports = () => {
return new Promise(() => {
// Make a request
// `resolve` the returned data
});
};
{% for p in posts %}
<li>
<a href="{{ p.url }}">
{{ p.title }}
</a>
</li>
{% endfor %}
Turn an array into pages Data to Pages
---
permalink: p.permalink
pagination:
data: posts
size: 1
alias: p
---
11ty dir key |
Folder |
---|---|
input |
. |
output |
_site |
includes |
_includes |
layouts |
dir.includes |
data |
_data |
permalink
Permalinkscontact.md
becomes /contact/index.html
tags/css.md
becomes /tags/css/index.html
---
layout: home
---
This page will be rendered with _includes/home.liquid
.
home.njk
Reduce repetition Layout Chaining
<!-- index.md -->
---
layout: home
---
<!-- home.liquid -->
---
layout: global
---
Custom layout names mapped to files Layout Aliases
eleventyConfig.addLayoutAlias(
'home',
'views/homeTemplate.njk'
);
{% include header %}
maps to
_includes/header.liquid
eleventyConfig.addShortcode(
'link',
(title, url) => {
return `<a href="${url}" class="link">${title}</a>`;
}
);
## Section
Content including a {% link
"cool hyperlink"
"https://jdsteinbach.com" %}
.11ty.js
template files.11ty.js
Templateclass
JS Template Classes
data()
function returns a data object (front matter)render()
function returns file contents.11ty.js
Templateindex.js
and return a rollup/webpack bundle JS TemplateeleventyConfig.addWatchTarget(
'./src/assets/js/**/*.js'
);
eleventyConfig.addWatchTarget(
'./src/assets/scss/**/*.scss'
);
eleventyConfig.addPassthroughCopy(
'src/fonts'
);
eleventyConfig.addPassthroughCopy({
'src/assets/site.js': 'js/site.js'
});
.addPassthroughCopy()
+ extra pluginimages.11ty.js
file running imagemin
Imagemin Processing<form netlify>
jdsteinbach