diff --git a/src/__tests__/pages/feed.xml.test.ts b/src/__tests__/pages/feed.xml.test.ts index 559ece999..0276ff79d 100644 --- a/src/__tests__/pages/feed.xml.test.ts +++ b/src/__tests__/pages/feed.xml.test.ts @@ -127,7 +127,16 @@ describe('feed.xml', () => { const item = options.items[0]; expect(item.title).toBe('My Post'); expect(item.description).toBe('Post description'); - expect(item.content).toBe('
Rendered HTML
'); + // Content is framed: a "new post" lead-in, the rendered body, and a book CTA. + expect(item.content).toContain('Rendered HTML
'); + expect(item.content).toContain('A new post from'); + expect(item.content).toContain(siteConfig.bookUrl); + expect(item.content.indexOf('A new post from')).toBeLessThan( + item.content.indexOf('Rendered HTML
'), + ); + expect(item.content.indexOf('Rendered HTML
')).toBeLessThan( + item.content.indexOf(siteConfig.bookUrl), + ); expect(item.link).toBe('https://ben.balter.com/2024/06/15/my-post/'); expect(item.author).toBe(siteConfig.email); expect(item.pubDate).toBeInstanceOf(Date); diff --git a/src/pages/feed.xml.ts b/src/pages/feed.xml.ts index 11e8fcddc..492d1f112 100644 --- a/src/pages/feed.xml.ts +++ b/src/pages/feed.xml.ts @@ -18,6 +18,57 @@ import { sharedShikiConfig, } from '../lib/markdown-pipeline'; +// Escape a raw ampersand for use inside HTML (feed content is delivered as HTML, +// e.g. rendered by Kit into email). Only the book title needs it today. +const bookTitle = siteConfig.bookTitle.replace(/&/g, '&'); + +/** + * A short framing line prepended to each feed item so email subscribers (and + * RSS readers) immediately know this is a new post on ben.balter.com and can + * jump to the canonical web version. The raw post body starts mid-thought + * otherwise — fine in context, disorienting as the first line of an email. + */ +function leadInHtml(link: string): string { + return ( + `` + + `A new post from ben.balter.com` + + ` · Read it on the web →` + + `
` + ); +} + +/** + * A plain, inline-styled book callout appended to each feed item. The site's + *| ` +
+ ` Coming ${siteConfig.bookLaunch} ` + + `${headline} ` + + `${siteConfig.bookDescription}. ` + + `Get notified when it launches →` + + ` |