├── .gitignore ├── test └── test.js ├── .eleventy.js ├── TransistorFm.js ├── package.json └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | .env 3 | .cache 4 | package-lock.json -------------------------------------------------------------------------------- /test/test.js: -------------------------------------------------------------------------------- 1 | const test = require("ava"); 2 | const TransistorFm = require("../TransistorFm"); 3 | // require('dotenv').config(); 4 | 5 | test("Starter", async t => { 6 | let episodes = await TransistorFm(); 7 | t.true(episodes.length > 0); 8 | t.truthy(episodes[0].title); 9 | t.truthy(episodes[0].summary); 10 | t.truthy(episodes[0].url); 11 | }); -------------------------------------------------------------------------------- /.eleventy.js: -------------------------------------------------------------------------------- 1 | const TransistorFm = require("./TransistorFm"); 2 | const pkg = require("./package.json"); 3 | 4 | require('dotenv').config(); 5 | 6 | module.exports = function(eleventyConfig, options = {}) { 7 | try { 8 | eleventyConfig.versionCheck(pkg["11ty"].compatibility); 9 | } catch(e) { 10 | console.log( `WARN: Eleventy Plugin (${pkg.name}) Compatibility: ${e.message}` ); 11 | } 12 | 13 | let opts = Object.assign({ 14 | envApiKey: "TRANSISTOR_FM_API_KEY", 15 | envApiKeyRequired: false, 16 | data: "transistorfm.episodes", 17 | }, options); 18 | 19 | let apiKey = process.env[opts.envApiKey]; 20 | if(opts.envApiKeyRequired && !apiKey) { 21 | throw new Error(`The environment variable ${opts.envApiKey} is missing. Do you have an .env file?`) 22 | } 23 | 24 | eleventyConfig.addGlobalData(opts.data, async function() { 25 | return TransistorFm({ 26 | apiKey 27 | }); 28 | }); 29 | }; -------------------------------------------------------------------------------- /TransistorFm.js: -------------------------------------------------------------------------------- 1 | const EleventyFetch = require("@11ty/eleventy-fetch"); 2 | 3 | module.exports = async function(options = {}) { 4 | let { apiKey } = options; 5 | 6 | const request = await EleventyFetch('https://api.transistor.fm/v1/episodes', { 7 | duration: "1d", 8 | type: "json", 9 | fetchOptions: { 10 | headers: { 11 | "X-API-KEY": apiKey 12 | } 13 | } 14 | }) 15 | 16 | const data = request.data.filter(episode => { 17 | return episode.attributes.status === "published"; 18 | }).map(episode => { 19 | const { attributes } = episode; 20 | return { 21 | title: attributes.title, 22 | meta: { 23 | date: attributes.formatted_published_at, 24 | duration: attributes.duration_in_mmss.slice(0, 2) + " minutes", 25 | season: attributes.season, 26 | episode: attributes.number, 27 | }, 28 | summary: attributes.formatted_summary, 29 | url: attributes.share_url, 30 | media: `${attributes.media_url}?src=site`, 31 | download: `${attributes.media_url}?download=true&src=site`, 32 | full_description: attributes.description, 33 | } 34 | }); 35 | 36 | return data; 37 | } -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@11ty/eleventy-data-transistor-fm", 3 | "version": "1.1.0", 4 | "description": "An Eleventy data plugin for transistor.fm episodes.", 5 | "publishConfig": { 6 | "access": "public" 7 | }, 8 | "scripts": { 9 | "test": "ava" 10 | }, 11 | "main": ".eleventy.js", 12 | "repository": { 13 | "type": "git", 14 | "url": "git+https://github.com/11ty/eleventy-data-transistor-fm.git" 15 | }, 16 | "funding": { 17 | "type": "opencollective", 18 | "url": "https://opencollective.com/11ty" 19 | }, 20 | "keywords": [ 21 | "eleventy", 22 | "eleventy-data", 23 | "eleventy-plugin" 24 | ], 25 | "author": { 26 | "name": "Zach Leatherman", 27 | "email": "zachleatherman@gmail.com", 28 | "url": "https://zachleat.com/" 29 | }, 30 | "license": "MIT", 31 | "bugs": { 32 | "url": "https://github.com/11ty/eleventy-data-transistor-fm/issues" 33 | }, 34 | "homepage": "https://github.com/11ty/eleventy-data-transistor-fm/", 35 | "11ty": { 36 | "compatibility": ">=0.12 || >= 1" 37 | }, 38 | "dependencies": { 39 | "@11ty/eleventy-fetch": "^3.0.0", 40 | "dotenv": "^10.0.0" 41 | }, 42 | "devDependencies": { 43 | "ava": "^3.15.0" 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Eleventy Data Plugin: Transistor.fm 2 | 3 | API Docs: https://developers.transistor.fm/#episodes 4 | 5 | ## Installation: 6 | 7 | ```sh 8 | npm install @11ty/eleventy-data-transistor-fm 9 | ``` 10 | 11 | ## Usage 12 | 13 | ```js 14 | const TransistorFmPlugin = require("@11ty/eleventy-data-transistor-fm"); 15 | 16 | module.exports = function(eleventyConfig) { 17 | eleventyConfig.addPlugin(TransistorFmPlugin); 18 | }; 19 | ``` 20 | 21 | ### In a template 22 | 23 | By default, the episodes are stored in `transistorfm.episodes` (this is configurable). 24 | 25 | ``` 26 | {% for episode in transistorfm.episodes %} 27 | {{ episode.title }} 28 | {% endfor %} 29 | ``` 30 | 31 | ### Use with an API key 32 | 33 | By default, a Transistor FM API key is optional. If you want to use one, create a `.env` file and add an entry for `TRANSISTOR_FM_API_KEY`: 34 | 35 | ``` 36 | TRANSISTOR_FM_API_KEY=This is my key 37 | ``` 38 | 39 | You can make the key required or even change the name of the environment variable by passing options to your plugin. 40 | 41 | 42 | ### Pass in options 43 | 44 | 45 | ```js 46 | const TransistorFmPlugin = require("@11ty/eleventy-data-transistor-fm"); 47 | 48 | module.exports = function(eleventyConfig) { 49 | eleventyConfig.addPlugin(TransistorFmPlugin, { 50 | envApiKey: "TRANSISTOR_FM_API_KEY", // the name of the environment variable for the API key 51 | 52 | envApiKeyRequired: false, // fail if the environment variable is missing? 53 | 54 | data: "transistorfm.episodes", // where in Eleventy to store the return data 55 | }); 56 | }; 57 | ``` 58 | 59 | --------------------------------------------------------------------------------