Skip to content

Commit 33b0398

Browse files
committed
refactor: lessons in root of Tutorial
1 parent 0af3848 commit 33b0398

10 files changed

+508
-464
lines changed

packages/astro/src/default/pages/index.astro

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,22 @@ import { joinPaths } from '../utils/url';
55
const tutorial = await getTutorial();
66
77
const part = tutorial.parts[tutorial.firstPartId!];
8-
const chapter = part.chapters[part?.firstChapterId!];
9-
const lesson = chapter.lessons[chapter?.firstLessonId!];
8+
const chapter = part.chapters[part.firstChapterId!];
9+
const lesson = tutorial.lessons.find((l) => l.id === chapter.firstLessonId)!;
10+
11+
if (!lesson) {
12+
throw new Error(
13+
`Unable to find lesson for ${JSON.stringify(
14+
{
15+
partId: tutorial.firstPartId || null,
16+
chapterId: part.firstChapterId || null,
17+
lessonId: chapter.firstLessonId || null,
18+
},
19+
null,
20+
2,
21+
)}`,
22+
);
23+
}
1024
1125
const redirect = joinPaths(import.meta.env.BASE_URL, `/${part.slug}/${chapter.slug}/${lesson.slug}`);
1226
---

packages/astro/src/default/utils/__snapshots__/multiple-parts.json

Lines changed: 114 additions & 118 deletions
Original file line numberDiff line numberDiff line change
@@ -17,44 +17,6 @@
1717
"type": "chapter"
1818
},
1919
"slug": "chapter-slug",
20-
"lessons": {
21-
"1-first": {
22-
"data": {
23-
"type": "lesson",
24-
"title": "Welcome to TutorialKit",
25-
"template": "default",
26-
"i18n": {
27-
"mocked": "default localization"
28-
},
29-
"openInStackBlitz": true
30-
},
31-
"id": "1-first",
32-
"filepath": "1-part/1-chapter/1-first/content.md",
33-
"order": 0,
34-
"part": {
35-
"id": "1-part",
36-
"title": "Basics"
37-
},
38-
"chapter": {
39-
"id": "1-chapter",
40-
"title": "The first chapter in part 1"
41-
},
42-
"Markdown": "Markdown for tutorial",
43-
"slug": "lesson-slug",
44-
"files": [
45-
"1-part-1-chapter-1-first-files.json",
46-
[]
47-
],
48-
"solution": [
49-
"1-part-1-chapter-1-first-solution.json",
50-
[]
51-
],
52-
"next": {
53-
"title": "Welcome to TutorialKit",
54-
"href": "/part-slug/chapter-slug/lesson-slug"
55-
}
56-
}
57-
},
5820
"firstLessonId": "1-first"
5921
}
6022
},
@@ -77,48 +39,6 @@
7739
"type": "chapter"
7840
},
7941
"slug": "chapter-slug",
80-
"lessons": {
81-
"1-second": {
82-
"data": {
83-
"type": "lesson",
84-
"title": "Welcome to TutorialKit",
85-
"template": "default",
86-
"i18n": {
87-
"mocked": "default localization"
88-
},
89-
"openInStackBlitz": true
90-
},
91-
"id": "1-second",
92-
"filepath": "2-part/2-chapter/1-second/content.md",
93-
"order": 0,
94-
"part": {
95-
"id": "2-part",
96-
"title": "Basics"
97-
},
98-
"chapter": {
99-
"id": "2-chapter",
100-
"title": "The first chapter in part 1"
101-
},
102-
"Markdown": "Markdown for tutorial",
103-
"slug": "lesson-slug",
104-
"files": [
105-
"2-part-2-chapter-1-second-files.json",
106-
[]
107-
],
108-
"solution": [
109-
"2-part-2-chapter-1-second-solution.json",
110-
[]
111-
],
112-
"prev": {
113-
"title": "Welcome to TutorialKit",
114-
"href": "/part-slug/chapter-slug/lesson-slug"
115-
},
116-
"next": {
117-
"title": "Welcome to TutorialKit",
118-
"href": "/part-slug/chapter-slug/lesson-slug"
119-
}
120-
}
121-
},
12242
"firstLessonId": "1-second"
12343
}
12444
},
@@ -141,49 +61,125 @@
14161
"type": "chapter"
14262
},
14363
"slug": "chapter-slug",
144-
"lessons": {
145-
"1-third": {
146-
"data": {
147-
"type": "lesson",
148-
"title": "Welcome to TutorialKit",
149-
"template": "default",
150-
"i18n": {
151-
"mocked": "default localization"
152-
},
153-
"openInStackBlitz": true
154-
},
155-
"id": "1-third",
156-
"filepath": "3-part/3-chapter/1-third/content.md",
157-
"order": 0,
158-
"part": {
159-
"id": "3-part",
160-
"title": "Basics"
161-
},
162-
"chapter": {
163-
"id": "3-chapter",
164-
"title": "The first chapter in part 1"
165-
},
166-
"Markdown": "Markdown for tutorial",
167-
"slug": "lesson-slug",
168-
"files": [
169-
"3-part-3-chapter-1-third-files.json",
170-
[]
171-
],
172-
"solution": [
173-
"3-part-3-chapter-1-third-solution.json",
174-
[]
175-
],
176-
"prev": {
177-
"title": "Welcome to TutorialKit",
178-
"href": "/part-slug/chapter-slug/lesson-slug"
179-
}
180-
}
181-
},
18264
"firstLessonId": "1-third"
18365
}
18466
},
18567
"firstChapterId": "3-chapter"
18668
}
18769
},
70+
"lessons": [
71+
{
72+
"data": {
73+
"type": "lesson",
74+
"title": "Welcome to TutorialKit",
75+
"template": "default",
76+
"i18n": {
77+
"mocked": "default localization"
78+
},
79+
"openInStackBlitz": true
80+
},
81+
"id": "1-first",
82+
"filepath": "1-part/1-chapter/1-first/content.md",
83+
"order": 0,
84+
"part": {
85+
"id": "1-part",
86+
"title": "Basics"
87+
},
88+
"chapter": {
89+
"id": "1-chapter",
90+
"title": "The first chapter in part 1"
91+
},
92+
"Markdown": "Markdown for tutorial",
93+
"slug": "lesson-slug",
94+
"files": [
95+
"1-part-1-chapter-1-first-files.json",
96+
[]
97+
],
98+
"solution": [
99+
"1-part-1-chapter-1-first-solution.json",
100+
[]
101+
],
102+
"next": {
103+
"title": "Welcome to TutorialKit",
104+
"href": "/part-slug/chapter-slug/lesson-slug"
105+
}
106+
},
107+
{
108+
"data": {
109+
"type": "lesson",
110+
"title": "Welcome to TutorialKit",
111+
"template": "default",
112+
"i18n": {
113+
"mocked": "default localization"
114+
},
115+
"openInStackBlitz": true
116+
},
117+
"id": "1-second",
118+
"filepath": "2-part/2-chapter/1-second/content.md",
119+
"order": 0,
120+
"part": {
121+
"id": "2-part",
122+
"title": "Basics"
123+
},
124+
"chapter": {
125+
"id": "2-chapter",
126+
"title": "The first chapter in part 1"
127+
},
128+
"Markdown": "Markdown for tutorial",
129+
"slug": "lesson-slug",
130+
"files": [
131+
"2-part-2-chapter-1-second-files.json",
132+
[]
133+
],
134+
"solution": [
135+
"2-part-2-chapter-1-second-solution.json",
136+
[]
137+
],
138+
"prev": {
139+
"title": "Welcome to TutorialKit",
140+
"href": "/part-slug/chapter-slug/lesson-slug"
141+
},
142+
"next": {
143+
"title": "Welcome to TutorialKit",
144+
"href": "/part-slug/chapter-slug/lesson-slug"
145+
}
146+
},
147+
{
148+
"data": {
149+
"type": "lesson",
150+
"title": "Welcome to TutorialKit",
151+
"template": "default",
152+
"i18n": {
153+
"mocked": "default localization"
154+
},
155+
"openInStackBlitz": true
156+
},
157+
"id": "1-third",
158+
"filepath": "3-part/3-chapter/1-third/content.md",
159+
"order": 0,
160+
"part": {
161+
"id": "3-part",
162+
"title": "Basics"
163+
},
164+
"chapter": {
165+
"id": "3-chapter",
166+
"title": "The first chapter in part 1"
167+
},
168+
"Markdown": "Markdown for tutorial",
169+
"slug": "lesson-slug",
170+
"files": [
171+
"3-part-3-chapter-1-third-files.json",
172+
[]
173+
],
174+
"solution": [
175+
"3-part-3-chapter-1-third-solution.json",
176+
[]
177+
],
178+
"prev": {
179+
"title": "Welcome to TutorialKit",
180+
"href": "/part-slug/chapter-slug/lesson-slug"
181+
}
182+
}
183+
],
188184
"firstPartId": "1-part"
189185
}

