Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
feat(astro): support lessons without parts or chapters
  • Loading branch information
AriPerkkio committed Oct 21, 2024
commit e65eee1a28892cd157e245a0c980eeff6b9259c6
59 changes: 59 additions & 0 deletions docs/tutorialkit.dev/src/content/docs/guides/creating-content.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ title: Content creation
description: 'Creating content in TutorialKit.'
---
import { FileTree } from '@astrojs/starlight/components';
import { Tabs, TabItem } from '@astrojs/starlight/components';

From an information architecture perspective, tutorial content is divided into **parts**, which are further divided into **chapters**, each consisting of **lessons**.

Expand Down Expand Up @@ -36,6 +37,64 @@ This structure is reflected in the directory structure of your TutorialKit proje

Navigate into one of these folders to see another folder that represents a **chapter**. Inside the chapter folder, you will find one or more **lesson** folders.

You can also omit parts and chapters, if your tutorial doesn't need that deep hierarchy.

<Tabs>
<TabItem label="Structure">
```plaintext
- Lesson 1: Getting started
- Lesson 2: Adding pages
```
</TabItem>

<TabItem label="File tree">
<FileTree>
- src
- content
- tutorial
- getting-started
- _files/
- _solution/
- content.md
- adding-pages/
- meta.md
- config.ts
- templates/
</FileTree>
</TabItem>
</Tabs>

<Tabs>
<TabItem label="Structure">
```plaintext
- Part 1: Introduction
- Lesson 1: What is Vite?
- Lesson 2: Installing
- …
- Part 2: Project structure
- …
```
</TabItem>

<TabItem label="File tree">
<FileTree>
- src
- content
- tutorial
- introduction/
- what-is-vite/
- _files/
- _solution/
- content.md
- installing/
- project-structure/
- meta.md
- config.ts
- templates/
</FileTree>
</TabItem>
</Tabs>

## A lesson content file

Navigate to the `src/content/tutorial/1-basics/1-introduction/1-welcome` folder and open the `content.md` in your editor. You will see a file structured like this:
Expand Down
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
73 changes: 33 additions & 40 deletions packages/astro/src/default/utils/__snapshots__/multiple-parts.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,9 @@
"title": "The first chapter in part 1",
"type": "chapter"
},
"slug": "chapter-slug",
"firstLessonId": "1-first"
"slug": "chapter-slug"
}
},
"firstChapterId": "1-chapter"
}
},
"2-part": {
"id": "2-part",
Expand All @@ -38,11 +36,9 @@
"title": "The first chapter in part 1",
"type": "chapter"
},
"slug": "chapter-slug",
"firstLessonId": "1-second"
"slug": "chapter-slug"
}
},
"firstChapterId": "2-chapter"
}
},
"3-part": {
"id": "3-part",
Expand All @@ -60,11 +56,9 @@
"title": "The first chapter in part 1",
"type": "chapter"
},
"slug": "chapter-slug",
"firstLessonId": "1-third"
"slug": "chapter-slug"
}
},
"firstChapterId": "3-chapter"
}
}
},
"lessons": [
Expand All @@ -81,14 +75,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 +85,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 +110,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 +121,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 +150,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,11 +161,18 @@
"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"
}
}
],
"firstPartId": "1-part"
]
}
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,44 @@
{
"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"
}
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,9 @@
"title": "The first chapter in part 1",
"type": "chapter"
},
"slug": "chapter-slug",
"firstLessonId": "1-lesson"
"slug": "chapter-slug"
}
},
"firstChapterId": "1-chapter"
}
}
},
"lessons": [
Expand All @@ -37,14 +35,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,8 +44,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"
]
}
Loading