Files
rpg-static-site/content/episodes/transcript-index.11ty.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

31 lines
1.0 KiB
JavaScript

import {parseText} from 'media-captions';
import Fetch from "@11ty/eleventy-fetch";
import path from 'path';
class SearchIndex {
data() {
return {eleventyExcludeFromCollections:["episode"], layout: null}
}
async render (data) {
const episodesWithTranscript = data.collections.episode.filter(e=>e.data.podcast?.transcriptUrl)
const promises = episodesWithTranscript.map((episode)=>{
const {transcriptUrl} = episode.data.podcast
return Fetch(transcriptUrl, {type:'text', duration: "1d"})
.then(srt_buffer=>parseText(srt_buffer.toString(), {type:'srt'}))
.then(({cues})=>cues)
.then((cues)=>({
name: path.basename(transcriptUrl,".srt"),
episode: episode.data.episode,
season: episode.data.season,
title: episode.data.title,
url: `${this.url(episode.url)}`,
cues: cues.map(({id, startTime, text})=>({id,startTime,text}))
}))
})
const result = await Promise.all(promises)
return JSON.stringify(result)
}
}
export default SearchIndex