|
|
|
|
@ -1,5 +1,4 @@
|
|
|
|
|
import { extractFrontmatter } from '@sveltejs/site-kit/markdown';
|
|
|
|
|
import fs from 'node:fs';
|
|
|
|
|
import { CONTENT_BASE_PATHS } from '../../../constants.js';
|
|
|
|
|
import { render_content } from '../renderer.js';
|
|
|
|
|
|
|
|
|
|
@ -23,24 +22,27 @@ export async function get_parsed_tutorial(tutorial_data, slug) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @returns {import('./types').TutorialData}
|
|
|
|
|
* @returns {Promise<import('./types').TutorialData>}
|
|
|
|
|
*/
|
|
|
|
|
export function get_tutorial_data(base = CONTENT_BASE_PATHS.TUTORIAL) {
|
|
|
|
|
export async function get_tutorial_data(base = CONTENT_BASE_PATHS.TUTORIAL) {
|
|
|
|
|
const { readdir, readFile, stat } = await import('node:fs/promises');
|
|
|
|
|
|
|
|
|
|
const tutorials = [];
|
|
|
|
|
|
|
|
|
|
for (const subdir of fs.readdirSync(base)) {
|
|
|
|
|
for (const subdir of await readdir(base)) {
|
|
|
|
|
const section = {
|
|
|
|
|
title: '', // Initialise with empty
|
|
|
|
|
slug: subdir.split('-').slice(1).join('-'),
|
|
|
|
|
tutorials: []
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
if (!(fs.statSync(`${base}/${subdir}`).isDirectory() || subdir.endsWith('meta.json'))) continue;
|
|
|
|
|
if (!((await stat(`${base}/${subdir}`)).isDirectory() || subdir.endsWith('meta.json')))
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
if (!subdir.endsWith('meta.json'))
|
|
|
|
|
section.title = JSON.parse(fs.readFileSync(`${base}/${subdir}/meta.json`, 'utf-8')).title;
|
|
|
|
|
section.title = JSON.parse(await readFile(`${base}/${subdir}/meta.json`, 'utf-8')).title;
|
|
|
|
|
|
|
|
|
|
for (const section_dir of fs.readdirSync(`${base}/${subdir}`)) {
|
|
|
|
|
for (const section_dir of await readdir(`${base}/${subdir}`)) {
|
|
|
|
|
const match = /\d{2}-(.+)/.exec(section_dir);
|
|
|
|
|
if (!match) continue;
|
|
|
|
|
|
|
|
|
|
@ -49,22 +51,22 @@ export function get_tutorial_data(base = CONTENT_BASE_PATHS.TUTORIAL) {
|
|
|
|
|
const tutorial_base_dir = `${base}/${subdir}/${section_dir}`;
|
|
|
|
|
|
|
|
|
|
// Read the file, get frontmatter
|
|
|
|
|
const contents = fs.readFileSync(`${tutorial_base_dir}/text.md`, 'utf-8');
|
|
|
|
|
const contents = await readFile(`${tutorial_base_dir}/text.md`, 'utf-8');
|
|
|
|
|
const { metadata, body } = extractFrontmatter(contents);
|
|
|
|
|
|
|
|
|
|
// Get the contents of the apps.
|
|
|
|
|
const completion_states_data = { initial: [], complete: [] };
|
|
|
|
|
for (const app_dir of fs.readdirSync(tutorial_base_dir)) {
|
|
|
|
|
for (const app_dir of await readdir(tutorial_base_dir)) {
|
|
|
|
|
if (!app_dir.startsWith('app-')) continue;
|
|
|
|
|
|
|
|
|
|
const app_dir_path = `${tutorial_base_dir}/${app_dir}`;
|
|
|
|
|
const app_contents = fs.readdirSync(app_dir_path, 'utf-8');
|
|
|
|
|
const app_contents = await readdir(app_dir_path, 'utf-8');
|
|
|
|
|
|
|
|
|
|
for (const file of app_contents) {
|
|
|
|
|
completion_states_data[app_dir === 'app-a' ? 'initial' : 'complete'].push({
|
|
|
|
|
name: file,
|
|
|
|
|
type: file.split('.').at(-1),
|
|
|
|
|
content: fs.readFileSync(`${app_dir_path}/${file}`, 'utf-8')
|
|
|
|
|
content: await readFile(`${app_dir_path}/${file}`, 'utf-8')
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|