Luciano Mammino PRO
Cloud developer, entrepreneur, fighter, butterfly maker! #nodejs #javascript - Author of https://www.nodejsdesignpatterns.com , Founder of https://fullstackbulletin.com
Luciano Mammino (@loige)
May 18, 19, 20 - 2021
content & templates
static HTML pages & assets
This is the core of a static site generator!
A programming blog
A recipes website
A movie reviews website
A photo book
An online portfolio
A podcast website
...
And even single-page applications!
I'm Luciano (🇮🇹🍕🍝) 👋
👨💻 Senior Architect
Co-Author of Node.js Design Patterns 👉
Accelerated Serverless | AI as a Service | Platform Modernisation
Do you want to work with us?
METALSMITH
A Java API client!
It's easy
It's generally cheap
It can scale easily
It can be more secure
We can build fast websites
We can still use dynamic data (API, CMS, etc.)
We can still add dynamic features
+350 tools listed!
It's written in Node.js
It's so simple that you don't need a "starter"
(but there are many if you want)
Fast & lightweight
Not opinionated
Simple to build incrementally on top of it
Makes me feel productive...
Install + Hello world
Custom config
Templates, frontmatter & Layouts
Live reload
Copying static files
Custom global data
Collection API
Using dynamic data
Pagination API
mkdir 11ty-sample-project
cd 11ty-sample-project
npm init -y
npm i --save-dev @11ty/eleventy
echo "# My sample Eleventy website" > index.md
node_modules/.bin/eleventy --watch --serve
// .eleventy.js
module.exports = function (config) {
return {
dir: {
input: './src', // default: `.`
output: './build' // default: _site
}
}
}
---
name: someone
age: 17
---
Rest of the file
---
name: someone
age: 17
---
{{ name }} is {{ age }} years old!
---
title: My default title
---
<!DOCTYPE html>
<head>
<meta charset="utf-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>{{ title }}</title>
</head>
<body>
<main>
{{ content | safe }}
</main>
</body>
</html>
src/_includes/base.njk
---
layout: base
---
# Hello from Eleventy
This is a simple Eleventy demo
To use a layout you can use the special frontmatter property "layout" in a template:
Eleventy uses BrowserSync to give you live-reload 🚀
src/_includes/style.css
html, body {
background-color: #eee;
margin: 0;
}
main {
box-sizing: border-box;
max-width: 1024px;
min-height: 100vh;
padding: 2em;
margin: 0 auto;
background: white;
}
// .eleventy.js
module.exports = function (config) {
config.addPassthroughCopy({
'./src/_includes/style.css': 'style.css'
})
// ...
}
---
title: My default title
---
<!DOCTYPE html>
<head>
<meta charset="utf-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>{{ title }}</title>
<link rel="stylesheet" href="/style.css"/>
</head>
<body>
<main>
{{ content | safe }}
</main>
</body>
</html>
src/_includes/base.njk
// src/_data/site.js
module.exports = {
author: 'Luciano Mammino',
copyrightYear: (new Date()).getFullYear()
}
<main>
{{ content | safe }}
<hr/>
<small>
A website by {{ site.author }}
- © {{ site.copyrightYear }}
</small>
</main>
---
tags: ["posts", "javascript"]
---
## An introduction to the spread syntax
**Spread syntax** (`...`) allows an iterable such as an array
expression or string to be expanded in places where zero or
more arguments (for function calls) or elements
(for array literals) are expected, or an object expression
to be expanded in places where zero or more
key-value pairs (for object literals) are expected.
---
title: "All posts"
layout: base
---
<h1>All posts</h1>
<ul>
{% for post in collections.posts %}
<li>
<a href="{{ post.url }}">
{{ post.data.title }}
</a>
</li>
{% endfor %}
</ul>
npm i --save-dev @11ty/eleventy-cache-assets
// src/_data/movies.js
const Cache = require('@11ty/eleventy-cache-assets')
module.exports = async function () {
return Cache(
'https://ghibliapi.herokuapp.com/films/',
{ type: 'json' }
)
}
---
layout: base
title: Studio Ghibli movies
---
<h1>Studio Ghibli movies</h1>
<ul>
{% for movie in movies %}
<li>
<a href="/movie/{{ movie.title | slug }">
{{ movie.title }}
</a>
</li>
{% endfor %}
</ul>
---
layout: base
permalink: /movie/{{ movie.title | slug }}/
pagination:
data: movies
size: 1
alias: movie
---
<h2>{{ movie.title }}</h2>
<ul>
<li>Released in <strong>{{ movie.release_date }}</strong></li>
<li>Directed by <strong>{{ movie.director }}</strong></li>
<li>Produced by <strong>{{ movie.producer }}</strong></li>
</ul>
<p>{{ movie.description }}</p>
<p><a href="/movies">See all movies</a></p>
Example using GitHub actions:
Icons by Freepik and Zlatko Najdenovski on Pixelbuddha
If you enjoyed this talk, you might also enjoy nodejsdp.link 😛
By Luciano Mammino
Static site generators and the JAMStack are all the rage right now. After trying several different tools to generate Static Sites, I recently discovered Eleventy and after building a few websites with it I feel like I am in love! In this presentation, I will try to explain why is that!
Cloud developer, entrepreneur, fighter, butterfly maker! #nodejs #javascript - Author of https://www.nodejsdesignpatterns.com , Founder of https://fullstackbulletin.com