-
Notifications
You must be signed in to change notification settings - Fork 82
feat(astro): support lessons without parts or chapters #374
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(astro): support lessons without parts or chapters #374
Conversation
This comment was marked as outdated.
This comment was marked as outdated.
977e911
to
8854d0b
Compare
This comment was marked as outdated.
This comment was marked as outdated.
8854d0b
to
266c7e5
Compare
This comment was marked as outdated.
This comment was marked as outdated.
5d0cef6
to
1c0694e
Compare
518887e
to
e76ce9a
Compare
docs/tutorialkit.dev/src/content/docs/guides/creating-content.mdx
Outdated
Show resolved
Hide resolved
"dev:lessons-in-root": "astro dev --config ./configs/lessons-in-root.ts", | ||
"preview:lessons-in-root": "astro build --config ./configs/lessons-in-root.ts && astro preview --config ./configs/lessons-in-root.ts", | ||
"dev:lessons-in-part": "astro dev --config ./configs/lessons-in-part.ts", | ||
"preview:lessons-in-part": "astro build --config ./configs/lessons-in-part.ts && astro preview --config ./configs/lessons-in-part.ts", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm planning to create scripts/start.mjs
that can be called like node scripts/start.mjs --dev lessons-in-root
to reduce these verbose scripts. But that will be added in follow-up PR.
e76ce9a
to
8b73cc8
Compare
This comment was marked as outdated.
This comment was marked as outdated.
8b73cc8
to
109f309
Compare
109f309
to
e65eee1
Compare
This comment was marked as outdated.
This comment was marked as outdated.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fantastic work on this @AriPerkkio ! 🎉
Can't wait to get this landed 😃
I finished a first pass, I'll try to do another pass later this week 🤞
docs/tutorialkit.dev/src/content/docs/guides/creating-content.mdx
Outdated
Show resolved
Hide resolved
await expect(page.getByText('Lesson in part without chapter')).toBeVisible(); | ||
|
||
// navigation select can take a while to hydrate on page load, click until responsive | ||
await expect(async () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh interesting, what does this expect
call do (compared to having them in the parent function)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The button can become visible before it has been hydrated. Clicking it doesn't do anything. So here if the last await expect(page.locator('[data-state="open"]', { has: button })).toBeVisible({ timeout: 50 })
fails, the whole callback inside expect(callback).toPass()
will be retried -> button is clicked again.
This hydration issue might be related to running <root>/e2e
in dev mode only. I'll try in follow-up PR that if we switch to vite build --watch & vite preview
, would this issue disappear.
if (partId) { | ||
if (!tutorial.parts[partId]) { | ||
throw new Error(`Could not find part '${partId}'`); | ||
} | ||
|
||
lesson.part = { | ||
id: partId, | ||
title: tutorial.parts[partId].data.title, | ||
}; | ||
} | ||
|
||
_tutorial.parts[partId].chapters[chapterId].lessons[lessonId] = lesson; | ||
if (partId && chapterId) { | ||
if (!tutorial.parts[partId].chapters[chapterId]) { | ||
throw new Error(`Could not find chapter '${chapterId}'`); | ||
} | ||
|
||
lesson.chapter = { | ||
id: chapterId, | ||
title: tutorial.parts[partId].chapters[chapterId].data.title, | ||
}; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm wondering if we should do this in a second pass in case parts, chapters and lessons are not in order.
It's also something that could have been an issue with the previous logic though so maybe we don't need to care about this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At this point they should be ordered:
tutorialkit/packages/astro/src/default/utils/content.ts
Lines 20 to 22 in 0b2896a
const collection = sortCollection(await getCollection('tutorial')); | |
const { tutorial, tutorialMetaData } = await parseCollection(collection); |
tutorialkit/packages/astro/src/default/utils/content.ts
Lines 271 to 278 in 0b2896a
function sortCollection(collection: CollectionEntryTutorial[]) { | |
return collection.sort((a, b) => { | |
const depthA = a.id.split('/').length; | |
const depthB = b.id.split('/').length; | |
return depthA - depthB; | |
}); | |
} |
But yes, it's not visible from this function only. Should we move the sortCollection
function call inside this function, so that we can be sure it's always sorted before looping it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah I missed that, no all good this function is internal to this module 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Amazing work on this @AriPerkkio! 🎉
Super impressed with how much cleaner the code is and overall this is a really high quality PR 💪
Thanks for review @Nemikolh, let's get this merged! 💯 |
Adds support for defining lessons without chapters or parts.
Custom order can be defined using
lessons
in metadata:Mixing structures is not supported and an error is thrown when these are not followed:
part
's or one-or-manylesson
'schapter
's or one-or-manylesson
'sIn practice:
However you can have multiple
part
's, where some contain justchapter
's and some contain justlesson
's:tk-mixed-hierarchy.webm