Skip to content

Commit

Permalink
feat(astro): support lessons without parts or chapters
Browse files Browse the repository at this point in the history
  • Loading branch information
AriPerkkio committed Oct 18, 2024
1 parent ad6ad6b commit 1c0694e
Show file tree
Hide file tree
Showing 16 changed files with 754 additions and 464 deletions.
22 changes: 5 additions & 17 deletions packages/astro/src/default/pages/index.astro
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,13 @@ import { joinPaths } from '../utils/url';
const tutorial = await getTutorial();
const part = tutorial.parts[tutorial.firstPartId!];
const chapter = part.chapters[part.firstChapterId!];
const lesson = tutorial.lessons.find((l) => l.id === chapter.firstLessonId)!;
const lesson = tutorial.lessons[0];
const part = lesson.part && tutorial.parts[lesson.part.id];
const chapter = lesson.chapter && part?.chapters[lesson.chapter.id];
if (!lesson) {
throw new Error(
`Unable to find lesson for ${JSON.stringify(
{
partId: tutorial.firstPartId || null,
chapterId: part.firstChapterId || null,
lessonId: chapter.firstLessonId || null,
},
null,
2,
)}`,
);
}
const slug = [part?.slug, chapter?.slug, lesson.slug].filter(Boolean).join('/');
const redirect = joinPaths(import.meta.env.BASE_URL, `/${part.slug}/${chapter.slug}/${lesson.slug}`);
const redirect = joinPaths(import.meta.env.BASE_URL, `/${slug}`);
---

