├── .gitignore ├── netlify.toml ├── _redirects ├── package.json ├── README.md ├── data └── sites.json ├── lambda-build ├── random.js ├── previous.js └── next.js └── index.html /.gitignore: -------------------------------------------------------------------------------- 1 | /node_modules/* 2 | /functions/ -------------------------------------------------------------------------------- /netlify.toml: -------------------------------------------------------------------------------- 1 | [build] 2 | functions = "./functions" -------------------------------------------------------------------------------- /_redirects: -------------------------------------------------------------------------------- 1 | /next /.netlify/functions/next 301 2 | /random /.netlify/functions/random 301 -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "Webring-functions", 3 | "version": "0.0.1", 4 | "dependencies": {}, 5 | "devDependencies": { 6 | "netlify-lambda": "^1.1.0" 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # A lambda function for creating a webring on netlify 2 | 3 | Add this to your netlify account, have folks add their sites to `/data/sites.json` and you're off to the races. 4 | 5 | Each site can add a widget to their site and hit the end points `/next`, `/random` and `/previous` to send their users to a new site! -------------------------------------------------------------------------------- /data/sites.json: -------------------------------------------------------------------------------- 1 | [ 2 | 3 | { 4 | "name": "Some site", 5 | "uri": "https://something.com" 6 | }, 7 | { 8 | "name": "Some site", 9 | "uri": "http://localhost:9000" 10 | }, 11 | { 12 | "name": "Bryan's site", 13 | "uri": "https://somethingelse.com" 14 | } 15 | ] -------------------------------------------------------------------------------- /lambda-build/random.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | const sites = require('../data/sites.json'); 3 | 4 | exports.handler = function(event, context, callback) { 5 | const randomSite = sites[Math.floor(Math.random()*sites.length)]; 6 | console.log(randomSite); 7 | 8 | var response = { 9 | statusCode: 302, 10 | headers: { 11 | "Location" : `${randomSite.uri}?from=webring`, 12 | "Cache-Control": "no-store" 13 | }, 14 | body: `Redirecting to ${randomSite.name}` 15 | }; 16 | 17 | callback(null, response); 18 | }; 19 | -------------------------------------------------------------------------------- /index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Fansite webring of fansites 8 | 9 | 10 |

This is the future home of something awesome: The fansite webring of fansites!

11 |

This site is mostly a holding point right now for a couple lambda functions to control some fansites' webring options

12 |

Want your site in the webring? Issue a pull request and add your site to this json file

13 | 14 | -------------------------------------------------------------------------------- /lambda-build/previous.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | const sites = require('../data/sites.json'); 3 | 4 | const findSite = (url) => { 5 | const site = sites.findIndex(function(item) { 6 | return item.uri.includes(url) 7 | }); 8 | return site; 9 | } 10 | const isFirst = (siteId) => { 11 | return (siteId === 0) ? true : false 12 | 13 | } 14 | 15 | exports.handler = function(event, context, callback) { 16 | const uri = event.headers.host; 17 | console.log(event); 18 | const siteId = findSite(uri); 19 | const firstCheck = isFirst(siteId); 20 | const previousSite = firstCheck ? `${sites[sites.length - 1].uri}` : `${sites[siteId - 1].uri}`; 21 | console.log(previousSite); 22 | 23 | var response = { 24 | statusCode: 302, 25 | headers: { 26 | "Location": previousSite 27 | }, 28 | body: `event is ${event}` 29 | }; 30 | callback(null, response); 31 | }; -------------------------------------------------------------------------------- /lambda-build/next.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | const sites = require('../data/sites.json'); 3 | 4 | const findSite = (url) => { 5 | const site = sites.findIndex(function(item) { 6 | return item.uri.includes(url) 7 | }); 8 | console.log(site); 9 | return site; 10 | } 11 | 12 | const isLast = (siteId) => { 13 | return siteId === sites.length - 1 ? true : false 14 | } 15 | 16 | exports.handler = function(event, context, callback) { 17 | const uri = event.headers.host; 18 | const siteId = findSite(uri); 19 | 20 | const lastCheck = isLast(siteId); 21 | console.log(lastCheck); 22 | const nextSite = lastCheck ? `${sites[0].uri}` : `${sites[siteId + 1].uri}`; 23 | console.log(nextSite); 24 | var response = { 25 | statusCode: 302, 26 | headers: { 27 | "Location": nextSite, 28 | "Cache-Control": "no-cache, no-store, must-revalidate" 29 | }, 30 | body: `event is ${event}` 31 | }; 32 | callback(null, response); 33 | }; --------------------------------------------------------------------------------