2023-04-09 11:25:12 +01:00
import MarkdownIt from 'markdown-it' ;
2023-04-17 23:23:35 +01:00
import _ from 'lodash' ;
2022-10-07 09:14:10 +01:00
import rss from '@astrojs/rss' ;
2023-04-09 11:25:12 +01:00
import sanitizeHtml from 'sanitize-html' ;
import { getCollection } from 'astro:content' ;
2022-10-07 09:14:10 +01:00
2023-04-09 11:25:12 +01:00
export async function get ( ) {
const emails = await getCollection ( 'daily-email' ) ;
2022-10-13 00:15:24 +01:00
2023-04-09 11:25:12 +01:00
const sortedEmails = Object . values ( emails )
. sort ( ( a , b ) =>
new Date ( b . data . pubDate ) . valueOf ( ) -
new Date ( a . data . pubDate ) . valueOf ( )
) ;
const parser = new MarkdownIt ( ) ;
2023-04-17 23:05:00 +01:00
const callToAction = ( ) => {
return _ . sample ( [
'Do you need help or want another pair of eyes on your code? Book a <a href="https://www.oliverdavies.uk/call">1-on-1 consulting call</a> or an <a href="https://www.oliverdavies.uk/pair">online pair programming session</a> with a 100% money-back guarantee.' ,
'If you\'re creating a new Drupal module, try my <a href="https://github.com/opdavies/drupal-module-template">free Drupal module template</a>.' ,
] ) ;
} ;
2023-04-09 11:25:12 +01:00
return rss ( {
2022-10-13 08:40:06 +01:00
title : 'Daily email list' ,
2022-10-13 00:15:24 +01:00
description : 'A daily newsletter on software development, DevOps, community, and open-source.' ,
site : import . meta . env . SITE ,
2023-04-09 11:25:12 +01:00
items : sortedEmails . slice ( 0 , 1 ) . map ( ( email ) => ( {
2023-04-17 23:05:00 +01:00
description : `
< div style = "max-width: 550px;" >
$ { sanitizeHtml ( parser . render ( email . body ) ) }
< hr / >
< p > P . S . $ { callToAction ( ) } < / p >
< / d i v >
` ,
2023-04-09 11:25:12 +01:00
link : ` ${ import . meta . env . SITE } / ${ email . data . permalink } ` ,
pubDate : email . data . pubDate ,
2023-04-16 13:12:58 +01:00
title : ` ${ email . data . title } ` ,
customData : ` <tags> ${ email . data . tags . map ( tag => ` <tag># ${ tag } </tag> ` ) } </tags> ` ,
2022-10-13 00:15:24 +01:00
} ) )
} ) ;
2023-04-09 11:25:12 +01:00
} ;