Skip to content

Commit e6fecff

Browse files
committed
Show case studies and product updates in feed
1 parent 8cef61e commit e6fecff

File tree

4 files changed

+53
-34
lines changed

4 files changed

+53
-34
lines changed

packages/web/docs/src/app/blog/blog-types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ export interface BlogFrontmatter {
1212
featured?: boolean;
1313
image?: VideoPath | StaticImageData;
1414
thumbnail?: StaticImageData;
15+
description?: string;
1516
}
1617

1718
type VideoPath = `${string}.${'webm' | 'mp4'}`;

packages/web/docs/src/app/blog/feed.xml/route.ts

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
// eslint-disable-next-line import/no-extraneous-dependencies
22
import RSS from 'rss';
33
import { 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

710
function 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

1821
export 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',
Lines changed: 7 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
import { getPageMap } from '@theguild/components/server';
2-
import type { Author } from '../../authors';
3-
import { CaseStudyFile } from '../case-studies/case-study-types';
2+
import { coerceCaseStudiesToBlogs } from '../case-studies/coerce-case-studies-to-blogs';
43
import { getCaseStudies } from '../case-studies/get-case-studies';
5-
import { BlogFrontmatter, BlogPostFile, isBlogPost } from './blog-types';
4+
import { isBlogPost } from './blog-types';
65
import { NewsletterFormCard } from './components/newsletter-form-card';
76
import { PostsByTag } from './components/posts-by-tag';
87
// We can't move this page to `(index)` dir together with `tag` page because Nextra crashes for
@@ -16,10 +15,14 @@ export const metadata = {
1615

1716
export default async function BlogPage() {
1817
const [_meta, _indexPage, ...pageMap] = await getPageMap('/blog');
18+
const [, , ...productUpdates] = await getPageMap('/product-updates');
1919

2020
const caseStudies = await getCaseStudies().then(coerceCaseStudiesToBlogs);
2121

22-
const allPosts = pageMap.filter(isBlogPost).concat(caseStudies);
22+
const allPosts = pageMap
23+
.filter(isBlogPost)
24+
.concat(caseStudies)
25+
.concat(productUpdates.filter(isBlogPost));
2326

2427
return (
2528
<BlogPageLayout>
@@ -29,21 +32,3 @@ export default async function BlogPage() {
2932
</BlogPageLayout>
3033
);
3134
}
32-
33-
function coerceCaseStudiesToBlogs(caseStudies: CaseStudyFile[]): BlogPostFile[] {
34-
return caseStudies.map(caseStudy => ({
35-
...caseStudy,
36-
frontMatter: {
37-
...caseStudy.frontMatter,
38-
tags: ['Case Study'],
39-
authors: caseStudy.frontMatter.authors.map(
40-
(author): Author => ({
41-
name: author.name,
42-
avatar: author.avatar,
43-
link: '' as 'https://',
44-
github: '',
45-
}),
46-
),
47-
} satisfies BlogFrontmatter,
48-
}));
49-
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { Author } from '../../authors';
2+
import { BlogFrontmatter, BlogPostFile } from '../blog/blog-types';
3+
import { CaseStudyFile } from './case-study-types';
4+
5+
export function coerceCaseStudiesToBlogs(caseStudies: CaseStudyFile[]): BlogPostFile[] {
6+
return caseStudies.map(caseStudy => ({
7+
...caseStudy,
8+
frontMatter: {
9+
...caseStudy.frontMatter,
10+
tags: ['Case Study'],
11+
authors: caseStudy.frontMatter.authors.map(
12+
(author): Author => ({
13+
name: author.name,
14+
avatar: author.avatar,
15+
link: '' as 'https://',
16+
github: '',
17+
}),
18+
),
19+
} satisfies BlogFrontmatter,
20+
}));
21+
}

0 commit comments

Comments
 (0)