UNPKG

gatsby-remark-embedder

Version:

Gatsby Remark plugin to embed well known services by their URL.

32 lines (31 loc) 1.19 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.shouldTransform = exports.getSpotifyIFrameSrc = exports.getHTML = void 0; var _utils = require("./utils"); const shouldTransform = url => { const { host, pathname } = new URL(url); return host === 'open.spotify.com' && !(0, _utils.includesSomeOfArray)(pathname, ['embed', 'embed-podcast']) && (0, _utils.includesSomeOfArray)(pathname, ['/album/', '/artist/', '/episode/', '/show/', '/track/', '/playlist/']); }; exports.shouldTransform = shouldTransform; const getSpotifyIFrameSrc = urlString => { const { pathname } = new URL(urlString); const type = pathname.split('/')[1].toLowerCase(); const podcastTypes = ['episode', 'show']; if (podcastTypes.includes(type)) { return urlString.replace(type, `embed-podcast/${type}`); } return urlString.replace(type, `embed/${type}`); }; exports.getSpotifyIFrameSrc = getSpotifyIFrameSrc; const getHTML = url => { const iframeSrc = getSpotifyIFrameSrc(url); return `<iframe src="${iframeSrc}" width="100%" height="380" frameborder="0" allowtransparency="true" allow="encrypted-media"></iframe>`; }; exports.getHTML = getHTML;