All Projects → 11ty → demo-eleventy-serverless

11ty / demo-eleventy-serverless

Licence: other
Run Eleventy in a serverless function

Programming Languages

javascript
184084 projects - #8 most used programming language
Nunjucks
165 projects

Projects that are alternatives of or similar to demo-eleventy-serverless

Eleventy
A simpler static site generator. An alternative to Jekyll. Transforms a directory of templates (of varying types) into HTML.
Stars: ✭ 10,867 (+20403.77%)
Mutual labels:  eleventy
11r
America's favorite Eleventy blog template.
Stars: ✭ 135 (+154.72%)
Mutual labels:  eleventy
eleventy bundler
NOT RECOMMENDED FOR USE; see README
Stars: ✭ 19 (-64.15%)
Mutual labels:  eleventy
eleventy-load
Resolve dependencies and post-process files in your Eleventy project
Stars: ✭ 28 (-47.17%)
Mutual labels:  eleventy
11up
A utility to create an 11ty site scaffold from one of a number of site templates. Mostly just Phil Hawksworth's regular starting points
Stars: ✭ 25 (-52.83%)
Mutual labels:  eleventy
frontend-tips
Super tiny, quick tips, tricks and best practices of front-end development
Stars: ✭ 511 (+864.15%)
Mutual labels:  eleventy
home
a blag.
Stars: ✭ 21 (-60.38%)
Mutual labels:  eleventy
data-11ty
An open source 11ty theme designed for reporting & data-visualization
Stars: ✭ 19 (-64.15%)
Mutual labels:  eleventy
fernfolio-11ty-template
The super simple portfolio template built with Eleventy and Netlify CMS
Stars: ✭ 64 (+20.75%)
Mutual labels:  eleventy
11ty-tailwind-jit
Try editing some Tailwind in this repo while running in dev. It's SO FAST!
Stars: ✭ 17 (-67.92%)
Mutual labels:  eleventy
alexcarpenter-11ty
📝 Source files for my personal website built with Eleventy and hosted with Netlify.
Stars: ✭ 89 (+67.92%)
Mutual labels:  eleventy
stacks-11ty
Open source 11ty theme with personality
Stars: ✭ 21 (-60.38%)
Mutual labels:  eleventy
eleventy-navigation
A plugin for creating hierarchical navigation in Eleventy projects. Supports breadcrumbs too!
Stars: ✭ 88 (+66.04%)
Mutual labels:  eleventy
Formation
💻 macOS setup script for front-end development
Stars: ✭ 1,706 (+3118.87%)
Mutual labels:  eleventy
nodejsdesignpatterns.com
Source for Website for Node.js Design Patterns, book by Mario Casciaro and Luciano Mammino, published by Packt (https://nodejsdp.link/buy)
Stars: ✭ 27 (-49.06%)
Mutual labels:  eleventy
Eleventy High Performance Blog
A high performance blog template for the 11ty static site generator.
Stars: ✭ 3,492 (+6488.68%)
Mutual labels:  eleventy
frontenso-11ty-starter
Production-ready 11ty+Gulp+Webpack Starter that features Nunjucks, SASS, TailwindCSS (with JIT complier), and ESNext.
Stars: ✭ 24 (-54.72%)
Mutual labels:  eleventy
11straps
11straps is a static website boilerplate. It combines Eleventy with Bootstrap 5. 🎉
Stars: ✭ 85 (+60.38%)
Mutual labels:  eleventy
eleventy-plugin-social-images
Create dynamic images sized for social media tags for your Eleventy content.
Stars: ✭ 35 (-33.96%)
Mutual labels:  eleventy
eleventy-plugin-prismic
Eleventy plugin and shortcodes to fetch and present Prismic content
Stars: ✭ 39 (-26.42%)
Mutual labels:  eleventy

Eleventy Serverless Demo

Running Eleventy inside of a Netlify serverless function.

Read the documentation on 11ty.dev

Run it

Locally

  1. Run npm install
  2. Run npm start
  3. Navigate to the demo URL at http://localhost:8080/

Production

  1. View the demo on Netlify
  2. Deploy your own to Netlify

How it works

Read the documentation on 11ty.dev

This requires Eleventy 1.0 or newer.

  1. Use Eleventy as normal.
    • In this demo src is the input directory.
    • For this demo we include one Nunjucks template (./src/sample-nunjucks.njk), a Global Data file, an include template, and an Eleventy layout.
    • To make any template file into a serverless template, modify your permalink object to include a serverless key.
---
permalink:
  build: "/"
  serverless: "/:slug/"
---

This makes eleventy.path.slug (the slug name matches :slug) available in global data for use in your serverless templates.

  1. Add the bundler plugin to your Eleventy configuration file (probably .eleventy.js). The name you pass into the plugin (we use serverless in this example) should match the key inside of your template’s permalink object (permalink.serverless).
const { EleventyServerlessBundlerPlugin } = require("@11ty/eleventy");

module.exports = function(eleventyConfig) {
	eleventyConfig.addPlugin(EleventyServerlessBundlerPlugin, {
		name: "serverless",
		functionsDir: "./netlify/functions/",
	});
};
  1. ./netlify/functions/serverless/index.js is the boilerplate serverless function code. You’ll need to create this yourself.
const { EleventyServerless } = require("@11ty/eleventy");
const { builder } = require("@netlify/functions");

// For the bundler (auto-generated by the plugin)
require("./eleventy-bundler-modules.js");

async function handler (event) {
	let elev = new EleventyServerless("serverless", event.path, {
		inputDir: "src",
		functionsDir: "netlify/functions/",
		query: event.queryStringParameters,
	});

	try {
		return {
			statusCode: 200,
			headers: {
				"Content-Type": "text/html; charset=UTF-8"
			},
			body: await elev.render()
		};
	} catch (error) {
		return {
			statusCode: error.httpStatusCode || 500,
			body: JSON.stringify({
				error: error.message
			})
		};
	}
}

// Netlify On-demand Builder (runs on first request only)
exports.handler = builder(handler);
  1. Add entries to your .gitignore file so the bundles aren’t checked into your repository.
netlify/functions/serverless/**
!netlify/functions/serverless/index.js
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].