Skip to content

Commit 6d82890

Browse files
committed
add all static
1 parent 528b681 commit 6d82890

139 files changed

Lines changed: 1077 additions & 181 deletions

File tree

  • apps/codingcatdev/src

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎apps/codingcatdev/src/lib/server/content.ts‎

Lines changed: 9 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
import { ContentType, ContentPublished, type Lesson, type Podcast, type Author } from '$lib/types';
1+
import { ContentType, ContentPublished, type Podcast } from '$lib/types';
22
import type { Content, Course } from '$lib/types';
33
import { env } from '$env/dynamic/private';
44
import { fileURLToPath } from 'url';
5-
import { opendirSync, readFileSync } from "fs";
6-
import { compile } from 'mdsvex';
5+
import { opendirSync } from "fs";
76

87
const LIMIT = 20;
98

@@ -52,8 +51,6 @@ export const parseContentType = (async <T>(path: string, withCode = true) => {
5251
// let frontmatter;
5352
// let html;
5453
// if (prod) {
55-
console.log('IMPORT PATH', path);
56-
5754
const { metadata, default: Page } = await import(path);
5855
const frontmatter = metadata;
5956
const html = Page?.render()?.html;
@@ -156,14 +153,12 @@ export const filterContent = async <T extends Content>({
156153
/**
157154
* List all content from specified content type by author
158155
* */
159-
export const listContentByAuthor = async ({ authorSlug, contentItems }:
156+
export const listContentByAuthor = async <T extends Content>({ authorSlug, contentItems }:
160157
{
161158
authorSlug: string,
162-
contentItems: Content[];
159+
contentItems: T[];
163160
}) => {
164-
console.debug(`Searching for items from author: ${authorSlug}`);
165-
const fullConent = await listContent({ contentItems, after: 0, limit: 10000 });
166-
const content = fullConent.content.filter(
161+
const content = contentItems.filter(
167162
preview ?
168163
(c) =>
169164
c.authors?.filter((g) => g == authorSlug)?.length
@@ -181,14 +176,12 @@ export const listContentByAuthor = async ({ authorSlug, contentItems }:
181176
/**
182177
* List all content from specified content type by sponsor
183178
* */
184-
export const listContentBySponsor = async ({ sponsorSlug, contentItems }:
179+
export const listContentBySponsor = async <T extends Content>({ sponsorSlug, contentItems }:
185180
{
186181
sponsorSlug: string,
187-
contentItems: Content[];
182+
contentItems: T[];
188183
}) => {
189-
console.debug(`Searching for items from sponsor: ${sponsorSlug}`);
190-
const fullConent = await listContent({ contentItems, after: 0, limit: 10000 });
191-
const content = fullConent.content.filter(
184+
const content = contentItems.filter(
192185
preview ?
193186
(c) =>
194187
c.sponsors?.filter((g) => g == sponsorSlug)?.length
@@ -203,60 +196,14 @@ export const listContentBySponsor = async ({ sponsorSlug, contentItems }:
203196
];
204197
};
205198

206-
207-
/**
208-
* Get lesson by course and slug
209-
* */
210-
export const getLessonFromCourseSlug = async ({ courseSlug, slug, courseItems }:
211-
{
212-
courseSlug: string, slug: string,
213-
courseItems: Content[];
214-
}) => {
215-
console.debug(`Searching for course: ${courseSlug}`);
216-
217-
const course = await getContentBySlug({ contentItems: courseItems, slug: courseSlug });
218-
if (!course) {
219-
console.debug(`course not found`);
220-
return null;
221-
}
222-
console.debug(`Searching within ${course.slug} for lesson slug: ${slug}`);
223-
224-
// TODO: ADD Pro check?
225-
const doc = course
226-
?.lesson?.filter(
227-
preview ?
228-
(l) =>
229-
l.slug == slug
230-
:
231-
(l) =>
232-
l.slug == slug &&
233-
new Date(l.start) <= new Date() &&
234-
l.published === ContentPublished.published
235-
)
236-
.sort((a, b) => new Date(b.start).valueOf() - new Date(a.start).valueOf())
237-
.slice(0, 1)
238-
.at(0);
239-
if (!doc) {
240-
console.debug(`lesson not found`);
241-
return null;
242-
}
243-
244-
return {
245-
...doc,
246-
courseSlug: course.slug
247-
};
248-
};
249-
250-
251199
/**
252200
* Get podcast by guest slug
253201
* */
254-
export const getPodcastByGuest = async ({ slug, podcastItems }:
202+
export const listContentByGuest = async ({ slug, podcastItems }:
255203
{
256204
slug: string,
257205
podcastItems: Podcast[];
258206
}) => {
259-
console.debug(`Searching for podcasts from guest: ${slug}`);
260207
const podcasts = podcastItems
261208
.filter(
262209
preview ?

‎apps/codingcatdev/src/lib/types/index.ts‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@ export enum ContentType {
7575
page = 'page',
7676
podcast = 'podcast',
7777
post = 'post',
78-
schedule = 'schedule',
7978
sponsor = 'sponsor',
8079
tutorial = 'tutorial'
8180
}

‎apps/codingcatdev/src/routes/(content-list)/schedules/+page.server.ts‎

Lines changed: 0 additions & 13 deletions
This file was deleted.

‎apps/codingcatdev/src/routes/(content-list)/schedules/+page.svelte‎

Lines changed: 0 additions & 7 deletions
This file was deleted.

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

Lines changed: 127 additions & 9 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 Content, type Course } from '$lib/types';
2+
import { filterContent, getContentTypeDirectory, getContentTypePath, listContent, listContentByAuthor, listContentByGuest, listContentBySponsor } from '$lib/server/content';
3+
import { ContentType, type Content, type Course, type Author, type Podcast, type Sponsor } from '$lib/types';
44

55
export const load = (async (params) => {
66
try {
@@ -9,14 +9,38 @@ export const load = (async (params) => {
99
const path = splitPath.at(2)
1010

1111
if (!contentType || !path) throw error(404);
12-
const md = await getContentTypePath<Content>(contentType as ContentType, path);
12+
const md = await getContentTypePath<Content & Podcast & Author & Sponsor>(contentType as ContentType, path);
1313
if (!md) throw error(404);
1414

1515
const contentItems = await filterContent({ contentItems: [md] })
1616
const content = contentItems?.at(0);
1717
if (!content) throw error(404);
1818

19+
// Content is good, fetch surrounding items
20+
const authors: Author[] = [];
21+
if (content?.authors) {
22+
for (const authorSlug of content.authors) {
23+
const author = await getContentTypePath<Author>(ContentType.author, authorSlug);
24+
if (author) authors.push(author)
25+
}
26+
}
27+
const guests: Author[] = [];
28+
if (content?.guests) {
29+
for (const guestSlug of content.guests) {
30+
const guest = await getContentTypePath<Author>(ContentType.guest, guestSlug);
31+
if (guest) guests.push(guest)
32+
}
33+
}
34+
35+
const sponsors: Sponsor[] = [];
36+
if (content?.sponsors) {
37+
for (const sponsorSlug of content.sponsors) {
38+
const sponsor = await getContentTypePath<Sponsor>(ContentType.sponsor, sponsorSlug);
39+
if (sponsor) sponsors.push(sponsor)
40+
}
41+
}
1942

43+
// Static last 3 content
2044
const post = (await listContent<Content>({
2145
contentItems: await getContentTypeDirectory<Content>(ContentType.post),
2246
limit: 3
@@ -38,14 +62,108 @@ export const load = (async (params) => {
3862
limit: 3
3963
})).content
4064

41-
return {
42-
content,
43-
course,
44-
tutorial,
45-
podcast,
46-
post,
65+
const baseContent = {
66+
content, // Main Content
67+
authors, // Possibly Empty
68+
guests, // Possibly Empty
69+
sponsors, // Possibly Empty
70+
course, // Top 3
71+
tutorial, // Top 3
72+
podcast, // Top 3
73+
post, // Top 3
74+
}
75+
76+
if (content.type === ContentType.author) {
77+
const allCourses = (await listContent<Course>({
78+
contentItems: await getContentTypeDirectory<Course>(ContentType.course),
79+
limit: 10000,
80+
})).content;
81+
82+
const authorCourses = await listContentByAuthor<Course>({ authorSlug: content.slug, contentItems: allCourses })
83+
84+
const allTutorials = (await listContent<Content>({
85+
contentItems: await getContentTypeDirectory<Content>(ContentType.tutorial),
86+
limit: 10000,
87+
})).content;
88+
89+
const authorTutorials = await listContentByAuthor<Course>({ authorSlug: content.slug, contentItems: allTutorials })
90+
91+
const allPosts = (await listContent<Content>({
92+
contentItems: await getContentTypeDirectory<Content>(ContentType.post),
93+
limit: 10000,
94+
})).content;
95+
96+
const authorPosts = await listContentByAuthor<Course>({ authorSlug: content.slug, contentItems: allPosts })
97+
98+
99+
return {
100+
...baseContent,
101+
102+
// Author Specific
103+
authorCourses,
104+
authorTutorials,
105+
authorPosts
106+
}
107+
}
108+
109+
if (content.type === ContentType.guest) {
110+
const allPodcasts = (await listContent<Podcast>({
111+
contentItems: await getContentTypeDirectory<Podcast>(ContentType.podcast),
112+
limit: 10000,
113+
})).content;
114+
115+
const guestPodcasts = await listContentByGuest({ slug: content.slug, podcastItems: allPodcasts })
116+
117+
return {
118+
...baseContent,
119+
120+
// Guest Specific
121+
guestPodcasts
122+
}
123+
}
124+
125+
if (content.type === ContentType.sponsor) {
126+
const allCourses = (await listContent<Course>({
127+
contentItems: await getContentTypeDirectory<Course>(ContentType.course),
128+
limit: 10000,
129+
})).content;
130+
131+
const sponsorCourses = await listContentBySponsor<Course>({ sponsorSlug: content.slug, contentItems: allCourses })
132+
133+
const allTutorials = (await listContent<Content>({
134+
contentItems: await getContentTypeDirectory<Content>(ContentType.tutorial),
135+
limit: 10000,
136+
})).content;
137+
138+
const sponsorTutorials = await listContentBySponsor<Course>({ sponsorSlug: content.slug, contentItems: allTutorials })
139+
140+
const allPosts = (await listContent<Content>({
141+
contentItems: await getContentTypeDirectory<Content>(ContentType.post),
142+
limit: 10000,
143+
})).content;
144+
145+
const sponsorPosts = await listContentBySponsor<Course>({ sponsorSlug: content.slug, contentItems: allPosts })
146+
147+
const allPodcasts = (await listContent<Podcast>({
148+
contentItems: await getContentTypeDirectory<Podcast>(ContentType.podcast),
149+
limit: 10000,
150+
})).content;
151+
152+
const sponsorPodcasts = await listContentBySponsor({ sponsorSlug: content.slug, contentItems: allPodcasts })
153+
154+
155+
return {
156+
...baseContent,
157+
158+
// Sponsor Specific
159+
sponsorCourses,
160+
sponsorTutorials,
161+
sponsorPosts,
162+
sponsorPodcasts
163+
}
47164
}
48165

166+
return baseContent;
49167
}
50168
catch (e) {
51169
console.error(e)

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

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
import { ContentType } from '$lib/types';
55
import { storeCurrentUrl } from '$lib/stores/stores';
66
import Content from './Content.svelte';
7+
import Author from './Author.svelte';
8+
import Guest from './Guest.svelte';
9+
import Sponsor from './Sponsor.svelte';
710
811
export let data;
912
</script>
@@ -15,9 +18,23 @@
1518
slotSidebarRight="hidden xl:block"
1619
>
1720
<!-- Page Content -->
18-
<Content {data}>
19-
<slot />
20-
</Content>
21+
{#if data.content.type === ContentType.author}
22+
<Author {data}>
23+
<slot />
24+
</Author>
25+
{:else if data.content.type === ContentType.guest}
26+
<Guest {data}>
27+
<slot />
28+
</Guest>
29+
{:else if data.content.type === ContentType.sponsor}
30+
<Sponsor {data}>
31+
<slot />
32+
</Sponsor>
33+
{:else}
34+
<Content {data}>
35+
<slot />
36+
</Content>
37+
{/if}
2138
<svelte:fragment slot="bcu-app-shell-sidebar-right">
2239
<!-- Div takes up same room as fixed -->
2340
<div class="w-[19.5rem] xl:w-96" />

0 commit comments

Comments
 (0)