const { convert } = require('html-to-text');

class SearchIndex {
  data() {
    return {eleventyExcludeFromCollections:["episode"], layout: null}
  }

  render (data) {
    const documents = data.collections.episode.map((episode)=>{
    return {
      url:`${this.url(episode.url)}`,
      title: episode.data.title,
      text: convert (episode.content, {
        selectors: [
          { selector: 'hr', format: 'skip' },
          { selector: 'img', format: 'skip'}
        ]
      }),
      season: episode.data.season,
      episode: episode.data.episode
    }})
    return JSON.stringify(documents);
  }
}

module.exports = SearchIndex