packages/astro/src/default/utils/__snapshots__/single-part-chapter-and-lesson.json

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -17,45 +17,45 @@
1717
"type": "chapter"
1818
},
1919
"slug": "chapter-slug",
20-
"lessons": {
21-
"1-lesson": {
22-
"data": {
23-
"type": "lesson",
24-
"title": "Welcome to TutorialKit",
25-
"template": "default",
26-
"i18n": {
27-
"mocked": "default localization"
28-
},
29-
"openInStackBlitz": true
30-
},
31-
"id": "1-lesson",
32-
"filepath": "1-part/1-chapter/1-lesson/content.md",
33-
"order": 0,
34-
"part": {
35-
"id": "1-part",
36-
"title": "Basics"
37-
},
38-
"chapter": {
39-
"id": "1-chapter",
40-
"title": "The first chapter in part 1"
41-
},
42-
"Markdown": "Markdown for tutorial",
43-
"slug": "lesson-slug",
44-
"files": [
45-
"1-part-1-chapter-1-lesson-files.json",
46-
[]
47-
],
48-
"solution": [
49-
"1-part-1-chapter-1-lesson-solution.json",
50-
[]
51-
]
52-
}
53-
},
5420
"firstLessonId": "1-lesson"
5521
}
5622
},
5723
"firstChapterId": "1-chapter"
5824
}
5925
},
26+
"lessons": [
27+
{
28+
"data": {
29+
"type": "lesson",
30+
"title": "Welcome to TutorialKit",
31+
"template": "default",
32+
"i18n": {
33+
"mocked": "default localization"
34+
},
35+
"openInStackBlitz": true
36+
},
37+
"id": "1-lesson",
38+
"filepath": "1-part/1-chapter/1-lesson/content.md",
39+
"order": 0,
40+
"part": {
41+
"id": "1-part",
42+
"title": "Basics"
43+
},
44+
"chapter": {
45+
"id": "1-chapter",
46+
"title": "The first chapter in part 1"
47+
},
48+
"Markdown": "Markdown for tutorial",
49+
"slug": "lesson-slug",
50+
"files": [
51+
"1-part-1-chapter-1-lesson-files.json",
52+
[]
53+
],
54+
"solution": [
55+
"1-part-1-chapter-1-lesson-solution.json",
56+
[]
57+
]
58+
}
59+
],
6060
"firstPartId": "1-part"
6161
}

0 commit comments

Comments
 (0)