Rvert to old hack

pull/8427/head
Puru Vijay 4 years ago
parent db672cf662
commit 009051a9f5

@ -2,9 +2,7 @@
import fs from 'node:fs';
import { extract_frontmatter } from '../markdown/index.js';
const base = new URL('../../../../../../site/content/tutorial/', import.meta.url).pathname;
console.log(base);
const base = '../../site/content/tutorial/';
/**
* @returns {import('./types').TutorialData}
@ -37,18 +35,18 @@ export function get_tutorial_data() {
const { metadata, body } = extract_frontmatter(contents);
// Get the contents of the apps.
const completionStatesData = { initial: [], complete: [] };
for (const appDir of fs.readdirSync(tutorial_base_dir)) {
if (!appDir.startsWith('app-')) continue;
const completion_states_data = { initial: [], complete: [] };
for (const app_dir of fs.readdirSync(tutorial_base_dir)) {
if (!app_dir.startsWith('app-')) continue;
const appDirPath = `${tutorial_base_dir}/${appDir}`;
const appContents = fs.readdirSync(appDirPath, 'utf-8');
const app_dir_path = `${tutorial_base_dir}/${app_dir}`;
const app_contents = fs.readdirSync(app_dir_path, 'utf-8');
for (const file of appContents) {
completionStatesData[appDir === 'app-a' ? 'initial' : 'complete'].push({
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(`${appDirPath}/${file}`, 'utf-8'),
content: fs.readFileSync(`${app_dir_path}/${file}`, 'utf-8'),
});
}
}
@ -58,7 +56,7 @@ export function get_tutorial_data() {
slug,
content: body,
dir: `${subdir}/${section_dir}`,
...completionStatesData,
...completion_states_data,
});
}

@ -1,13 +1,13 @@
<script>
import { browser } from '$app/environment';
import '@sveltejs/site-kit/styles/code.css';
import ScreenToggle from '$lib/components/ScreenToggle.svelte';
import Repl from '@sveltejs/repl';
import ScreenToggle from '$lib/components/ScreenToggle.svelte';
import TableOfContents from './TableOfContents.svelte';
import { browser } from '$app/environment';
import { mapbox_setup, svelteUrl } from '../../../config.js';
import '@sveltejs/site-kit/styles/code.css';
export let data;
/** @type {import('@sveltejs/repl').default} */
@ -153,6 +153,16 @@
{/if}
</div>
<!-- HACK to prerender -->
<p style="display: none;">
{#each data.tutorials_list as { tutorials }}
{#each tutorials as { slug }}
<!-- svelte-ignore a11y-missing-content -->
<a href="/tutorial/{slug}" />
{/each}
{/each}
</p>
<style>
.tutorial-outer {
position: relative;

@ -14,7 +14,6 @@
<nav>
<a
rel="prefetch"
aria-label="Previous tutorial step"
class="no-underline"
href="/tutorial/{(selected.prev || selected).slug}"
@ -46,7 +45,6 @@
</div>
<a
rel="prefetch"
aria-label="Next tutorial step"
class="no-underline"
href="/tutorial/{(selected.next || selected).slug}"
@ -109,6 +107,6 @@
height: 100%;
opacity: 0.0001;
cursor: pointer;
-webkit-appearance: none;
appearance: none;
}
</style>

@ -1,9 +1,5 @@
// @ts-check
import adapter from '@sveltejs/adapter-auto';
import {
get_tutorial_data,
get_tutorial_list,
} from './src/lib/server/tutorial/get-tutorial-data.js';
/** @type {import('@sveltejs/kit').Config} */
export default {
@ -12,13 +8,6 @@ export default {
prerender: {
// TODO: REMOVE
handleMissingId: 'ignore',
entries: ['*', ...tutorial_entries()],
},
},
};
function tutorial_entries() {
return get_tutorial_list(get_tutorial_data()).flatMap(({ tutorials }) =>
tutorials.map((tutorial) => /** @type {`/${string}`} */ ('/tutorial/' + tutorial.slug))
);
}

Loading…
Cancel
Save