#How to add HTML content to RSS feed?

3 messages · Page 1 of 1 (latest)

manic owl
#

Hi, I'm trying to show a preview of the HTML content in my RSS feed.

How do I do that?

Here's my attempt using description and encodeHTML...

import rss from '@astrojs/rss';
import { encodeHTML } from 'entities'
import { SITE_TITLE, SITE_DESCRIPTION } from '../config.ts'
import { sortedPosts } from '@/js/util.js'

// https://docs.astro.build/en/guides/rss/#2-list-of-rss-feed-objects
const postImportResult = import.meta.glob('../wordpress/**/*.{md,mdx}', { eager: true })
const posts = sortedPosts(Object.values(postImportResult))

export const get = () =>
  rss({
    stylesheet: '/rss/pretty-feed-v3.xsl',
    title: SITE_TITLE,
    description: SITE_DESCRIPTION,
    site: import.meta.env.SITE,
    items: posts.map((post) => ({
      link: post.frontmatter.permalink,
      title: post.frontmatter.title,
      pubDate: post.frontmatter.date,
      description: encodeHTML(post.compiledContent())
        .slice(0, 1000)
        .split(' ')
        .slice(0, 46) // about 46 words
        .join(' ') + '...'
    }))
  })
#

How to add HTML content to RSS feed?

#

Figured it out!

You simply pass in the compiledContent()! No need to encode the HTML entities! 😄