Skip to content

Commit bce8ebc

Browse files
authored
Fix/course data (#457)
* Fixed Author lookup * update sponsor listings
1 parent c66f93a commit bce8ebc

File tree

3 files changed

+87
-7
lines changed

3 files changed

+87
-7
lines changed

apps/codingcatdev/src/routes/(content-single)/course/+layout.server.ts

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { error } from '@sveltejs/kit';
2-
import { filterContent, getContentTypeDirectory, getContentTypePath, listContent } from '$lib/server/content';
3-
import { ContentType, type Course, type Author } from '$lib/types';
2+
import { filterContent, getContentTypePath } from '$lib/server/content';
3+
import { ContentType, type Course, type Author, type Sponsor } from '$lib/types';
44

55
export const prerender = false;
66

@@ -18,14 +18,28 @@ export const load = (async (params) => {
1818
const course = contentItems?.at(0);
1919
if (!course) throw error(404);
2020

21-
const authors = (await listContent<Author>({
22-
contentItems: await getContentTypeDirectory<Author>(ContentType.author)
23-
}))?.content
21+
// Content is good, fetch surrounding items
22+
const authors: Author[] = [];
23+
if (course?.authors) {
24+
for (const authorSlug of course.authors) {
25+
const author = await getContentTypePath<Author>(ContentType.author, authorSlug);
26+
if (author) authors.push(author)
27+
}
28+
}
29+
30+
const sponsors: Sponsor[] = [];
31+
if (course?.sponsors) {
32+
for (const sponsorSlug of course.sponsors) {
33+
const sponsor = await getContentTypePath<Sponsor>(ContentType.sponsor, sponsorSlug);
34+
if (sponsor) sponsors.push(sponsor)
35+
}
36+
}
2437

2538
return {
2639
content: course.lesson?.find(l => l.slug === lessonSlug),
2740
course,
28-
authors
41+
authors,
42+
sponsors
2943
}
3044
}
3145
catch (e) {

apps/codingcatdev/src/routes/(content-single)/course/+layout.svelte

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import Course from './Course.svelte';
44
import LessonList from './LessonList.svelte';
55
import Lesson from './Lesson.svelte';
6+
import Image from '$lib/components/content/Image.svelte';
67
import { storeCurrentUrl } from '$lib/stores/stores';
78
89
export let data;
@@ -24,6 +25,38 @@
2425
<div class="w-[19.5rem] xl:w-96" />
2526
<div class="fixed top-[5.125rem] bottom-24 w-[19.5rem] xl:w-96 py-10 overflow-y-auto ">
2627
<div class="flex flex-col gap-2 px-8 md:gap-8">
28+
<!-- Sponsors -->
29+
{#if data?.sponsors?.length}
30+
<span class="bcu-toc-label px-4 pt-0 font-bold">Sponsors</span>
31+
<section class="flex flex-col gap-2 md:flex-row md:gap-8">
32+
{#each data?.sponsors as sponsor (sponsor.slug)}
33+
<a
34+
class="overflow-hidden bcu-card bg-initial card-hover md:flex-1"
35+
href={`${sponsor.url}`}
36+
target="_blank"
37+
rel="noopener noreferrer"
38+
>
39+
<header>
40+
{#if sponsor?.cover}
41+
<Image
42+
src={sponsor.cover}
43+
alt={sponsor.name}
44+
classes="object-cover w-full bg-cover rounded bg-black/50 aspect-video"
45+
/>
46+
{/if}
47+
</header>
48+
<div class="p-4 space-y-4">
49+
<h3 data-toc-ignore="">{sponsor?.name}</h3>
50+
<article>
51+
<p>
52+
{sponsor?.description}
53+
</p>
54+
</article>
55+
</div>
56+
</a>
57+
{/each}
58+
</section>
59+
{/if}
2760
{#key $storeCurrentUrl}
2861
<TableOfContents />
2962
{/key}

apps/codingcatdev/src/routes/(content-single)/course/Course.svelte

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
<script lang="ts">
22
import 'prism-themes/themes/prism-shades-of-purple.min.css';
33
import Video from '$lib/components/content/Video.svelte';
4-
import type { Author, Content, Course, Lesson } from '$lib/types';
4+
import type { Author, Sponsor, Course } from '$lib/types';
55
import LessonCards from './LessonCards.svelte';
66
import Image from '$lib/components/content/Image.svelte';
77
export let data: {
88
course: Course;
99
authors: Author[];
10+
sponsors: Sponsor[];
1011
};
1112
</script>
1213

@@ -44,6 +45,38 @@
4445
</section>
4546
{/if}
4647
<h1>{data.course.title}</h1>
48+
<!-- Sponsors -->
49+
{#if data?.sponsors?.length}
50+
<h2>Sponsors</h2>
51+
<section class="flex flex-col gap-2 md:flex-row md:gap-8">
52+
{#each data?.sponsors as sponsor (sponsor.slug)}
53+
<a
54+
class="overflow-hidden bcu-card bg-initial card-hover md:flex-1"
55+
href={`${sponsor.url}`}
56+
target="_blank"
57+
rel="noopener noreferrer"
58+
>
59+
<header>
60+
{#if sponsor?.cover}
61+
<Image
62+
src={sponsor.cover}
63+
alt={sponsor.name}
64+
classes="object-cover w-full bg-cover rounded bg-black/50 aspect-video"
65+
/>
66+
{/if}
67+
</header>
68+
<div class="p-4 space-y-4">
69+
<h3 data-toc-ignore="">{sponsor?.name}</h3>
70+
<article>
71+
<p>
72+
{sponsor?.description}
73+
</p>
74+
</article>
75+
</div>
76+
</a>
77+
{/each}
78+
</section>
79+
{/if}
4780
<section class="flex-grow w-full markdown flex flex-col gap-2 md:gap-8">
4881
<slot />
4982
</section>

0 commit comments

Comments
 (0)