Skip to content

Instantly share code, notes, and snippets.

@thebells1111
Last active June 6, 2021 20:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thebells1111/25fe0d318984815fdf02892815a2315a to your computer and use it in GitHub Desktop.
Save thebells1111/25fe0d318984815fdf02892815a2315a to your computer and use it in GitHub Desktop.
function exportOPML() {
let newOpml = jsonToXML(podcastList);
let file = new Blob([newOpml], { type: 'text/xml' });
let a = document.createElement('a');
a.href = URL.createObjectURL(file);
a.download = 'podcast.opml';
a.click();
a.remove();
$showOPML = false;
function escapeEntities(str) {
return str
.replace(/&/g, '&')
.replace(/</g, '&lt;')
.replace(/>/g, '&gt;')
.replace(/"/g, '&quot;')
.replace(/'/g, '&apos;');
}
function jsonToXML(json) {
return `<?xml version="1.0"?><opml version="1.0"><head><title>OPML exported from CurioCaster</title>
<dateCreated>${new Date()}</dateCreated><dateModified>${new Date()}</dateModified></head><body>${json.map(
(podcast) =>
`<outline text="${escapeEntities(
podcast.title
)}" type="rss" xmlUrl="${encodeURIComponent(podcast.url)}"/>`
)}</body></opml>`;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment