Code Monkey home page Code Monkey logo

11ty-starter's Introduction

11ty starter

Table of contents

Overview

This is my 11ty starter template, with some useful plugins, scripts, and so on out of the box.

Features

This starter / template doesn't aim to be a total one-stop-shop, but it does attempt to include an array of common and useful features out-of-the-box:

  • Nunjucks (but you could easily modify it to use Liquid or something else)
  • bundled and minified (S)CSS and JS, using Parcel.js
  • minimized HTML in production, using html-minifier
  • image optimization with eleventy-img shortcode
  • generated OpenGraph meta and image tags
  • optimized favicons using eleventy-plugin-gen-favicons
  • checking for broken links using eleventy-plugin-broken-links
  • code linting with eslint and formatting with prettier
  • convenient dev and build npm scripts
  • GitHub action for checking Lighthouse scores after build, including caching of yarn dependencies and built output
  • dependabot pull requests for dependency updates

Getting Started

  1. Click "Use this template" above
  2. git clone the repo locally
  3. yarn to install dependencies
  4. yarn start to start local development
  5. yarn build to build for production

Essential next steps

  1. Edit the sitemeta.json file in src/_data and add your details
    • title
    • url (production)
    • twitter handle
    • author
    • description
    • favicon
  2. Place your favicon in the src/img directory
  3. Make sure the correct filename is specified in the sitemeta.json. (This filename should be relative to the project directory, e.g. ./src/img/favicon.svg)

Usage

Shortcodes

There are some useful shortcodes out of the box.

image

This is used for local or remote image optimiztion with eleventy-img.

The syntax is:

{% image "src", "alt" %}

NOTE: src is relative to ./src/img. All images should be placed in this directory. Sub-directories are allowed, but you must specify them when using the image shortcode.

E.g.:

{% image "foo/bar.jpg", "alt" %}

... will source an image located at ./src/img/foo/bar.jpg.

All images are outputted to dist/img, regardless of which sub-directory they are in, if any.

Optionally, you can specify further options, including:

Option Default Accepted Description
formats ['webp', 'avif', 'jpg'] Array of formats Specify which formats to output
loading "lazy" "lazy" or "eager" whether to use lazy loading
sizes ["100vw"] Array of media query sizes Specify sizes of media query sizes used on screen
widths [600, 1200, 1800, 2400, 4200, null] array of pixel sizes Sizes to output

You can use any or all of the options by passing them after the required src and alt values:

{% image "example.jpg", "An example image", loading="eager", widths=[600] %}

ogimage

This shortcode is used to add the OpenGraph image meta tags.

{% ogimage "src", "alt" %}

This feature can be used via variables in frontmatter or in .njk templates:

---
layout: 'layouts/example.njk'
og_image:
  src: 'example.jpg'
  alt: 'The alt text'
---

width and format can be set in 11ty/constants/settings.js.

OpenGraph

OpenGraph meta tags are set using the ogimage shortcode (as above), and by setting the title and description variables in frontmatter or elsewhere.

---
layout: foo.njk
title: "Page title"
description: "An example page"
og_image:
  src: example.jpg
  alt: "the image alt"
---

This is an example page with OG meta tags.

11ty-starter's People

Contributors

bradleyburgess avatar dependabot[bot] avatar

Stargazers

 avatar  avatar

Watchers

 avatar

Forkers

dwoodman2008

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.