Skip to content

Commit f1f1370

Browse files
committed
moved tutorials to posts
1 parent ac01b29 commit f1f1370

66 files changed

Lines changed: 509 additions & 663 deletions

File tree

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: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -29,31 +29,30 @@ export const getRootPath = (contentType: ContentType, courseDir?: string) => {
2929
return root;
3030
}
3131

32-
export const getContentTypeDirectory = async <T>(contentType: ContentType, withCode = true, courseDir?: string) => {
32+
export const getContentTypeDirectory = async <T>(contentType: ContentType, courseDir?: string) => {
3333
const contentList: T[] = [];
3434
const dirs = opendirSync(getRootPath(contentType, courseDir));
3535
for await (const dir of dirs) {
3636
if (dir.isFile()) continue;
37-
const parsed = await parseContentType<T>(`${getRootPath(contentType, courseDir)}/${dir.name}/${suffix}`, withCode) as T;
37+
const parsed = await parseContentType<T>(`${getRootPath(contentType, courseDir)}/${dir.name}/${suffix}`) as T;
3838
contentList.push(parsed);
3939
}
4040
return contentList;
4141
}
4242

43-
export const getContentTypePath = async <T>(contentType: ContentType, path: string, withCode = true, courseDir?: string) => {
43+
export const getContentTypePath = async <T>(contentType: ContentType, path: string, courseDir?: string) => {
4444
const root = getRootPath(contentType, courseDir);
45-
return await parseContentType<T>(`${root}/${path}/${suffix}`, withCode) as T;
45+
return await parseContentType<T>(`${root}/${path}/${suffix}`) as T;
4646
}
4747

48-
export const parseContentType = (async <T>(path: string, withCode = true) => {
48+
export const parseContentType = (async <T>(path: string) => {
4949
// If we are in production everything has already been compiled to JavaScript
5050
// and we can just read the metadata, otherwise compile and read.
5151
// let frontmatter;
5252
// let html;
5353
// if (prod) {
54-
const { metadata, default: Page } = await import(path);
54+
const { metadata } = await import(path);
5555
const frontmatter = metadata;
56-
const html = Page?.render()?.html;
5756
// } else {
5857
// console.log('READ PATH', path);
5958
// const md = readFileSync(path, 'utf8');
@@ -64,15 +63,14 @@ export const parseContentType = (async <T>(path: string, withCode = true) => {
6463
// TODO: Add more checks?
6564

6665
if (!frontmatter?.type) {
67-
console.error('Missing Frontmatter details');
66+
console.error('Missing Frontmatter details', path);
6867
return;
6968
}
7069

7170
const content = {
7271
...frontmatter,
7372
cover: frontmatter?.cover ? decodeURI(frontmatter?.cover) : '',
7473
type: frontmatter?.type as ContentType,
75-
html: withCode ? html : undefined,
7674
weight: frontmatter?.weight ? frontmatter?.weight : 0,
7775
published: frontmatter?.published ? frontmatter?.published : ContentPublished.draft,
7876
start: frontmatter?.start ? new Date(frontmatter?.start) : new Date('Jan 01, 2000'),
@@ -81,7 +79,7 @@ export const parseContentType = (async <T>(path: string, withCode = true) => {
8179

8280
if (frontmatter.type === ContentType.course) {
8381
const lesson = (await listContent<Content>({
84-
contentItems: await getContentTypeDirectory<Content>(ContentType.lesson, false, frontmatter.slug),
82+
contentItems: await getContentTypeDirectory<Content>(ContentType.lesson, frontmatter.slug),
8583
limit: 10000
8684
})).content
8785
return { ...content, lesson } as T;
@@ -124,15 +122,15 @@ export const filterContent = async <T extends Content>({
124122
contentItems: T[];
125123
}) => {
126124
const doc = contentItems
127-
.filter(
125+
?.filter(
128126
preview ?
129127
() => true
130128
:
131-
(c) => new Date(c.start) <= new Date() &&
129+
(c) => c?.start ? new Date(c.start) <= new Date() : false &&
132130
c.published === ContentPublished.published
133131
)
134-
.sort((a, b) => new Date(b.start).valueOf() - new Date(a.start).valueOf())
135-
.map((c: Course) => {
132+
?.sort((a, b) => a?.start && b?.start && new Date(b.start).valueOf() - new Date(a.start).valueOf())
133+
?.map((c: Course) => {
136134
return {
137135
...c,
138136
lesson: c?.lesson

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,6 @@ export enum ContentType {
7676
podcast = 'podcast',
7777
post = 'post',
7878
sponsor = 'sponsor',
79-
tutorial = 'tutorial'
8079
}
8180

8281
export enum PodcastType {

‎apps/codingcatdev/src/routes/(content-list)/authors/AuthorCards.svelte‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,21 @@
22
import Image from '$lib/components/content/Image.svelte';
33
import type { Author, ContentType } from '$lib/types';
44
5-
export let data: { content: Author[]; next?: any };
5+
export let data: { contentType: ContentType; content: Author[]; next?: any };
66
77
let next = data.next;
8+
const contentType = data.contentType;
89
const more = async () => {
910
const response = await fetch('/api/more-content', {
1011
method: 'POST',
11-
body: JSON.stringify({ after: next }),
12+
body: JSON.stringify({ after: next, contentType }),
1213
headers: {
1314
'content-type': 'application/json'
1415
}
1516
});
1617
const d = await response.json();
1718
data = {
19+
contentType,
1820
content: [...data.content, ...d.content],
1921
next
2022
};

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ export const load = async () => {
77
return {
88
contentType,
99
...await listContent<Author>({
10-
contentItems: await getContentTypeDirectory<Author>(contentType)
10+
contentItems: await getContentTypeDirectory<Author>(contentType),
11+
limit: 100
1112
})
1213
};
1314
};

‎apps/codingcatdev/src/routes/(content-list)/guests/GuestCards.svelte‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,21 @@
33
import Image from '$lib/components/content/Image.svelte';
44
import type { Author, ContentType } from '$lib/types';
55
6-
export let data: { content: Author[]; next?: any };
6+
export let data: { contentType: ContentType; content: Author[]; next?: any };
77
88
let next = data.next;
9+
const contentType = data.contentType;
910
const more = async () => {
1011
const response = await fetch('/api/more-content', {
1112
method: 'POST',
12-
body: JSON.stringify({ after: next }),
13+
body: JSON.stringify({ after: next, contentType }),
1314
headers: {
1415
'content-type': 'application/json'
1516
}
1617
});
1718
const d = await response.json();
1819
data = {
20+
contentType,
1921
content: [...data.content, ...d.content],
2022
next
2123
};

‎apps/codingcatdev/src/routes/(content-list)/sponsors/SponsorCards.svelte‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,21 @@
22
import Image from '$lib/components/content/Image.svelte';
33
import type { ContentType, Sponsor } from '$lib/types';
44
5-
export let data: { content: Sponsor[]; next?: any };
5+
export let data: { contentType: ContentType; content: Sponsor[]; next?: any };
66
77
let next = data.next;
8+
const contentType = data.contentType;
89
const more = async () => {
910
const response = await fetch('/api/more-content', {
1011
method: 'POST',
11-
body: JSON.stringify({ after: next }),
12+
body: JSON.stringify({ after: next, contentType }),
1213
headers: {
1314
'content-type': 'application/json'
1415
}
1516
});
1617
const d = await response.json();
1718
data = {
19+
contentType,
1820
content: [...data.content, ...d.content],
1921
next
2022
};

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

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

‎apps/codingcatdev/src/routes/(content-list)/tutorials/+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: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -57,18 +57,12 @@ export const load = (async (params) => {
5757
limit: 3
5858
})).content
5959

60-
const tutorial = (await listContent<Content>({
61-
contentItems: await getContentTypeDirectory<Content>(ContentType.tutorial),
62-
limit: 3
63-
})).content
64-
6560
const baseContent = {
6661
content, // Main Content
6762
authors, // Possibly Empty
6863
guests, // Possibly Empty
6964
sponsors, // Possibly Empty
7065
course, // Top 3
71-
tutorial, // Top 3
7266
podcast, // Top 3
7367
post, // Top 3
7468
}
@@ -81,13 +75,6 @@ export const load = (async (params) => {
8175

8276
const authorCourses = await listContentByAuthor<Course>({ authorSlug: content.slug, contentItems: allCourses })
8377

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-
9178
const allPosts = (await listContent<Content>({
9279
contentItems: await getContentTypeDirectory<Content>(ContentType.post),
9380
limit: 10000,
@@ -101,7 +88,6 @@ export const load = (async (params) => {
10188

10289
// Author Specific
10390
authorCourses,
104-
authorTutorials,
10591
authorPosts
10692
}
10793
}
@@ -130,13 +116,6 @@ export const load = (async (params) => {
130116

131117
const sponsorCourses = await listContentBySponsor<Course>({ sponsorSlug: content.slug, contentItems: allCourses })
132118

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-
140119
const allPosts = (await listContent<Content>({
141120
contentItems: await getContentTypeDirectory<Content>(ContentType.post),
142121
limit: 10000,
@@ -157,7 +136,6 @@ export const load = (async (params) => {
157136

158137
// Sponsor Specific
159138
sponsorCourses,
160-
sponsorTutorials,
161139
sponsorPosts,
162140
sponsorPodcasts
163141
}

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

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,6 @@
4646
{#if data?.course}
4747
<RecentPostsList contentType={ContentType.course} list={data.course} />
4848
{/if}
49-
{#if data?.tutorial}
50-
<RecentPostsList contentType={ContentType.tutorial} list={data.tutorial} />
51-
{/if}
5249
{#if data?.podcast}
5350
<RecentPostsList contentType={ContentType.podcast} list={data.podcast} />
5451
{/if}
@@ -63,9 +60,6 @@
6360
{#if data?.course}
6461
<RecentPostsList contentType={ContentType.course} list={data.course} />
6562
{/if}
66-
{#if data?.tutorial}
67-
<RecentPostsList contentType={ContentType.tutorial} list={data.tutorial} />
68-
{/if}
6963
{#if data?.podcast}
7064
<RecentPostsList contentType={ContentType.podcast} list={data.podcast} />
7165
{/if}

0 commit comments

Comments
 (0)