export type EmbedParams = { conversation?: 'none'; cards?: 'hidden'; align?: 'center'|'right'; theme?: 'dark'; } export const extractIdFromUrl = (url: string) => { const match = url.match(/status\/([0-9]*)/); if (!match || !match.length) return; return match[0].replace('status/', ''); } const WIDGET_JS = ` window.twttr = (function(d, s, id) { var js, fjs = d.getElementsByTagName(s)[0], t = window.twttr || {}; if (d.getElementById(id)) return; js = d.createElement(s); js.id = id; js.src = "https://platform.twitter.com/widgets.js"; fjs.parentNode.insertBefore(js, fjs); t._e = []; t.ready = function(f) { t._e.push(f); }; return t; }(document, "script", "twitter-wjs")); `; export const tweetHtml = (params: EmbedParams, id?: number|string, url?: string) => { let _id = id; if (url && url.length) _id = extractIdFromUrl(url); if (!_id) return; return `
` }