|
1 | 1 | import adapter from '@sveltejs/adapter-static'; |
| 2 | +import { readdir } from 'fs/promises'; |
| 3 | +import { join } from 'path'; |
2 | 4 |
|
3 | | -/** @type {import('@sveltejs/kit').Config} */ |
4 | | -const config = { |
5 | | - kit: { |
6 | | - // adapter-auto only supports some environments, see https://svelte.dev/docs/kit/adapter-auto for a list. |
7 | | - // If your environment is not supported, or you settled on a specific environment, switch out the adapter. |
8 | | - // See https://svelte.dev/docs/kit/adapters for more information about adapters. |
9 | | - adapter: adapter({ |
10 | | - pages: 'build', |
11 | | - assets: 'build', |
12 | | - fallback: undefined, |
13 | | - precompress: false, |
14 | | - strict: true |
15 | | - }), |
16 | | - paths: { |
17 | | - base: process.env.CUSTOM_DOMAIN |
18 | | - ? '' |
19 | | - : process.env.NODE_ENV === 'production' |
20 | | - ? '/microfolio' |
21 | | - : '' |
22 | | - }, |
23 | | - prerender: { |
24 | | - handleHttpError: 'warn' |
| 5 | +async function createConfig() { |
| 6 | + const entries = [ |
| 7 | + '/', |
| 8 | + '/projects', |
| 9 | + '/list', |
| 10 | + '/map', |
| 11 | + '/about' |
| 12 | + ]; |
| 13 | + |
| 14 | + try { |
| 15 | + const projectsPath = join(process.cwd(), 'content/projects'); |
| 16 | + const projectFolders = await readdir(projectsPath); |
| 17 | + |
| 18 | + for (const folder of projectFolders) { |
| 19 | + if (folder.startsWith('.') || folder.endsWith('.zip')) continue; |
| 20 | + entries.push(`/projects/${folder}`); |
25 | 21 | } |
| 22 | + |
| 23 | + console.log(`Generated ${entries.length} prerender entries`); |
| 24 | + } catch (error) { |
| 25 | + console.error('Error generating entries:', error); |
26 | 26 | } |
27 | | -}; |
28 | 27 |
|
29 | | -export default config; |
| 28 | + /** @type {import('@sveltejs/kit').Config} */ |
| 29 | + return { |
| 30 | + kit: { |
| 31 | + adapter: adapter({ |
| 32 | + pages: 'build', |
| 33 | + assets: 'build', |
| 34 | + fallback: undefined, |
| 35 | + precompress: false, |
| 36 | + strict: true |
| 37 | + }), |
| 38 | + paths: { |
| 39 | + base: process.env.CUSTOM_DOMAIN |
| 40 | + ? '' |
| 41 | + : process.env.NODE_ENV === 'production' |
| 42 | + ? '/microfolio' |
| 43 | + : '' |
| 44 | + }, |
| 45 | + prerender: { |
| 46 | + handleHttpError: 'warn', |
| 47 | + entries |
| 48 | + } |
| 49 | + } |
| 50 | + }; |
| 51 | +} |
| 52 | + |
| 53 | +export default await createConfig(); |
0 commit comments