11// eslint-disable-next-line import/no-extraneous-dependencies
22import RSS from 'rss' ;
33import { getPageMap } from '@theguild/components/server' ;
4- import { AuthorId , authors } from '../../../authors' ;
5- import { BlogFrontmatter , isBlogPost } from '../blog-types' ;
4+ import { Author , AuthorId , authors } from '../../../authors' ;
5+ import { CaseStudyFile } from '../../case-studies/case-study-types' ;
6+ import { coerceCaseStudiesToBlogs } from '../../case-studies/coerce-case-studies-to-blogs' ;
7+ import { isCaseStudy } from '../../case-studies/isCaseStudyFile' ;
8+ import { BlogFrontmatter , BlogPostFile , isBlogPost } from '../blog-types' ;
69
710function getAuthor ( frontmatterAuthors : BlogFrontmatter [ 'authors' ] ) : string {
811 const first = Array . isArray ( frontmatterAuthors ) ? frontmatterAuthors [ 0 ] : frontmatterAuthors ;
@@ -16,23 +19,32 @@ function getAuthor(frontmatterAuthors: BlogFrontmatter['authors']): string {
1619}
1720
1821export async function GET ( ) {
19- const [ _meta , _indexPage , ...pageMap ] = await getPageMap ( '/blog' ) ;
20- const allPosts = pageMap
21- . filter ( isBlogPost )
22- . map (
23- item =>
24- ( {
22+ let allPosts : RSS . ItemOptions [ ] = [ ] ;
23+
24+ const [ , , ...blogs ] = await getPageMap ( '/blog' ) ;
25+ const [ , , ...studies ] = await getPageMap ( '/case-studies' ) ;
26+ const [ , , ...updates ] = await getPageMap ( '/product-updates' ) ;
27+
28+ const studiesAsBlogs = coerceCaseStudiesToBlogs ( studies . filter ( isCaseStudy ) ) ;
29+
30+ for ( const items of [ blogs . filter ( isBlogPost ) , updates . filter ( isBlogPost ) , studiesAsBlogs ] ) {
31+ allPosts = allPosts . concat (
32+ items . map (
33+ ( item ) : RSS . ItemOptions => ( {
2534 title : item . frontMatter . title ,
2635 date : new Date ( item . frontMatter . date ) ,
2736 url : `https://the-guild.dev/graphql/hive${ item . route } ` ,
28- description : ( item . frontMatter as any ) . description ?? '' ,
37+ description : item . frontMatter . description ?? '' ,
2938 author : getAuthor ( item . frontMatter . authors ) ,
3039 categories : Array . isArray ( item . frontMatter . tags )
3140 ? item . frontMatter . tags
3241 : [ item . frontMatter . tags ] ,
33- } ) satisfies RSS . ItemOptions ,
34- )
35- . sort ( ( a , b ) => b . date . getTime ( ) - a . date . getTime ( ) ) ;
42+ } ) ,
43+ ) ,
44+ ) ;
45+ }
46+
47+ allPosts = allPosts . sort ( ( a , b ) => new Date ( b . date ) . getTime ( ) - new Date ( a . date ) . getTime ( ) ) ;
3648
3749 const feed = new RSS ( {
3850 title : 'Hive Blog' ,
0 commit comments