Files
rpg-static-site/content/episodes/episodes.11tydata.js
Anthony Correa 27eb1e634c feat: improve Markdown support and add transcript search functionality
- Add `.cache` to `.gitignore` for temporary build files.
- Introduce Markdown snippets for creating Season 1 and Season 5 show notes in `.vscode/markdown.code-snippets`.
- Update `.vscode/settings.json`:
  - Exclude `node_modules` directory.
  - Adjust quick suggestions to disable them for comments, strings, and others.
- Remove unnecessary `console.log` statements from `episodes.11tydata.js`.
- Add an image file `content/episodes/image.jpg`.
- Implement a transcript search feature:
  - Add `search-transcripts.hbs` to enable searching transcript cues with time markers.
  - Add `transcript-index.11ty.js` to generate a searchable transcript index.
- Update `search-index.11ty.js` to skip processing `<hr>` and `<img>` tags.
- Enhance episode layout with `startAt` query parameter to allow audio playback from a specific time.
- Add a new dependency:
  - `@11ty/eleventy-fetch` for fetching transcripts.
  - `media-captions` for parsing and handling transcript files.
- Update package-lock.json and package.json to include new dependencies.
2024-12-24 12:07:32 -06:00

81 lines
2.3 KiB
JavaScript

const {seasonEpisodeFormat, episodeNumber} = require('../../utils/filters');
const fs = require('fs/promises');
path = require('path')
module.exports = {
"layout": "episode",
"tags":['episode'],
"eleventyComputed": {
"episode": "{{page.fileSlug | episodeNumber: episode}}",
"image": async (data) => {
const image_locations_promises = [
data.image,
`${data.page.filePathStem}.jpg`,
`${data.page.filePathStem}.png`,
'../image.jpg',
'../image.png',
'../../image.jpg',
'../../image.png'
].filter(image_path=>image_path).map((image_path)=>
fs.access(path.resolve(data.page.inputPath, image_path))
.then(()=>path.resolve(data.page.filePathStem, image_path))
.catch(()=>null)
)
return (await Promise.all(image_locations_promises)).find(i=>i)
},
"podcast": podcastData
}
}
async function podcastData (data) {
var file_stem
if (data.season === 1) {
file_stem = `ep${data.episode}`
} else {
file_stem = `${seasonEpisodeFormat(null, data).toLowerCase()}`
}
const mp3_exists_promise = new Promise ((resolve, reject) => {
if (data.podcast.enclosureUrl) {
resolve(data.podcast.enclosureUrl)
} else {
const url = `${data.site.cdn}/${file_stem}.mp3`
fetch(url, { method: "HEAD" })
.then((res)=>{
if (res.ok) {
resolve(`${url}`)
} else {
reject(new Error(`No file at ${url}`));
}
})
}
}).catch((e)=>{return null})
const transcript_exists_promise = new Promise ((resolve, reject) => {
if (data.podcast.transcriptUrl) {
resolve(data.podcast.transcriptUrl)
} else {
const url = `${data.site.cdn}/${file_stem}.srt`
fetch(url, { method: "HEAD" })
.then((res)=>{
if (res.ok) {
resolve(`${url}`)
} else {
reject(new Error(`No file at ${url}`));
}
})
}
}).catch((e)=>{return null})
const result = {
"enclosureUrl": await mp3_exists_promise,
"transcriptUrl": await transcript_exists_promise,
"title": data.podcast.title || `${seasonEpisodeFormat(null, data)}: ${data.title || "Episode " + data.episode}`,
"image" : data.podcast.image || data.image
}
if (result.enclosureUrl != null) {
return result
} else {
return false
}
}