{"id":15016413,"url":"https://github.com/11ty/demo-eleventy-serverless","last_synced_at":"2025-10-19T14:32:23.792Z","repository":{"id":46694550,"uuid":"337877729","full_name":"11ty/demo-eleventy-serverless","owner":"11ty","description":"Run Eleventy in a serverless function","archived":false,"fork":false,"pushed_at":"2023-05-04T20:43:49.000Z","size":57,"stargazers_count":59,"open_issues_count":3,"forks_count":10,"subscribers_count":5,"default_branch":"master","last_synced_at":"2024-10-29T15:44:53.431Z","etag":null,"topics":["eleventy","serverless"],"latest_commit_sha":null,"homepage":"https://demo-eleventy-serverless.netlify.app/","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/11ty.png","metadata":{"funding":{"open_collective":"11ty"},"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2021-02-10T23:03:18.000Z","updated_at":"2024-01-04T16:54:41.000Z","dependencies_parsed_at":"2023-09-23T14:37:47.764Z","dependency_job_id":null,"html_url":"https://github.com/11ty/demo-eleventy-serverless","commit_stats":{"total_commits":114,"total_committers":1,"mean_commits":114.0,"dds":0.0,"last_synced_commit":"02cb7ce37aa823d08cc4947165104c0b5751e3e1"},"previous_names":[],"tags_count":0,"template":true,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/11ty%2Fdemo-eleventy-serverless","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/11ty%2Fdemo-eleventy-serverless/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/11ty%2Fdemo-eleventy-serverless/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/11ty%2Fdemo-eleventy-serverless/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/11ty","download_url":"https://codeload.github.com/11ty/demo-eleventy-serverless/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":237152820,"owners_count":19263792,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["eleventy","serverless"],"created_at":"2024-09-24T19:48:50.730Z","updated_at":"2025-10-19T14:32:18.446Z","avatar_url":"https://github.com/11ty.png","language":"JavaScript","funding_links":["https://opencollective.com/11ty"],"categories":[],"sub_categories":[],"readme":"# Eleventy Serverless Demo\n\nRunning Eleventy inside of a Netlify serverless function.\n\n_[Read the documentation on 11ty.dev](https://www.11ty.dev/docs/plugins/serverless/)_\n\n## Run it\n\n### Locally\n\n1. Run `npm install`\n1. Run `npm start`\n1. Navigate to the demo URL at `http://localhost:8080/`\n\n### Production\n\n1. [View the demo on Netlify](https://demo-eleventy-serverless.netlify.app)\n1. [Deploy your own to Netlify](https://app.netlify.com/start/deploy?repository=https://github.com/11ty/demo-eleventy-serverless)\n\n## How it works\n\n_[Read the documentation on 11ty.dev](https://www.11ty.dev/docs/plugins/serverless/)_\n\n_This requires Eleventy 1.0 or newer._\n\n1. Use Eleventy as normal.\n\t- In this demo `src` is the input directory.\n\t- For this demo we include one Nunjucks template (`./src/sample-nunjucks.njk`), a Global Data file, an include template, and an Eleventy layout.\n\t- To make any template file into a serverless template, modify your `permalink` object to include a `serverless` key.\n\n```\n---\npermalink:\n  build: \"/\"\n  serverless: \"/:slug/\"\n---\n```\n\nThis makes `eleventy.path.slug` (the `slug` name matches `:slug`) available in global data for use in your serverless templates.\n\n2. 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`).\n\n```js\nconst { EleventyServerlessBundlerPlugin } = require(\"@11ty/eleventy\");\n\nmodule.exports = function(eleventyConfig) {\n\televentyConfig.addPlugin(EleventyServerlessBundlerPlugin, {\n\t\tname: \"serverless\",\n\t\tfunctionsDir: \"./netlify/functions/\",\n\t});\n};\n```\n\n3. `./netlify/functions/serverless/index.js` is the boilerplate serverless function code. You’ll need to create this yourself.\n\n```js\nconst { EleventyServerless } = require(\"@11ty/eleventy\");\nconst { builder } = require(\"@netlify/functions\");\n\n// For the bundler (auto-generated by the plugin)\nrequire(\"./eleventy-bundler-modules.js\");\n\nasync function handler (event) {\n\tlet elev = new EleventyServerless(\"serverless\", event.path, {\n\t\tinputDir: \"src\",\n\t\tfunctionsDir: \"netlify/functions/\",\n\t\tquery: event.queryStringParameters,\n\t});\n\n\ttry {\n\t\treturn {\n\t\t\tstatusCode: 200,\n\t\t\theaders: {\n\t\t\t\t\"Content-Type\": \"text/html; charset=UTF-8\"\n\t\t\t},\n\t\t\tbody: await elev.render()\n\t\t};\n\t} catch (error) {\n\t\treturn {\n\t\t\tstatusCode: error.httpStatusCode || 500,\n\t\t\tbody: JSON.stringify({\n\t\t\t\terror: error.message\n\t\t\t})\n\t\t};\n\t}\n}\n\n// Netlify On-demand Builder (runs on first request only)\nexports.handler = builder(handler);\n```\n\n4. Add entries to your `.gitignore` file so the bundles aren’t checked into your repository.\n\n```\nnetlify/functions/serverless/**\n!netlify/functions/serverless/index.js\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F11ty%2Fdemo-eleventy-serverless","html_url":"https://awesome.ecosyste.ms/projects/github.com%2F11ty%2Fdemo-eleventy-serverless","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F11ty%2Fdemo-eleventy-serverless/lists"}