mirror of
https://github.com/GuerillaStudio/compteur-de-greve.git
synced 2025-01-04 17:51:57 +00:00
add wip serverless support
This commit is contained in:
parent
898e9110ec
commit
0bbe61f47d
8 changed files with 97 additions and 2 deletions
|
@ -1,6 +1,12 @@
|
|||
const { EleventyServerlessBundlerPlugin } = require("@11ty/eleventy");
|
||||
const eleventySass = require("@11tyrocks/eleventy-plugin-sass-lightningcss")
|
||||
|
||||
module.exports = function (eleventyConfig) {
|
||||
eleventyConfig.addPlugin(EleventyServerlessBundlerPlugin, {
|
||||
name: "serverless",
|
||||
functionsDir: "./netlify/functions/",
|
||||
});
|
||||
|
||||
eleventyConfig.addPlugin(eleventySass)
|
||||
|
||||
eleventyConfig.setServerPassthroughCopyBehavior("passthrough")
|
||||
|
|
5
.gitignore
vendored
5
.gitignore
vendored
|
@ -11,3 +11,8 @@ public
|
|||
# macOS related files
|
||||
.DS_Store
|
||||
|
||||
|
||||
netlify/functions/serverless/*
|
||||
!netlify/functions/serverless/index.js
|
||||
netlify/functions/dynamic/*
|
||||
!netlify/functions/dynamic/index.js
|
||||
|
|
3
netlify.toml
Normal file
3
netlify.toml
Normal file
|
@ -0,0 +1,3 @@
|
|||
[build]
|
||||
publish = "public"
|
||||
command = "npm run build"
|
58
netlify/functions/serverless/index.js
Normal file
58
netlify/functions/serverless/index.js
Normal file
|
@ -0,0 +1,58 @@
|
|||
const { EleventyServerless } = require("@11ty/eleventy");
|
||||
|
||||
// Explicit dependencies for the bundler from config file and global data.
|
||||
// The file is generated by the Eleventy Serverless Bundler Plugin.
|
||||
require("./eleventy-bundler-modules.js");
|
||||
|
||||
async function handler(event) {
|
||||
let elev = new EleventyServerless("serverless", {
|
||||
path: new URL(event.rawUrl).pathname,
|
||||
singleTemplateScope: false,
|
||||
query: event.multiValueQueryStringParameters || event.queryStringParameters,
|
||||
functionsDir: "./netlify/functions/",
|
||||
});
|
||||
|
||||
try {
|
||||
let [page] = await elev.getOutput();
|
||||
|
||||
// If you want some of the data cascade available in `page.data`, use `eleventyConfig.dataFilterSelectors`.
|
||||
// Read more: https://www.11ty.dev/docs/config/#data-filter-selectors
|
||||
|
||||
return {
|
||||
statusCode: 200,
|
||||
headers: {
|
||||
"Content-Type": "text/html; charset=UTF-8",
|
||||
},
|
||||
body: page.content,
|
||||
};
|
||||
} catch (error) {
|
||||
// Only console log for matching serverless paths
|
||||
// (otherwise you’ll see a bunch of BrowserSync 404s for non-dynamic URLs during --serve)
|
||||
if (elev.isServerlessUrl(event.path)) {
|
||||
console.log("Serverless Error:", error);
|
||||
}
|
||||
|
||||
return {
|
||||
statusCode: error.httpStatusCode || 500,
|
||||
body: JSON.stringify(
|
||||
{
|
||||
error: error.message,
|
||||
},
|
||||
null,
|
||||
2
|
||||
),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
// Choose one:
|
||||
// * Runs on each request: AWS Lambda, Netlify Function
|
||||
// * Runs on first request only: Netlify On-demand Builder
|
||||
// 1. Don’t forget to `npm install @netlify/functions`
|
||||
// 2. Also use `redirects: "netlify-toml-builders"` in your config file’s serverless bundler options:
|
||||
// https://www.11ty.dev/docs/plugins/serverless/#bundler-options
|
||||
|
||||
// exports.handler = handler;
|
||||
|
||||
const { builder } = require("@netlify/functions");
|
||||
exports.handler = builder(handler);
|
17
package-lock.json
generated
17
package-lock.json
generated
|
@ -11,6 +11,7 @@
|
|||
"dependencies": {
|
||||
"@11ty/eleventy": "^2.0.0",
|
||||
"@11tyrocks/eleventy-plugin-sass-lightningcss": "^1.0.0",
|
||||
"@netlify/functions": "^1.4.0",
|
||||
"alpinejs": "^3.11.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
|
@ -293,6 +294,22 @@
|
|||
"resolved": "https://registry.npmjs.org/@iarna/toml/-/toml-2.2.5.tgz",
|
||||
"integrity": "sha512-trnsAYxU3xnS1gPHPyU961coFyLkh4gAD/0zQ5mymY4yOZ+CYvsPqUbOFSw0aDM4y0tV7tiFxL/1XfXPNC6IPg=="
|
||||
},
|
||||
"node_modules/@netlify/functions": {
|
||||
"version": "1.4.0",
|
||||
"resolved": "https://registry.npmjs.org/@netlify/functions/-/functions-1.4.0.tgz",
|
||||
"integrity": "sha512-gy7ULTIRroc2/jyFVGx1djCmmBMVisIwrvkqggq5B6iDcInRSy2Tpkm+V5C63hKJVkNRskKWtLQKm9ecCaQTjA==",
|
||||
"dependencies": {
|
||||
"is-promise": "^4.0.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=8.3.0"
|
||||
}
|
||||
},
|
||||
"node_modules/@netlify/functions/node_modules/is-promise": {
|
||||
"version": "4.0.0",
|
||||
"resolved": "https://registry.npmjs.org/is-promise/-/is-promise-4.0.0.tgz",
|
||||
"integrity": "sha512-hvpoI6korhJMnej285dSg6nu1+e6uxs7zG3BYAm5byqDsgJNWwxzM6z6iZiAgQR4TJ30JmBTOwqZUw3WlyH3AQ=="
|
||||
},
|
||||
"node_modules/@nodelib/fs.scandir": {
|
||||
"version": "2.1.5",
|
||||
"resolved": "https://registry.npmjs.org/@nodelib/fs.scandir/-/fs.scandir-2.1.5.tgz",
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
"dependencies": {
|
||||
"@11ty/eleventy": "^2.0.0",
|
||||
"@11tyrocks/eleventy-plugin-sass-lightningcss": "^1.0.0",
|
||||
"@netlify/functions": "^1.4.0",
|
||||
"alpinejs": "^3.11.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
|
|
3
src/index.11tydata.js
Normal file
3
src/index.11tydata.js
Normal file
|
@ -0,0 +1,3 @@
|
|||
module.exports = function() {
|
||||
return Promise.resolve({count: 69420})
|
||||
}
|
|
@ -1,8 +1,10 @@
|
|||
---
|
||||
layout: base.njk
|
||||
title: Compteur de grève
|
||||
permalink:
|
||||
serverless: /
|
||||
---
|
||||
<section class="banner" x-data="counter" data-initial-count="148563">
|
||||
<section class="banner" x-data="counter" data-initial-count="{{count}}">
|
||||
<div class="banner-layout">
|
||||
<div>
|
||||
<article class="counter">
|
||||
|
@ -11,7 +13,7 @@ title: Compteur de grève
|
|||
<span class="color-pink-2 pb05 inline-block">Contre la réforme des retraites,</span><br>
|
||||
À l’appel de l’ensemble des organisations syndicales, <span class="color-purple-1">le 7 mars</span>
|
||||
<span aria-live="polite">
|
||||
<strong class="counter-number" x-bind="counter">148 563</strong>
|
||||
<strong class="counter-number" x-bind="counter">{{count}}</strong>
|
||||
<span class="separator">personnes seront</span>
|
||||
<em class="counter-strikeeeee-lol highlighter-zigzag">en grève<span class="visually-hidden"> !</span></em>
|
||||
</span>
|
Loading…
Reference in a new issue