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

@ -1,13 +1,13 @@
<script> <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 Repl from '@sveltejs/repl';
import ScreenToggle from '$lib/components/ScreenToggle.svelte';
import TableOfContents from './TableOfContents.svelte'; import TableOfContents from './TableOfContents.svelte';
import { browser } from '$app/environment';
import { mapbox_setup, svelteUrl } from '../../../config.js'; import { mapbox_setup, svelteUrl } from '../../../config.js';
import '@sveltejs/site-kit/styles/code.css';
export let data; export let data;
/** @type {import('@sveltejs/repl').default} */ /** @type {import('@sveltejs/repl').default} */
@ -153,6 +153,16 @@
{/if} {/if}
</div> </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> <style>
.tutorial-outer { .tutorial-outer {
position: relative; position: relative;

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

@ -1,9 +1,5 @@
// @ts-check // @ts-check
import adapter from '@sveltejs/adapter-auto'; 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} */ /** @type {import('@sveltejs/kit').Config} */
export default { export default {
@ -12,13 +8,6 @@ export default {
prerender: { prerender: {
// TODO: REMOVE // TODO: REMOVE
handleMissingId: 'ignore', 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