Last active
June 6, 2021 20:42
-
-
Save thebells1111/25fe0d318984815fdf02892815a2315a to your computer and use it in GitHub Desktop.
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
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, '<') | |
.replace(/>/g, '>') | |
.replace(/"/g, '"') | |
.replace(/'/g, '''); | |
} | |
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