Prerender in svelte.config.js

pull/8427/head
Puru Vijay 4 years ago
parent dcd6f3926c
commit 7990e70560

@ -1,8 +1,10 @@
// @ts-check // @ts-check
import fs from 'node:fs'; import fs from 'node:fs';
import { extract_frontmatter } from '../markdown'; import { extract_frontmatter } from '../markdown/index.js';
const base = '../../site/content/tutorial/'; const base = new URL('../../../../../../site/content/tutorial/', import.meta.url).pathname;
console.log(base);
/** /**
* @returns {import('./types').TutorialData} * @returns {import('./types').TutorialData}

@ -32,7 +32,7 @@
slug: chapter.slug, slug: chapter.slug,
section, section,
chapter, chapter,
prev prev,
}; };
lookup.set(chapter.slug, obj); lookup.set(chapter.slug, obj);
@ -54,13 +54,13 @@
const clone = (file) => ({ const clone = (file) => ({
name: file.name.replace(/.\w+$/, ''), name: file.name.replace(/.\w+$/, ''),
type: file.type, type: file.type,
source: file.content source: file.content,
}); });
$: if (repl) { $: if (repl) {
completed = false; completed = false;
repl.set({ repl.set({
components: data.tutorial.initial.map(clone) components: data.tutorial.initial.map(clone),
}); });
} }
@ -68,13 +68,13 @@
function reset() { function reset() {
repl.update({ repl.update({
components: data.tutorial.initial.map(clone) components: data.tutorial.initial.map(clone),
}); });
} }
function complete() { function complete() {
repl.update({ repl.update({
components: data.tutorial.complete.map(clone) components: data.tutorial.complete.map(clone),
}); });
} }
@ -153,16 +153,6 @@
{/if} {/if}
</div> </div>
<!-- HACK: To prerender all tutorial pages -->
<div style="display: none">
{#each data.tutorials_list as { tutorials }}
{#each tutorials as { slug }}
<!-- svelte-ignore a11y-missing-content -->
<a href="/tutorial/{slug}" />
{/each}
{/each}
</div>
<style> <style>
.tutorial-outer { .tutorial-outer {
position: relative; position: relative;

@ -1,4 +1,9 @@
// @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 {
@ -7,6 +12,12 @@ export default {
prerender: { prerender: {
// TODO: REMOVE // TODO: REMOVE
handleMissingId: 'ignore', handleMissingId: 'ignore',
entries: [
'*',
...get_tutorial_list(get_tutorial_data()).flatMap(({ tutorials }) =>
tutorials.map((tutorial) => /** @type {`/${string}`} */ ('/tutorial/' + tutorial.slug))
),
],
}, },
}, },
}; };

Loading…
Cancel
Save