-
Notifications
You must be signed in to change notification settings - Fork 11
Create a page to show who is live on Twitch right now #120
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
BenDMyers
wants to merge
6
commits into
main
Choose a base branch
from
live-page
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
f0e0e20
Template for displaying streams that were live at build time
BenDMyers b80777e
Upgrade to Eleventy v1 beta
BenDMyers cbc9421
Unleash the serverless on the /live/ route
BenDMyers 9bf8c1f
Remove test streamers
BenDMyers 83ceab0
Don't require client ID
BenDMyers 1d88817
Pivot to 1.0.0-beta.3
BenDMyers File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| [ | ||
| "5t3phDev", | ||
| "BuildingBedrockLayout", | ||
| "lunchdev", | ||
| "marbiano", | ||
| "SomeAnticsDev", | ||
| "stepzen_dev", | ||
| "ThoriumSim", | ||
| "TrostCodes" | ||
| ] | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You might want to throw in a catch here and |
||
|
|
||
| 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; | ||
| }, | ||
| }, | ||
| }; | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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 😿