{"id":18584302,"url":"https://github.com/brob/demo-eleventy-serverless","last_synced_at":"2025-05-16T05:32:57.866Z","repository":{"id":49256626,"uuid":"379014859","full_name":"brob/demo-eleventy-serverless","owner":"brob","description":null,"archived":false,"fork":false,"pushed_at":"2023-12-15T20:31:18.000Z","size":53,"stargazers_count":1,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-02-17T16:51:56.904Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/brob.png","metadata":{"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,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-06-21T17:40:22.000Z","updated_at":"2021-07-07T14:53:37.000Z","dependencies_parsed_at":"2024-11-07T00:42:13.450Z","dependency_job_id":null,"html_url":"https://github.com/brob/demo-eleventy-serverless","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brob%2Fdemo-eleventy-serverless","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brob%2Fdemo-eleventy-serverless/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brob%2Fdemo-eleventy-serverless/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brob%2Fdemo-eleventy-serverless/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/brob","download_url":"https://codeload.github.com/brob/demo-eleventy-serverless/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254473722,"owners_count":22077159,"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":[],"created_at":"2024-11-07T00:27:03.769Z","updated_at":"2025-05-16T05:32:57.850Z","avatar_url":"https://github.com/brob.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Eleventy Serverless Demo\n\nRunning Eleventy inside of a Netlify serverless function.\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_This requires Eleventy 1.0 Canary 30 or newer. Be careful here, Canary is considered unstable! Don’t use it in production._\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%2Fbrob%2Fdemo-eleventy-serverless","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbrob%2Fdemo-eleventy-serverless","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbrob%2Fdemo-eleventy-serverless/lists"}