mirror of
https://github.com/Einundzwanzig-Podcast/einundzwanzig.space.git
synced 2025-12-11 15:26:50 +00:00
Add Podcasting 2.0 chapters
This commit is contained in:
17
helpers.js
17
helpers.js
@@ -1,6 +1,6 @@
|
|||||||
const { decode, encode } = require('html-entities')
|
const { decode, encode } = require('html-entities')
|
||||||
const { writeFileSync } = require('fs')
|
const { mkdirSync, writeFileSync } = require('fs')
|
||||||
const { join, resolve } = require('path')
|
const { dirname, join, resolve } = require('path')
|
||||||
const meta = require('./content/meta.json')
|
const meta = require('./content/meta.json')
|
||||||
const dir = resolve(__dirname, '.')
|
const dir = resolve(__dirname, '.')
|
||||||
|
|
||||||
@@ -24,7 +24,12 @@ const HOST = IS_DEV ? 'http://localhost:3000' : 'https://einundzwanzig.space'
|
|||||||
|
|
||||||
// replacements
|
// replacements
|
||||||
const replacements = str => str && str.replace(/<\/?u>/g, '').replace(meta.tallycoinUrl, meta.shoutoutUrl)
|
const replacements = str => str && str.replace(/<\/?u>/g, '').replace(meta.tallycoinUrl, meta.shoutoutUrl)
|
||||||
const stripHTML = str => str && encode(decode(str.replace(/(<([^>]+)>)/ig, '').trim().replace(/\n\s*/g, '\n')), { level: 'xml' })
|
const stripHTML = str => str && encode(decode(str
|
||||||
|
.replace(/<br(\s?\/?)>/g, '\n')
|
||||||
|
.replace(/<\/(p|ul|ol)>/g, '\n\n')
|
||||||
|
.replace(/(<([^>]+)>)/ig, '')
|
||||||
|
.trim()
|
||||||
|
.replace(/\n\s*/g, '\n')), { level: 'xml' })
|
||||||
|
|
||||||
// meetups
|
// meetups
|
||||||
const toMeetupMapInfo = m => {
|
const toMeetupMapInfo = m => {
|
||||||
@@ -89,7 +94,11 @@ const assetUrl = (path, protocol = 'https') => {
|
|||||||
return url
|
return url
|
||||||
}
|
}
|
||||||
|
|
||||||
const write = (name, data) => writeFileSync(join(dir, name), data)
|
const write = (name, data) => {
|
||||||
|
const dst = join(dir, name)
|
||||||
|
mkdirSync(dirname(dst), { recursive: true })
|
||||||
|
writeFileSync(dst, data)
|
||||||
|
}
|
||||||
const writeJSON = (name, data) => write(`generated/${name}.json`, JSON.stringify(data, null, 2))
|
const writeJSON = (name, data) => write(`generated/${name}.json`, JSON.stringify(data, null, 2))
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
|
|||||||
6
package-lock.json
generated
6
package-lock.json
generated
@@ -1053,9 +1053,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/caniuse-lite": {
|
"node_modules/caniuse-lite": {
|
||||||
"version": "1.0.30001660",
|
"version": "1.0.30001701",
|
||||||
"resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001660.tgz",
|
"resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001701.tgz",
|
||||||
"integrity": "sha512-GacvNTTuATm26qC74pt+ad1fW15mlQ/zuTzzY1ZoIzECTP8HURDfF43kNxPgf7H1jmelCBQTTbBNxdSXOA7Bqg==",
|
"integrity": "sha512-faRs/AW3jA9nTwmJBSO1PQ6L/EOgsB5HMQQq4iCu5zhPgVVgO/pZRHlmatwijZKetFw8/Pr4q6dEN8sJuq8qTw==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"funding": [
|
"funding": [
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
const { replacements, slugify, stripHTML, participantsWithAliases, participantToId, assetUrl, writeJSON } = require('../helpers')
|
const { replacements, slugify, stripHTML, participantsWithAliases, participantToId, assetUrl, write, writeJSON } = require('../helpers')
|
||||||
const { masterFeedUrl, publicFeedUrl, nodeId } = require('../content/meta.json')
|
const { masterFeedUrl, publicFeedUrl, nodeId, title: podcastName } = require('../content/meta.json')
|
||||||
const participantsRaw = require('../content/participants.json')
|
const participantsRaw = require('../content/participants.json')
|
||||||
const request = require('sync-request')
|
const request = require('sync-request')
|
||||||
const { XMLParser } = require('fast-xml-parser')
|
const { XMLParser } = require('fast-xml-parser')
|
||||||
@@ -125,7 +125,8 @@ const parseEpisode = e => {
|
|||||||
const episode = parseEpisode(item)
|
const episode = parseEpisode(item)
|
||||||
episodes.push(episode)
|
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
|
let { description, descriptionPlain } = episode
|
||||||
if (index > 20) {
|
if (index > 20) {
|
||||||
description = `Shownotes: ${link}`
|
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
|
return updated
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
const pug = require('pug')
|
const pug = require('pug')
|
||||||
const { mkdirSync, writeFileSync } = require('fs')
|
const { resolve } = require('path')
|
||||||
const { dirname, resolve } = require('path')
|
const { write } = require('../helpers')
|
||||||
const { slugify, participantsWithAliases, participantToId } = require('../helpers')
|
const { slugify, participantsWithAliases, participantToId } = require('../helpers')
|
||||||
const config = require('../pug.config')
|
const config = require('../pug.config')
|
||||||
const site = require('../generated/site-data.json')
|
const site = require('../generated/site-data.json')
|
||||||
@@ -37,11 +37,8 @@ const renderPage = (template, out, data = {}) => {
|
|||||||
const file = resolve(__dirname, '..', templateFile)
|
const file = resolve(__dirname, '..', templateFile)
|
||||||
const options = Object.assign({}, config, { site }, data, { pagePath })
|
const options = Object.assign({}, config, { site }, data, { pagePath })
|
||||||
const rendered = pug.renderFile(file, options)
|
const rendered = pug.renderFile(file, options)
|
||||||
const dst = resolve(__dirname, '..', 'dist', dest)
|
|
||||||
const dir = dirname(dst)
|
|
||||||
|
|
||||||
mkdirSync(dir, { recursive: true })
|
write(`dist/${dest}`, rendered)
|
||||||
writeFileSync(dst, rendered)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
renderPage('index', 'index', { navCurrent: 'index', currentEpisode: episodes[0], participants })
|
renderPage('index', 'index', { navCurrent: 'index', currentEpisode: episodes[0], participants })
|
||||||
|
|||||||
Reference in New Issue
Block a user