Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .eleventy.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
const { EleventyServerlessBundlerPlugin } = require('@11ty/eleventy');
const markdownIt = require('markdown-it');
const emoji = require('markdown-it-emoji');
const eleventyPluginFilesMinifier = require('@sherby/eleventy-plugin-files-minifier');
Expand All @@ -17,6 +18,12 @@ const isValidEvent = (event) => isValidTitle(event.data.title);
const byDate = comparators((event) => event.data.date);

module.exports = (eleventyConfig) => {
eleventyConfig.addPlugin(EleventyServerlessBundlerPlugin, {
name: 'onrequest',
functionsDir: './netlify/functions/',
copy: ['src/utils/'],
});

eleventyConfig.addCollection('events', (collectionApi) => {
return collectionApi.getFilteredByGlob('./src/schedule/*.md');
});
Expand Down
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,7 @@ package-lock.json
_site/
.idea/
**/.DS_Store
.cache
.cache
.env
netlify/functions/onrequest/**
!netlify/functions/onrequest/index.js
9 changes: 8 additions & 1 deletion netlify.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,9 @@
[build.environment]
TZ='America/Los_Angeles'
TZ = "America/Los_Angeles"

[[redirects]]
from = "/live/"
to = "/.netlify/functions/onrequest"
status = 200
force = true
_generated_by_eleventy_serverless = "onrequest"
50 changes: 50 additions & 0 deletions netlify/functions/onrequest/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
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('onrequest', {
path: event.path,
query: event.queryStringParameters,
functionsDir: './netlify/functions/',
});

try {
return {
statusCode: 200,
headers: {
'Content-Type': 'text/html; charset=UTF-8',
},
body: await elev.render(),
};
} 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 (or Netlify Function)
// * Runs on first request only: Netlify On-demand Builder
// (don’t forget to `npm install @netlify/functions`)

exports.handler = handler;

//const { builder } = require("@netlify/functions");
//exports.handler = builder(handler);
7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,23 @@
"recognize": "all-contributors add"
},
"dependencies": {
"@11ty/eleventy": "^0.11.1",
"@11ty/eleventy": "1.0.0-beta.3",
"@11ty/eleventy-cache-assets": "^2.3.0",
"axios": "^0.24.0",
"calendar-link": "^2.0.8",
"cross-env": "^7.0.3",
"date-fns": "^2.16.1",
"generate-comparators": "^1.0.3",
"markdown-it": "^12.0.4",
"markdown-it-emoji": "^2.0.0"
"markdown-it-emoji": "^2.0.0",
"querystring": "^0.2.1"
},
"devDependencies": {
"@sherby/eleventy-plugin-files-minifier": "^1.1.1",
"all-contributors-cli": "^6.19.0",
"chalk": "^4.1.0",
"commander": "^6.2.1",
"dotenv": "^10.0.0",
"husky": "^4.3.6",
"inquirer": "^7.3.3",
"node-emoji": "^1.10.0",
Expand Down
10 changes: 10 additions & 0 deletions src/_data/streamers.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[
"5t3phDev",
"BuildingBedrockLayout",
"lunchdev",
"marbiano",
"SomeAnticsDev",
"stepzen_dev",
"ThoriumSim",
"TrostCodes"
Comment on lines +2 to +9
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've got FOMO here 😿

]
12 changes: 6 additions & 6 deletions src/_includes/layouts/event.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
{% include partials/favicon.html %}
{% include 'partials/favicon.html' %}
<link rel="stylesheet" href="/css/reset.css" />
<link rel="stylesheet" href="/css/styles.css" />
<link rel="stylesheet" href="/css/navbar.css" />
Expand All @@ -30,10 +30,10 @@
<meta property="og:image:alt" content="lunch.dev" />
<meta property="twitter:card" content="summary_large_image" />
<script src="/js/localize-dates.js" defer></script>
{% include partials/analytics.html %}
{% include 'partials/analytics.html' %}
</head>
<body data-typeface="system-ui">
{% include partials/header.html %}
{% include 'partials/header.html' %}
<div data-layout="centered-single-column">
<main class="events-page">
<h1>{{ title }}</h1>
Expand All @@ -43,7 +43,7 @@ <h1>{{ title }}</h1>
</small>

{% if calendarLinks.isPastEvent %}
<div>{% include partials/calendarLinks.html %}{% include partials/join-discord-button.html %}</div>
<div>{% include 'partials/calendarLinks.html' %}{% include 'partials/join-discord-button.html' %}</div>
{% endif %} {{ content }} {% case speakers.size %} {% when undefined %} {% when 1 %}
<h3>Speaker</h3>
{% else %}
Expand Down Expand Up @@ -101,8 +101,8 @@ <h3>Speakers</h3>
</span>
</p>
</main>
{% include partials/event-sesh-command.html %}
{% include 'partials/event-sesh-command.html' %}
</div>
{% include partials/footer.html %}
{% include 'partials/footer.html' %}
</body>
</html>
8 changes: 4 additions & 4 deletions src/_includes/layouts/homepage.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
{% include partials/favicon.html %}
{% include 'partials/favicon.html' %}
<link rel="stylesheet" href="css/reset.css" />
<link rel="stylesheet" href="css/styles.css" />
<link rel="stylesheet" href="/css/navbar.css" />
Expand All @@ -17,10 +17,10 @@
/>
<title>Lunch.dev Community Calendar</title>
<script src="/js/localize-dates.js" defer></script>
{% include partials/analytics.html %}
{% include 'partials/analytics.html' %}
</head>
<body data-typeface="system-ui">
{% include partials/header.html %}
{% include 'partials/header.html' %}
<main data-layout="centered-single-column">
<h2 id="next-event" class="events-title">Next event</h2>
<section id="next-event-section" aria-labelledby="next-event" class="events-section">
Expand Down Expand Up @@ -113,6 +113,6 @@ <h3 id="{{ event.data.title | slug }}">{{ event.data.title }}</h3>
{% endfor %}
</section>
</main>
{% include partials/footer.html %}
{% include 'partials/footer.html' %}
</body>
</html>
8 changes: 4 additions & 4 deletions src/_includes/layouts/page.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
{% include partials/favicon.html %}
{% include 'partials/favicon.html' %}
<link rel="stylesheet" href="/css/reset.css" />
<link rel="stylesheet" href="/css/styles.css" />
<link rel="stylesheet" href="/css/navbar.css" />
Expand All @@ -14,16 +14,16 @@
rel="stylesheet"
/>
<title>{{ title }} | Lunch.dev Community Calendar</title>
{% include partials/analytics.html %}
{% include 'partials/analytics.html' %}
</head>
<body data-typeface="system-ui">
{% include partials/header.html %}
{% include 'partials/header.html' %}
<div data-layout="centered-single-column">
<main>
<h1>{{ title }}</h1>
{{ content }}
</main>
</div>
{% include partials/footer.html %}
{% include 'partials/footer.html' %}
</body>
</html>
4 changes: 2 additions & 2 deletions src/_includes/layouts/post.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@
rel="stylesheet"
/>
<title>{{ title }} | Lunch.dev Community Calendar</title>
{% include partials/analytics.html %}
{% include 'partials/analytics.html' %}
</head>
<body data-typeface="system-ui">
{% include partials/header.html %}
{% include 'partials/header.html' %}
<div data-layout="centered-single-column">
<main>
<h1>{{ title }}</h1>
Expand Down
8 changes: 4 additions & 4 deletions src/_includes/partials/calendarLinks.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,21 @@
<ul class="add-to-calendar">
<li>
<a aria-label="Add to Google Calendar" href="{{ calendarLinks.googleLink }}">
{% include partials/googlecalendar.svg %}
{% include 'partials/googlecalendar.svg' %}
</a>
</li>
<li>
<a aria-label="Add to Outlook Calendar" href="{{ calendarLinks.outlookLink }}">
{% include partials/microsoftoutlook.svg %}
{% include 'partials/microsoftoutlook.svg' %}
</a>
</li>
<li>
<a aria-label="Add to Office 365 Calendar" href="{{ calendarLinks.officeLink }}">
{% include partials/microsoftoffice.svg %}
{% include 'partials/microsoftoffice.svg' %}
</a>
</li>
<li>
<a aria-label="Add to ics Calendar" href="{{ calendarLinks.icsLink }}"> {% include partials/calendar.svg %} </a>
<a aria-label="Add to ics Calendar" href="{{ calendarLinks.icsLink }}"> {% include 'partials/calendar.svg' %} </a>
</li>
</ul>
</div>
38 changes: 38 additions & 0 deletions src/live/index.liquid
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
---
title: Community Streamers
layout: layouts/page
permalink:
onrequest: /live/
---
{% if online.size == 0 %}
<h2>No one is streaming right now!</h2>
<p>But check out some channels from around the community.</p>

{% elsif online.size == 1 %}
{% assign featuredChannel = online[0] %}
<h2>{{ featuredChannel }} is streaming right now!</h2>
{% twitch featuredChannel %}

{% else %}
<h2>{{ online.size }} community members are streaming right now!</h2>
<ul>
{% for streamer in online %}
<li>
<a href="https://twitch.tv/{{streamer}}">
{{ streamer }}
</a>
</li>
{% endfor %}
</ul>
{% endif %}

<h2>Streamer List</h2>
<ul>
{% for streamer in streamers %}
<li>
<a href="https://twitch.tv/{{streamer}}">
{{ streamer }}
</a>
</li>
{% endfor %}
</ul>
54 changes: 54 additions & 0 deletions src/live/live.11tydata.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
// require('dotenv').config();
const axios = require('axios');
const qs = require('querystring');

let accessToken;

/**
* Determines whether a given channel is streaming right now
* @param {string} channel
* @return {boolean} whether that channel is streaming
*/
async function isStreaming(channel) {
const {
data: { data: streams },
} = await axios.get(`https://api.twitch.tv/helix/streams?user_login=${channel}`, {
headers: {
'Client-ID': process.env.TWITCH_CLIENT_ID,
Authorization: `Bearer ${accessToken}`,
},
});

return streams.length > 0;
}
Comment on lines +12 to +23
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You might want to throw in a catch here and return false for safety


module.exports = {
eleventyComputed: {
online: async ({ streamers }) => {
if (!process.env.TWITCH_CLIENT_ID) {
return [];
}

const opts = {
client_id: process.env.TWITCH_CLIENT_ID,
client_secret: process.env.TWITCH_CLIENT_SECRET,
grant_type: 'client_credentials',
scopes: '',
};
const params = qs.stringify(opts);

const { data } = await axios.post(`https://id.twitch.tv/oauth2/token?${params}`);
accessToken = data.access_token;

let activeStreamers = [];
for (let streamer of streamers) {
const live = await isStreaming(streamer);
if (live) {
activeStreamers.push(streamer);
}
}

return activeStreamers;
},
},
};