-
Notifications
You must be signed in to change notification settings - Fork 123
Show case studies and product updates in feed #7192
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 20 commits
8ee063b
a804bd1
2e59252
b43dd3f
912be44
591724e
0656f2f
48daade
2e5e40a
f4bf439
9baa925
a28f187
bdff7e5
3c8bb4d
5b6857c
fa775e6
7743f6a
cac1fb1
6761aab
6a0ec30
49bd062
c4c6495
fd8f2da
759a199
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,8 +7,10 @@ | |
| }, | ||
| "scripts": { | ||
| "build": "next build && next-sitemap", | ||
| "build:analyze": "ANALYZE=true next build", | ||
| "dev": "next --turbopack", | ||
| "postbuild": "pagefind --site .next/server/app --output-path out/_pagefind", | ||
| "prettier": "prettier --cache --write --list-different --ignore-unknown src", | ||
| "validate-mdx-links": "pnpx [email protected] --files 'src/**/*.mdx'" | ||
| }, | ||
| "dependencies": { | ||
|
|
@@ -17,6 +19,7 @@ | |
| "@radix-ui/react-tabs": "1.1.2", | ||
| "@radix-ui/react-tooltip": "1.1.6", | ||
| "@theguild/components": "9.11.0", | ||
| "@types/rss": "^0.0.32", | ||
| "class-variance-authority": "0.7.1", | ||
| "clsx": "2.1.1", | ||
| "date-fns": "4.1.0", | ||
|
|
@@ -28,14 +31,15 @@ | |
| "react-dom": "19.0.0", | ||
| "react-icons": "5.4.0", | ||
| "rehype-frontmatter-mdx-imports": "0.1.1", | ||
| "tailwind-merge": "2.6.0" | ||
| "tailwind-merge": "2.6.0", | ||
| "zod": "3.25.76" | ||
| }, | ||
| "devDependencies": { | ||
| "@mdx-js/typescript-plugin": "^0.0.8", | ||
| "@next/bundle-analyzer": "^16.0.0", | ||
| "@tailwindcss/typography": "0.5.16", | ||
| "@theguild/tailwind-config": "0.6.3", | ||
| "@types/react": "18.3.18", | ||
| "@types/rss": "^0.0.32", | ||
| "next-sitemap": "4.2.3", | ||
| "pagefind": "^1.2.0", | ||
| "postcss": "8.4.49", | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,21 +1,25 @@ | ||
| import type { StaticImageData } from 'next/image'; | ||
| import { AuthorId } from '../../authors'; | ||
| import { MdxFile, PageMapItem } from '../../mdx-types'; | ||
| import { z } from 'zod'; | ||
| import { AuthorOrId, staticImageDataSchema } from '../../authors'; | ||
| import { MdxFile } from '../../mdx-types'; | ||
|
|
||
| export interface BlogFrontmatter { | ||
| authors: AuthorId | AuthorId[]; | ||
| title: string; | ||
| date: string; | ||
| tags: string | string[]; | ||
| featured?: boolean; | ||
| image?: VideoPath | StaticImageData; | ||
| thumbnail?: StaticImageData; | ||
| } | ||
| export const VideoPath = z | ||
| .string() | ||
| .regex(/^.+\.(webm|mp4)$/) as z.ZodType<`${string}.${'webm' | 'mp4'}`>; | ||
|
|
||
| type VideoPath = `${string}.${'webm' | 'mp4'}`; | ||
| export type VideoPath = z.infer<typeof VideoPath>; | ||
|
|
||
| export type BlogPostFile = Required<MdxFile<BlogFrontmatter>>; | ||
| export const BlogFrontmatter = z.object({ | ||
| authors: z.union([z.array(AuthorOrId), AuthorOrId]), | ||
| title: z.string(), | ||
| date: z.string(), | ||
| tags: z.union([z.string(), z.array(z.string())]), | ||
| featured: z.boolean().optional(), | ||
| image: z.union([VideoPath, staticImageDataSchema]).optional(), | ||
| thumbnail: staticImageDataSchema.optional(), | ||
| description: z.string().optional(), | ||
| }); | ||
|
|
||
| export function isBlogPost(item: PageMapItem): item is BlogPostFile { | ||
| return item && 'route' in item && 'name' in item && 'frontMatter' in item && !!item.frontMatter; | ||
| } | ||
| export type BlogFrontmatter = z.infer<typeof BlogFrontmatter>; | ||
|
|
||
| export const BlogPostFile = MdxFile(BlogFrontmatter); | ||
| export type BlogPostFile = z.infer<typeof BlogPostFile>; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,7 @@ | ||
| import { NextPageProps } from '@theguild/components'; | ||
| import { getPageMap } from '@theguild/components/server'; | ||
| import { isBlogPost } from '../../blog-types'; | ||
| import { parseSchema } from '../../../../lib/parse-schema'; | ||
| import { BlogPostFile } from '../../blog-types'; | ||
| import { PostsByTag } from '../../components/posts-by-tag'; | ||
|
|
||
| export async function generateMetadata({ params }: NextPageProps<'tag'>) { | ||
|
|
@@ -11,7 +12,7 @@ export async function generateMetadata({ params }: NextPageProps<'tag'>) { | |
|
|
||
| export default async function BlogTagPage(props: NextPageProps<'tag'>) { | ||
| const [_meta, _indexPage, ...pageMap] = await getPageMap('/blog'); | ||
| const allPosts = pageMap.filter(isBlogPost); | ||
| const allPosts = pageMap.map(x => parseSchema(x, BlogPostFile)); | ||
| const tag = (await props.params).tag; | ||
| const posts = allPosts.filter(post => post.frontMatter.tags.includes(tag)); | ||
|
|
||
|
|
@@ -20,7 +21,7 @@ export default async function BlogTagPage(props: NextPageProps<'tag'>) { | |
|
|
||
| export async function generateStaticParams() { | ||
| const [_meta, _indexPage, ...pageMap] = await getPageMap('/blog'); | ||
| const allPosts = pageMap.filter(isBlogPost); | ||
| const allPosts = pageMap.map(x => parseSchema(x, BlogPostFile)); | ||
| const tags = allPosts.flatMap(post => post.frontMatter.tags); | ||
| const uniqueTags = [...new Set(tags)]; | ||
| return uniqueTags.map(tag => ({ tag })); | ||
|
Comment on lines
22
to
27
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Similar to the issue in Here's a suggested implementation: import { getCaseStudies } from '../../../../app/case-studies/get-case-studies';
import { coerceCaseStudiesToBlogs } from '../../../../app/case-studies/coerce-case-studies-to-blogs';
// ...
export async function generateStaticParams() {
const [_meta, _indexPage, ...pageMap] = await getPageMap('/blog');
const [, , ...productUpdates] = await getPageMap('/product-updates');
const caseStudies = await getCaseStudies().then(coerceCaseStudiesToBlogs);
const allPosts = pageMap
.map(x => parseSchema(x, BlogPostFile))
.concat(caseStudies)
.concat(
productUpdates
.map(x => parseSchema(x, BlogPostFile))
.map(post => ((post.frontMatter.tags ||= ['Product Update']), post)),
);
const tags = allPosts.flatMap(post =>
Array.isArray(post.frontMatter.tags) ? post.frontMatter.tags : [post.frontMatter.tags],
);
const uniqueTags = [...new Set(tags)];
return uniqueTags.map(tag => ({ tag }));
}There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually we explicitly don't want to do this. The pages are rendered elsewhere, we just link to them from the blog index page. |
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.