<!doctype html>
Expand Down
52 changes: 26 additions & 26 deletions packages/astro/src/default/utils/__snapshots__/multiple-parts.json
Original file line number Diff line number Diff line change
Expand Up @@ -81,14 +81,6 @@
"id": "1-first",
"filepath": "1-part/1-chapter/1-first/content.md",
"order": 0,
"part": {
"id": "1-part",
"title": "Basics"
},
"chapter": {
"id": "1-chapter",
"title": "The first chapter in part 1"
},
"Markdown": "Markdown for tutorial",
"slug": "lesson-slug",
"files": [
Expand All @@ -99,6 +91,14 @@
"1-part-1-chapter-1-first-solution.json",
[]
],
"part": {
"id": "1-part",
"title": "Basics"
},
"chapter": {
"id": "1-chapter",
"title": "The first chapter in part 1"
},
"next": {
"title": "Welcome to TutorialKit",
"href": "/part-slug/chapter-slug/lesson-slug"
Expand All @@ -116,15 +116,7 @@
},
"id": "1-second",
"filepath": "2-part/2-chapter/1-second/content.md",
"order": 0,
"part": {
"id": "2-part",
"title": "Basics"
},
"chapter": {
"id": "2-chapter",
"title": "The first chapter in part 1"
},
"order": 1,
"Markdown": "Markdown for tutorial",
"slug": "lesson-slug",
"files": [
Expand All @@ -135,6 +127,14 @@
"2-part-2-chapter-1-second-solution.json",
[]
],
"part": {
"id": "2-part",
"title": "Basics"
},
"chapter": {
"id": "2-chapter",
"title": "The first chapter in part 1"
},
"prev": {
"title": "Welcome to TutorialKit",
"href": "/part-slug/chapter-slug/lesson-slug"
Expand All @@ -156,15 +156,7 @@
},
"id": "1-third",
"filepath": "3-part/3-chapter/1-third/content.md",
"order": 0,
"part": {
"id": "3-part",
"title": "Basics"
},
"chapter": {
"id": "3-chapter",
"title": "The first chapter in part 1"
},
"order": 2,
"Markdown": "Markdown for tutorial",
"slug": "lesson-slug",
"files": [
Expand All @@ -175,6 +167,14 @@
"3-part-3-chapter-1-third-solution.json",
[]
],
"part": {
"id": "3-part",
"title": "Basics"
},
"chapter": {
"id": "3-chapter",
"title": "The first chapter in part 1"
},
"prev": {
"title": "Welcome to TutorialKit",
"href": "/part-slug/chapter-slug/lesson-slug"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"parts": {},
"lessons": [
{
"data": {
"type": "lesson",
"title": "Welcome to TutorialKit",
"template": "default",
"i18n": {
"mocked": "default localization"
},
"openInStackBlitz": true
},
"id": "1-lesson",
"filepath": "1-lesson/content.md",
"order": 0,
"Markdown": "Markdown for tutorial",
"slug": "lesson-slug",
"files": [
"1-lesson-files.json",
[]
],
"solution": [
"1-lesson-solution.json",
[]
]
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
{
"parts": {
"1-part": {
"id": "1-part",
"order": 0,
"data": {
"type": "part",
"title": "Basics"
},
"slug": "part-slug",
"chapters": {}
}
},
"lessons": [
{
"data": {
"type": "lesson",
"title": "Welcome to TutorialKit",
"template": "default",
"i18n": {
"mocked": "default localization"
},
"openInStackBlitz": true
},
"id": "1-lesson",
"filepath": "1-part/1-lesson/content.md",
"order": 0,
"Markdown": "Markdown for tutorial",
"slug": "lesson-slug",
"files": [
"1-part-1-lesson-files.json",
[]
],
"solution": [
"1-part-1-lesson-solution.json",
[]
],
"part": {
"id": "1-part",
"title": "Basics"
}
}
],
"firstPartId": "1-part"
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,6 @@
"id": "1-lesson",
"filepath": "1-part/1-chapter/1-lesson/content.md",
"order": 0,
"part": {
"id": "1-part",
"title": "Basics"
},
"chapter": {
"id": "1-chapter",
"title": "The first chapter in part 1"
},
"Markdown": "Markdown for tutorial",
"slug": "lesson-slug",
"files": [
Expand All @@ -54,7 +46,15 @@
"solution": [
"1-part-1-chapter-1-lesson-solution.json",
[]
]
],
"part": {
"id": "1-part",
"title": "Basics"
},
"chapter": {
"id": "1-chapter",
"title": "The first chapter in part 1"
}
}
],
"firstPartId": "1-part"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,6 @@
"id": "1-first",
"filepath": "1-part/1-chapter/1-first/content.md",
"order": 0,
"part": {
"id": "1-part",
"title": "Basics"
},
"chapter": {
"id": "1-chapter",
"title": "The first chapter in part 1"
},
"Markdown": "Markdown for tutorial",
"slug": "lesson-slug",
"files": [
Expand All @@ -55,6 +47,14 @@
"1-part-1-chapter-1-first-solution.json",
[]
],
"part": {
"id": "1-part",
"title": "Basics"
},
"chapter": {
"id": "1-chapter",
"title": "The first chapter in part 1"
},
"next": {
"title": "Welcome to TutorialKit",
"href": "/part-slug/chapter-slug/lesson-slug"
Expand All @@ -73,14 +73,6 @@
"id": "2-second",
"filepath": "1-part/1-chapter/2-second/content.md",
"order": 1,
"part": {
"id": "1-part",
"title": "Basics"
},
"chapter": {
"id": "1-chapter",
"title": "The first chapter in part 1"
},
"Markdown": "Markdown for tutorial",
"slug": "lesson-slug",
"files": [
Expand All @@ -91,6 +83,14 @@
"1-part-1-chapter-2-second-solution.json",
[]
],
"part": {
"id": "1-part",
"title": "Basics"
},
"chapter": {
"id": "1-chapter",
"title": "The first chapter in part 1"
},
"prev": {
"title": "Welcome to TutorialKit",
"href": "/part-slug/chapter-slug/lesson-slug"
Expand All @@ -113,14 +113,6 @@
"id": "3-third",
"filepath": "1-part/1-chapter/3-third/content.md",
"order": 2,
"part": {
"id": "1-part",
"title": "Basics"
},
"chapter": {
"id": "1-chapter",
"title": "The first chapter in part 1"
},
"Markdown": "Markdown for tutorial",
"slug": "lesson-slug",
"files": [
Expand All @@ -131,6 +123,14 @@
"1-part-1-chapter-3-third-solution.json",
[]
],
"part": {
"id": "1-part",
"title": "Basics"
},
"chapter": {
"id": "1-chapter",
"title": "The first chapter in part 1"
},
"prev": {
"title": "Welcome to TutorialKit",
"href": "/part-slug/chapter-slug/lesson-slug"
Expand Down
Loading

0 comments on commit 1c0694e

Please sign in to comment.