Skip to content

Commit 0656f2f

Browse files
committed
Show case studies and product updates in blog
1 parent 591724e commit 0656f2f

File tree

8 files changed

+88
-30
lines changed

8 files changed

+88
-30
lines changed

packages/web/docs/src/app/blog/components/blog-card.tsx

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,15 @@ export function BlogCard({ post, className, variant, tag }: BlogCardProps) {
2020
const { title, tags } = frontmatter;
2121
const date = new Date(frontmatter.date);
2222

23-
const postAuthors: Author[] = (
24-
typeof frontmatter.authors === 'string'
25-
? [authors[frontmatter.authors as AuthorId]]
26-
: frontmatter.authors.map(author => authors[author as AuthorId])
27-
).filter(Boolean);
23+
const authorsArray = Array.isArray(frontmatter.authors)
24+
? frontmatter.authors
25+
: [frontmatter.authors];
26+
27+
const postAuthors: Author[] = authorsArray
28+
.map((authorId: AuthorId | Author) =>
29+
typeof authorId === 'string' ? authors[authorId] : authorId,
30+
)
31+
.filter(Boolean);
2832

2933
if (postAuthors.length === 0) {
3034
console.error('author not found', frontmatter);
@@ -44,6 +48,7 @@ export function BlogCard({ post, className, variant, tag }: BlogCardProps) {
4448
className,
4549
)}
4650
href={post.route}
51+
scroll
4752
>
4853
<article
4954
className={cn(
@@ -74,7 +79,8 @@ export function BlogCard({ post, className, variant, tag }: BlogCardProps) {
7479
<div className="relative size-6">
7580
<Image
7681
src={avatarSrc}
77-
alt={firstAuthor.name}
82+
alt=""
83+
role="presentation"
7884
width={24}
7985
height={24}
8086
className="rounded-full"

packages/web/docs/src/app/blog/components/posts-by-tag/latest-posts.tsx

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -43,22 +43,24 @@ export function LatestPosts({
4343
<ul className="mt-6 grid grid-cols-1 gap-4 sm:grid sm:grid-cols-2 sm:gap-6 md:mt-16 lg:grid-cols-3 xl:grid-cols-4">
4444
{firstSection}
4545
</ul>
46-
<details className="mt-8 sm:mt-12">
47-
<summary className="bg-beige-200 text-green-1000 border-beige-300 hover:bg-beige-300 hive-focus mx-auto w-fit cursor-pointer select-none list-none rounded-lg border px-4 py-2 hover:border-current dark:border-neutral-700 dark:bg-neutral-800 dark:text-neutral-100 dark:hover:bg-neutral-700 [&::marker]:hidden [[open]>&]:mb-8 [[open]>&]:sm:mb-12">
48-
<span className="[[open]_&]:hidden">Show more</span>
49-
<span className="hidden [[open]_&]:inline">Hide posts</span>
50-
</summary>
46+
{rest.length > 0 && (
47+
<details className="mt-8 sm:mt-12">
48+
<summary className="bg-beige-200 text-green-1000 border-beige-300 hover:bg-beige-300 hive-focus mx-auto w-fit cursor-pointer select-none list-none rounded-lg border px-4 py-2 hover:border-current dark:border-neutral-700 dark:bg-neutral-800 dark:text-neutral-100 dark:hover:bg-neutral-700 [&::marker]:hidden [[open]>&]:mb-8 [[open]>&]:sm:mb-12">
49+
<span className="[[open]_&]:hidden">Show more</span>
50+
<span className="hidden [[open]_&]:inline">Hide posts</span>
51+
</summary>
5152

52-
<ul className="mt-4 grid grid-cols-1 gap-4 sm:mt-6 sm:grid sm:grid-cols-2 sm:gap-6 lg:grid-cols-3 xl:grid-cols-4">
53-
{rest.map(post => {
54-
return (
55-
<li key={post.route} className="*:h-full">
56-
<BlogCard post={post} tag={tag} />
57-
</li>
58-
);
59-
})}
60-
</ul>
61-
</details>
53+
<ul className="mt-4 grid grid-cols-1 gap-4 sm:mt-6 sm:grid sm:grid-cols-2 sm:gap-6 lg:grid-cols-3 xl:grid-cols-4">
54+
{rest.map(post => {
55+
return (
56+
<li key={post.route} className="*:h-full">
57+
<BlogCard post={post} tag={tag} />
58+
</li>
59+
);
60+
})}
61+
</ul>
62+
</details>
63+
)}
6264
</section>
6365
);
6466
}

packages/web/docs/src/app/blog/page.tsx

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import { getPageMap } from '@theguild/components/server';
2+
import { coerceCaseStudiesToBlogs } from '../case-studies/coerce-case-studies-to-blogs';
3+
import { getCaseStudies } from '../case-studies/get-case-studies';
24
import { isBlogPost } from './blog-types';
35
import { NewsletterFormCard } from './components/newsletter-form-card';
46
import { PostsByTag } from './components/posts-by-tag';
@@ -13,7 +15,18 @@ export const metadata = {
1315

1416
export default async function BlogPage() {
1517
const [_meta, _indexPage, ...pageMap] = await getPageMap('/blog');
16-
const allPosts = pageMap.filter(isBlogPost);
18+
const [, , ...productUpdates] = await getPageMap('/product-updates');
19+
20+
const caseStudies = await getCaseStudies().then(coerceCaseStudiesToBlogs);
21+
22+
const allPosts = pageMap
23+
.filter(isBlogPost)
24+
.concat(caseStudies)
25+
.concat(
26+
productUpdates
27+
.filter(isBlogPost)
28+
.map(post => ((post.frontMatter.tags ||= ['Product Update']), post)),
29+
);
1730

1831
return (
1932
<BlogPageLayout>

packages/web/docs/src/app/case-studies/all-case-studies-list.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,16 @@ export function AllCaseStudiesList({ caseStudies }: { caseStudies: CaseStudyFile
99
<Heading size="md" as="h2" className="text-center">
1010
Explore customer stories
1111
</Heading>
12-
<ul className="mt-6 flex gap-4 max-sm:flex-col sm:mt-16 sm:gap-6">
12+
<ul className="mt-6 flex gap-4 max-lg:flex-col sm:mt-16 sm:gap-6">
1313
{caseStudies.map(caseStudy => {
1414
return (
15-
<li key={caseStudy.name} className="basis-1/3">
15+
<li key={caseStudy.name} className="relative basis-1/3">
1616
<CaseStudyCard
1717
category={caseStudy.frontMatter.category}
1818
excerpt={caseStudy.frontMatter.excerpt}
1919
href={caseStudy.route}
2020
logo={getCompanyLogo(caseStudy.name)}
21+
className="h-full"
2122
/>
2223
</li>
2324
);

packages/web/docs/src/app/case-studies/case-studies-header.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export function CaseStudiesHeader(props: React.HTMLAttributes<HTMLDivElement>) {
2424
<Heading as="h1" size="md" className="max-sm:text-[32px]">
2525
{frontmatter.title}
2626
</Heading>
27-
<Authors authors={frontmatter.authors} className="mt-8" />
27+
<Authors authors={frontmatter.authors} className="max-lg:my-4 lg:mt-8" />
2828
</div>
2929
<LogoWithDecorations className="h-[224px] w-full max-w-[640px] shrink-0 max-lg:-order-1 max-sm:mb-6 lg:w-[320px] lg:max-xl:h-[180px] xl:w-[400px] lg:max-xl:[&>svg]:w-[140px] lg:max-xl:[&_svg]:h-[120px]">
3030
{logo}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
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(coerceCaseStudyToBlog);
7+
}
8+
9+
export function coerceCaseStudyToBlog(caseStudy: CaseStudyFile): BlogPostFile {
10+
return {
11+
...caseStudy,
12+
frontMatter: {
13+
...caseStudy.frontMatter,
14+
tags: ['Case Study'],
15+
authors: caseStudy.frontMatter.authors.map(
16+
(author): Author => ({
17+
name: author.name,
18+
avatar: author.avatar,
19+
link: '' as 'https://',
20+
github: '',
21+
}),
22+
),
23+
} satisfies BlogFrontmatter,
24+
};
25+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { getPageMap } from '@theguild/components/server';
2+
import { isCaseStudy } from './isCaseStudyFile';
3+
4+
export async function getCaseStudies() {
5+
const [_meta, _indexPage, ...pageMap] = await getPageMap('/case-studies');
6+
7+
const caseStudies = pageMap.filter(isCaseStudy).sort((a, b) => {
8+
const aDate = a.frontMatter.date;
9+
const bDate = b.frontMatter.date;
10+
return aDate < bDate ? 1 : aDate > bDate ? -1 : 0;
11+
});
12+
13+
return caseStudies;
14+
}

packages/web/docs/src/app/case-studies/page.tsx

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,24 +5,21 @@ import {
55
Heading,
66
HiveLayoutConfig,
77
} from '@theguild/components';
8-
import { getPageMap } from '@theguild/components/server';
98
import { GetYourAPIGameWhite } from '../../components/get-your-api-game-white';
109
import { HeroLinks } from '../../components/hero';
1110
import { LandingPageContainer } from '../../components/landing-page-container';
1211
import { TrustedBySection } from '../../components/trusted-by-section';
1312
import { AllCaseStudiesList } from './all-case-studies-list';
1413
import { CaseStudiesArchDecoration, CaseStudiesGradientDefs } from './case-studies-arch-decoration';
1514
import { FeaturedCaseStudiesGrid } from './featured-case-studies-grid';
16-
import { isCaseStudy } from './isCaseStudyFile';
15+
import { getCaseStudies } from './get-case-studies';
1716

1817
export const metadata = {
1918
title: 'Case Studies',
2019
};
2120

2221
export default async function CaseStudiesPage() {
23-
const [_meta, _indexPage, ...pageMap] = await getPageMap('/case-studies');
24-
25-
const caseStudies = pageMap.filter(isCaseStudy);
22+
const caseStudies = await getCaseStudies();
2623

2724
return (
2825
<LandingPageContainer className="mx-auto max-w-[90rem] overflow-hidden px-6">

0 commit comments

Comments
 (0)