mirror of
https://github.com/Einundzwanzig-Podcast/einundzwanzig.space.git
synced 2025-12-14 00:36:48 +00:00
📰 Replace links in feed
This commit is contained in:
@@ -14,10 +14,16 @@ const slugify = str => str.toLowerCase()
|
|||||||
.replace(/\s+/g, '-').replace(/[^\w\-]+/g, '')
|
.replace(/\s+/g, '-').replace(/[^\w\-]+/g, '')
|
||||||
.replace(/\-\-+/g, '-').replace(/^-+/, '').replace(/-+$/, '')
|
.replace(/\-\-+/g, '-').replace(/^-+/, '').replace(/-+$/, '')
|
||||||
|
|
||||||
|
const parseBaseInfoFromMatch = m => {
|
||||||
|
let [, categoryName = 'News', number, titlePlain] = m ? m : [,,,]
|
||||||
|
if (!number) categoryName = 'Verschiedenes'
|
||||||
|
if (categoryName === 'Der-Weg') categoryName = 'Der Weg'
|
||||||
|
return { categoryName, number, titlePlain }
|
||||||
|
}
|
||||||
|
|
||||||
const parseInfo = e => {
|
const parseInfo = e => {
|
||||||
const titleMatch = e.title.match(/([\w\s]+?)?\s?#(\d+) - (.*)/)
|
const titleMatch = e.title.match(/([\w\s]+?)?\s?#(\d+) - (.*)/)
|
||||||
let [, categoryName = 'News', number, titlePlain] = titleMatch ? titleMatch : [,,,e.title]
|
const { categoryName, number, titlePlain } = parseBaseInfoFromMatch(titleMatch)
|
||||||
if (!number) categoryName = 'Verschiedenes'
|
|
||||||
const blockMatch = e.contentSnippet.match(/Blockzeit\s(\d+)/)
|
const blockMatch = e.contentSnippet.match(/Blockzeit\s(\d+)/)
|
||||||
const block = blockMatch ? parseInt(blockMatch[1]) : null
|
const block = blockMatch ? parseInt(blockMatch[1]) : null
|
||||||
const category = slugify(categoryName)
|
const category = slugify(categoryName)
|
||||||
@@ -61,4 +67,15 @@ const parseInfo = e => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
writeJSON('episodes', episodes)
|
writeJSON('episodes', episodes)
|
||||||
|
|
||||||
|
// Original Anchor-Feed
|
||||||
|
const updated = xml
|
||||||
|
.replace(/<link>(https:\/\/anchor\.fm\/einundzwanzig\/episodes\/(.*?))<\/link>/gi, (match, url, anchorSlug) => {
|
||||||
|
const slugMatch = anchorSlug.match(/^(?:(.*)-)?([0-9]+?)---/)
|
||||||
|
const { categoryName, number } = parseBaseInfoFromMatch(slugMatch)
|
||||||
|
const episode = slugMatch ? episodes.find(e => e.categoryName == categoryName && e.number === number) : null
|
||||||
|
const link = episode ? `https://einundzwanzig.space/podcast/${episode.slug}` : url
|
||||||
|
return `<link>${link}</link>`
|
||||||
|
})
|
||||||
|
write('dist/feed.xml', updated)
|
||||||
})()
|
})()
|
||||||
|
|||||||
Reference in New Issue
Block a user