refactor tutorial structure & design

This commit is contained in:
tglide
2023-10-26 17:20:29 +01:00
parent 785c331b9b
commit d4269b05f6
19 changed files with 303 additions and 202 deletions

View File

@@ -0,0 +1,52 @@
import { base } from '$app/paths';
import type { Tutorial } from '$markdoc/layouts/Tutorial.svelte';
const framework_order = ['React', 'Vue', 'SvelteKit'];
export async function load() {
const tutorialsGlob = import.meta.glob('./**/step-1/+page.markdoc', {
eager: true
});
const allTutorials = Object.entries(tutorialsGlob)
.map(([filepath, tutorialList]: [string, unknown]) => {
const { frontmatter } = tutorialList as {
frontmatter: Tutorial;
};
const slug = filepath
.replace('./', '')
.replace('/+page.markdoc', '')
.replace('/step-1', '');
const tutorialName = slug.slice(slug.lastIndexOf('/') + 1);
return {
title: frontmatter.title,
framework: frontmatter.framework,
draft: frontmatter.draft,
href: `${base}/blog/post/${tutorialName}`
};
})
.sort((a, b) => {
// Sort by framework order
const frameworkIndexA = framework_order.indexOf(a.framework as string);
const frameworkIndexB = framework_order.indexOf(b.framework as string);
if (frameworkIndexA > frameworkIndexB) {
return 1;
}
if (frameworkIndexA < frameworkIndexB) {
return -1;
}
// Else, sort by title
return a.title.toLowerCase().localeCompare(b.title.toLowerCase());
});
const drafts = allTutorials.filter((tutorial) => tutorial.draft);
const tutorials = allTutorials.filter((tutorial) => !tutorial.draft);
return {
tutorials,
drafts
};
}