-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6861a65
commit 010a5e1
Showing
10 changed files
with
187 additions
and
141 deletions.
There are no files selected for viewing
9 changes: 3 additions & 6 deletions
9
packages/gatsby-theme-podcast/content/episodes/01-pilot/pilot.mdx
This file contains 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 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 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 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 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 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,92 @@ | ||
const crypto = require("crypto"); | ||
const Parser = require("rss-parser"); | ||
const parser = new Parser(); | ||
|
||
// Based on and extended from https://github.com/rheajt/gatsby-source-rss/blob/master/src/gatsby-node.js | ||
|
||
const createContentDigest = obj => | ||
crypto | ||
.createHash("md5") | ||
.update(JSON.stringify(obj)) | ||
.digest("hex"); | ||
|
||
const generateRSSItemSlug = title => { | ||
return ( | ||
title | ||
// remove non-alphanumeric characters, except spaces | ||
.replace(/[^\w\s]/gi, "") | ||
.toLowerCase() | ||
.split(" ") | ||
.join("-") | ||
); | ||
}; | ||
|
||
const durationToMinutes = durationInSeconds => { | ||
return Math.floor(durationInSeconds / 60); | ||
}; | ||
|
||
// hackity hack. this extracts the first paragraph from the description | ||
const extractFirstParagraph = html => { | ||
return html.match(/<p>(.*?)<\/p>/)[0]; | ||
}; | ||
|
||
async function sourceNodes({ actions }, { rssSource = "" }) { | ||
if (!rssSource) { | ||
console.log(`gatsby-theme-podcast requires an RSS feed`); | ||
return; | ||
} | ||
const { createNode } = actions; | ||
const data = await parser.parseURL(rssSource); | ||
|
||
if (!data) { | ||
return; | ||
} | ||
|
||
// Create nodes for top-level RSS feed info | ||
const { title, description, link, image, items } = data; | ||
|
||
// Prepare RSS item nodes | ||
const preparedRssItemNodes = items.map(rssItem => { | ||
let slug = generateRSSItemSlug(rssItem.title); | ||
let excerpt = extractFirstParagraph(rssItem.content); | ||
let duration = durationToMinutes(rssItem.itunes.duration); | ||
const node = Object.assign({}, rssItem, { | ||
id: rssItem.link, | ||
title: rssItem.title, | ||
content: rssItem.content, | ||
link: rssItem.link, | ||
excerpt, | ||
duration, | ||
slug, | ||
parent: null, | ||
children: [] | ||
}); | ||
node.internal = { | ||
type: "rssFeedItem", | ||
contentDigest: createContentDigest(node) | ||
}; | ||
return node; | ||
}); | ||
|
||
const feedInfo = { | ||
id: link, | ||
title, | ||
description, | ||
link, | ||
imageUrl: image.url, | ||
items___NODE: preparedRssItemNodes.map(node => node.id), | ||
parent: null | ||
}; | ||
|
||
feedInfo.internal = { | ||
type: "rssFeedInfo", | ||
contentDigest: createContentDigest(feedInfo) | ||
}; | ||
|
||
createNode(feedInfo); | ||
|
||
// Actually create nodes for RSS items | ||
preparedRssItemNodes.forEach(rssItemNode => createNode(rssItemNode)); | ||
} | ||
|
||
exports.sourceNodes = sourceNodes; |
This file contains 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 @@ | ||
// boop |
This file contains 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 @@ | ||
{ | ||
"name": "@amber1ey/gatsby-source-rss-feed", | ||
"private": true, | ||
"version": "1.0.0", | ||
"main": "index.js", | ||
"license": "MIT", | ||
"dependencies": { | ||
"rss-parser": "^3.7.2" | ||
} | ||
} |
This file contains 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,34 @@ | ||
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. | ||
# yarn lockfile v1 | ||
|
||
|
||
entities@^1.1.1: | ||
version "1.1.2" | ||
resolved "https://registry.yarnpkg.com/entities/-/entities-1.1.2.tgz#bdfa735299664dfafd34529ed4f8522a275fea56" | ||
integrity sha512-f2LZMYl1Fzu7YSBKg+RoROelpOaNrcGmE9AZubeDfrCEia483oW4MI4VyFd5VNHIgQ/7qm1I0wUHK1eJnn2y2w== | ||
|
||
rss-parser@^3.7.2: | ||
version "3.7.2" | ||
resolved "https://registry.yarnpkg.com/rss-parser/-/rss-parser-3.7.2.tgz#9f5b7d4944d4f7a190b469e31a8353aedb17c052" | ||
integrity sha512-kx0VIFelgwBk5qA4n32U6cx40anAU7TwlRXjyxLDFgMlg8/UcJ64x+Hj5oRX1Kjos+OeFGOmnd5YXH5ES+bmzg== | ||
dependencies: | ||
entities "^1.1.1" | ||
xml2js "^0.4.19" | ||
|
||
sax@>=0.6.0: | ||
version "1.2.4" | ||
resolved "https://registry.yarnpkg.com/sax/-/sax-1.2.4.tgz#2816234e2378bddc4e5354fab5caa895df7100d9" | ||
integrity sha512-NqVDv9TpANUjFm0N8uM5GxL36UgKi9/atZw+x7YFnQ8ckwFGKrl4xX4yWtrey3UJm5nP1kUbnYgLopqWNSRhWw== | ||
|
||
xml2js@^0.4.19: | ||
version "0.4.19" | ||
resolved "https://registry.yarnpkg.com/xml2js/-/xml2js-0.4.19.tgz#686c20f213209e94abf0d1bcf1efaa291c7827a7" | ||
integrity sha512-esZnJZJOiJR9wWKMyuvSE1y6Dq5LCuJanqhxslH2bxM6duahNZ+HMpCLhBQGZkbX6xRf8x1Y2eJlgt2q3qo49Q== | ||
dependencies: | ||
sax ">=0.6.0" | ||
xmlbuilder "~9.0.1" | ||
|
||
xmlbuilder@~9.0.1: | ||
version "9.0.7" | ||
resolved "https://registry.yarnpkg.com/xmlbuilder/-/xmlbuilder-9.0.7.tgz#132ee63d2ec5565c557e20f4c22df9aca686b10d" | ||
integrity sha1-Ey7mPS7FVlxVfiD0wi35rKaGsQ0= |
Oops, something went wrong.