npm init
npm install @11ty/eleventy
"scripts": {
"start": "eleventy --serve",
"build": "eleventy"
},.eleventy.js
module.exports = function (eleventyConfig) {
return {
dir: {
input: "src",
output: "public",
},
};
};npm run develop
Create src/
Create src/index.md
Create _includes/base.njk
Emmet: html:5
<title>{{ title }}</title>
Add layout: base.njk to index.md frontmatter
---
layout: base.njk
---Optional: Create src/about.md
Within base.njk- Emmet: header>h1 with value {{ title }}
Create blog/
Create front-end.md
Create _includes/post.njk
Content:
<article>
{{ content | safe}}
</article>In post.njk add frontmatter:
---
layout: base.njk
---Create blog/blog.json
{
"layout": "post"
}{
"layout": "post",
"permalink": "/{{ page.fileSlug }}/"
}{
"layout": "post",
"permalink": "/{{ page.fileSlug }}/",
"tags": "posts"
}Add to index.md:
## Blog Posts
{% for post in collections.posts %}
{{ post.data.title }}
{% endfor %}Modify previous for loop:
<ul>
{% for post in collections.posts %}
<li><a href="{{ post.url }}">{{ post.data.title }}</a></li>
{% endfor %}
</ul>Create _includes/postlist.njk
Update index.md to use {% include "postlist.njk" %}
Add templateEngineOverride: njk,md to index.md frontmatter
Create css/
Create css/style.css:
body {
font-family: sans-serif;
}Modify .eleventy.js:
eleventyConfig.addPassthroughCopy("./src/css");<link rel="stylesheet" href="/css/style.css" />
Create _data/
Create _data/facts.json:
[
"Did you know horses can swim?",
"Did you know that the average human can hold their breath for 2 minutes?",
"Did you know that we live on Earth?"
]Add after article in _includes/post.njk:
<aside>
{% for fact in facts %}
<p>{{ fact }}</p>
{% endfor %}
</aside>Add within the module.exports in .eleventy.js
eleventyConfig.addFilter("randomItem", (arr) => {
arr.sort(() => {
return 0.5 - Math.random();
});
return arr.slice(0, 1);
});{% for fact in facts | randomItem %}
## Push to Github
Create a repo and push project to Github (_instructions outside the scope of these steps_).
## Deploy to Github pages