Skip to content

Commit

Permalink
Add videos to homepage
Browse files Browse the repository at this point in the history
  • Loading branch information
zackproser committed Aug 29, 2024
1 parent b094a03 commit c8726d2
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 5 deletions.
18 changes: 16 additions & 2 deletions src/app/HomepageClientComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,8 @@ interface HomepageClientComponentProps {
mlProjects: Article[];
aiDev: Article[];
refArchitectures: Article[];
careerAdvice: Article[];
videos: Article[];
isMobile: boolean;
}

Expand All @@ -141,6 +143,7 @@ export default function HomepageClientComponent({
aiDev,
refArchitectures,
careerAdvice,
videos,
isMobile
}: HomepageClientComponentProps) {
const [email, setEmail] = useState("")
Expand Down Expand Up @@ -251,7 +254,7 @@ export default function HomepageClientComponent({
</div>
</section>

<section className="bg-white dark:bg-gray-900 py-12">
<section className="bg-gray-100 dark:bg-gray-800 py-12">
<div className="container px-4 md:px-6 mx-auto">
<h2 className="text-2xl font-bold mb-6 text-gray-900 dark:text-white">Career Advice</h2>
<div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6">
Expand All @@ -262,7 +265,18 @@ export default function HomepageClientComponent({
</div>
</section>

<section className="bg-gray-100 dark:bg-gray-800 py-12">
<section className="bg-white dark:bg-gray-900 py-12">
<div className="container px-4 md:px-6 mx-auto">
<h2 className="text-2xl font-bold mb-6 text-gray-900 dark:text-white">Videos</h2>
<div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6">
{videos.slice(0, 3).map((article) => (
<BlogPostCard key={article.slug} article={article} />
))}
</div>
</div>
</section>

<section className="bg-white dark:bg-gray-900 py-12">
<div className="container px-4 md:px-6 mx-auto">
<h2 className="text-2xl font-bold mb-6 text-gray-900 dark:text-white">Reference Architectures and Demos</h2>
<div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6">
Expand Down
11 changes: 11 additions & 0 deletions src/app/page.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { getAllArticles } from "@/lib/articles"
import { getAllVideos } from "@/lib/videos" // Import the new function
import HomepageClientComponent from './HomepageClientComponent'
import { headers } from 'next/headers'
import { UAParser } from 'ua-parser-js'
Expand Down Expand Up @@ -34,11 +35,18 @@ export default async function Page() {
'you-get-to-keep-the-neural-connections'
]

const videoSlugs = [
'how-to-build-chat-with-your-data-rag',
'how-to-use-chatgpt-in-your-terminal',
'what-is-a-vector-database'
]

const allSlugs = [...mlProjectSlugs, ...aiDevSlugs, ...refArchitectureSlugs, ...careerAdviceSlugs]

try {
// Fetch all articles matching the slugs
const allArticles = await getAllArticles(allSlugs)
const allVideos = await getAllVideos(videoSlugs) // Fetch all videos with matching slugs

const mlProjects = allArticles.filter(article => mlProjectSlugs.includes(article.slug))

Expand All @@ -52,6 +60,8 @@ export default async function Page() {

const careerAdvice = allArticles.filter(article => careerAdviceSlugs.includes(article.slug))

const videos = allVideos.filter(video => videoSlugs.includes(video.slug)) // Filter videos

// Server-side mobile detection
const userAgent = headers().get('user-agent') || ''
const parser = new UAParser(userAgent)
Expand All @@ -64,6 +74,7 @@ export default async function Page() {
aiDev={aiDev}
refArchitectures={refArchitectures}
careerAdvice={careerAdvice}
videos={videos} // Added new prop
isMobile={isMobile}
/>
)
Expand Down
12 changes: 9 additions & 3 deletions src/lib/videos.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Article, ArticleWithSlug } from './shared-types'

import glob from 'fast-glob'
import path from 'path'

async function importArticle(
articleFilename: string,
Expand All @@ -17,12 +17,18 @@ async function importArticle(
}
}

export async function getAllVideos() {
// Extend getAllVideos to accept an optional array of slugs
export async function getAllVideos(matchingSlugs?: string[]) {
let articleFilenames = await glob('*/page.mdx', {
cwd: './src/app/videos',
cwd: path.join(process.cwd(), 'src', 'app', 'videos'),
})

let articles = await Promise.all(articleFilenames.map(importArticle))

// Filter articles to include only those whose slug is in matchingSlugs
if (matchingSlugs && matchingSlugs.length > 0) {
articles = articles.filter(article => matchingSlugs.includes(article.slug))
}

return articles.sort((a, z) => +new Date(z.date) - +new Date(a.date))
}

0 comments on commit c8726d2

Please sign in to comment.