mirror of
https://github.com/Einundzwanzig-Podcast/einundzwanzig.space.git
synced 2025-12-13 16:26:50 +00:00
Add Podcasting 2.0 chapters
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
const { replacements, slugify, stripHTML, participantsWithAliases, participantToId, assetUrl, writeJSON } = require('../helpers')
|
||||
const { masterFeedUrl, publicFeedUrl, nodeId } = require('../content/meta.json')
|
||||
const { replacements, slugify, stripHTML, participantsWithAliases, participantToId, assetUrl, write, writeJSON } = require('../helpers')
|
||||
const { masterFeedUrl, publicFeedUrl, nodeId, title: podcastName } = require('../content/meta.json')
|
||||
const participantsRaw = require('../content/participants.json')
|
||||
const request = require('sync-request')
|
||||
const { XMLParser } = require('fast-xml-parser')
|
||||
@@ -125,7 +125,8 @@ const parseEpisode = e => {
|
||||
const episode = parseEpisode(item)
|
||||
episodes.push(episode)
|
||||
|
||||
const link = `https://einundzwanzig.space/podcast/${episode.slug}`
|
||||
const episodePath = `podcast/${episode.slug}`
|
||||
const link = `https://einundzwanzig.space/${episodePath}`
|
||||
let { description, descriptionPlain } = episode
|
||||
if (index > 20) {
|
||||
description = `Shownotes: ${link}`
|
||||
@@ -203,6 +204,27 @@ const parseEpisode = e => {
|
||||
})
|
||||
}
|
||||
|
||||
// chapters
|
||||
const chapterInfo = descriptionPlain.match(/(\d{1,2}:\d{2}:\d{2})\s(.*)/g)
|
||||
if (chapterInfo) {
|
||||
try {
|
||||
const chapters = chapterInfo.map(chapter => {
|
||||
const [_, hms, title] = chapter.match(/(\d{1,2}:\d{2}:\d{2})\s(.*)/)
|
||||
const [h, m, s] = hms.split(':')
|
||||
const startTime = parseInt(h) * 3600 + parseInt(m) * 60 + parseInt(s)
|
||||
return { startTime, title }
|
||||
})
|
||||
const chapterData = { version: '1.2.0', podcastName, title: episode.title, chapters }
|
||||
write(`dist/${episodePath}/chapters.json`, JSON.stringify(chapterData, null, 2))
|
||||
updated['podcast:chapters'] = {
|
||||
__attr: { url: `${link}/chapters.json`, type: 'application/json+chapters' }
|
||||
}
|
||||
}
|
||||
catch (e) {
|
||||
console.error('Error generating chapters for', episode.slug, chapterInfo)
|
||||
}
|
||||
}
|
||||
|
||||
return updated
|
||||
})
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
const pug = require('pug')
|
||||
const { mkdirSync, writeFileSync } = require('fs')
|
||||
const { dirname, resolve } = require('path')
|
||||
const { resolve } = require('path')
|
||||
const { write } = require('../helpers')
|
||||
const { slugify, participantsWithAliases, participantToId } = require('../helpers')
|
||||
const config = require('../pug.config')
|
||||
const site = require('../generated/site-data.json')
|
||||
@@ -37,11 +37,8 @@ const renderPage = (template, out, data = {}) => {
|
||||
const file = resolve(__dirname, '..', templateFile)
|
||||
const options = Object.assign({}, config, { site }, data, { pagePath })
|
||||
const rendered = pug.renderFile(file, options)
|
||||
const dst = resolve(__dirname, '..', 'dist', dest)
|
||||
const dir = dirname(dst)
|
||||
|
||||
mkdirSync(dir, { recursive: true })
|
||||
writeFileSync(dst, rendered)
|
||||
write(`dist/${dest}`, rendered)
|
||||
}
|
||||
|
||||
renderPage('index', 'index', { navCurrent: 'index', currentEpisode: episodes[0], participants })
|
||||
|
||||
Reference in New Issue
Block a user