11ty: Static Website Generator

Sat Apr 15 2023 05:21:40 GMT+0000 (Coordinated Universal Time)

What is 11ty (Eleventy)?

11ty is a static website generation tool used to create websites from markdown files and style them using predefined templates.

Features:

Installation & First steps!

I really don't want to invent the wheel here. Please refer to the official documentation for more and up to date information.
I cannot include examples on this page. I couldn't work out how to ignore the templating engine on particular lines. (Parts of the page were becoming my navbar. etc etc etc.)

Other useful pages:

I would seriously recommend you set this up in a git repository. Not only does it make things easier for you, it allows you to more easily deploy your website.

  1. Go into your git repo, then initalise your npm package.json

  2. Install 11ty. Refer to the Official Instructions

  3. Create an .eleventy.js file in your src directory
    This file is where you configure 11ty with its various features and plugins. In the example below. 11ty is configured to read from src and output the generated files to www.


    module.exports = function (config) {
    // Return your Object options:
    return {
        markdownTemplateEngine: 'njk',
        dataTemplateEngine: 'njk',
        htmlTemplateEngine: 'njk',
        dir: {
            input: "src",
            output: "www"
        }    
    }
};
// Add config.addPassthroughCopy(dir) to this to allow you to copy other files to the dist directory
// config.addPassthroughCopy('./www_src/images/');
// config.addPassthroughCopy('./www_src/css/');
// config.addPassthroughCopy('./www_src/js/');

Creating your content

  1. Go to your src directory
  2. Create some files

    _includes
        layouts
            base.html
            page.html
    index.md
  1. Go to your index.md file and give it some content!

---
title: 'Home'
layout: 'layouts/page.html'
---
# Hello World!
Hello!
## Hello again!
  1. Before we go trying to look at our content. We need to define our template/layout files.
    reference the existing 11ty documentation here. I would include the base templates here, but it would mess with this page's layout.

  2. Run npx eleventy --serve to automatically generate your website whenever you save a file in the src directory

  3. Open http://localhost:8080/ in your browser to view your page

How to deploy?

Just copy your output (www) folder and place it on your webhost!