Skip to content

Commit

Permalink
Merge pull request #2 from khromov/new-presets
Browse files Browse the repository at this point in the history
New presets
  • Loading branch information
khromov authored Dec 4, 2024
2 parents 229fede + 7e4c5ef commit ae5242a
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 20 deletions.
51 changes: 37 additions & 14 deletions src/lib/presets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,44 @@ export type PresetConfig = {
}

const SVELTE_5_PROMPT =
'Always use Svelte 5 runes and Svelte 5 syntax. Runes do not need to be imported, they are globals. $state() runes are always declared using `let`, never with `const`. When passing a function to $derived, you must always use $derived.by().'
'Always use Svelte 5 runes and Svelte 5 syntax. Runes do not need to be imported, they are globals. $state() runes are always declared using `let`, never with `const`. When passing a function to $derived, you must always use $derived.by(() => ...).'

export const presets: Record<string, PresetConfig> = {
'svelte-complete': {
title: '⭐️ Svelte + SvelteKit (Recommended - Large preset)',
description: 'Complete Svelte + SvelteKit docs excluding legacy, notes and migration docs',
'svelte-complete-medium': {
title: '⭐️ Svelte + SvelteKit (Recommended - Medium preset)',
description:
'Complete Svelte + SvelteKit docs excluding certain advanced sections, legacy, notes and migration docs',
owner: 'sveltejs',
repo: 'svelte.dev',
glob: [
// Svelte
'**/apps/svelte.dev/content/docs/svelte/**/*.md',
// SvelteKit
'**/apps/svelte.dev/content/docs/kit/**/*.md'
],
ignore: [],
ignore: [
// Svelte ignores
'**/apps/svelte.dev/content/docs/svelte/07-misc/04-custom-elements.md',
'**/apps/svelte.dev/content/docs/svelte/07-misc/06-v4-migration-guide.md',
'**/apps/svelte.dev/content/docs/svelte/07-misc/07-v5-migration-guide.md',
'**/apps/svelte.dev/content/docs/svelte/07-misc/99-faq.md',
'**/apps/svelte.dev/content/docs/svelte/07-misc/xx-reactivity-indepth.md',
'**/apps/svelte.dev/content/docs/svelte/98-reference/21-svelte-legacy.md',
'**/apps/svelte.dev/content/docs/svelte/99-legacy/**/*.md',
'**/apps/svelte.dev/content/docs/svelte/98-reference/30-runtime-errors.md',
'**/apps/svelte.dev/content/docs/svelte/98-reference/30-runtime-warnings.md',
'**/apps/svelte.dev/content/docs/svelte/98-reference/30-compiler-errors.md',
'**/apps/svelte.dev/content/docs/svelte/98-reference/30-compiler-warnings.md',
'**/xx-*.md',
// SvelteKit ignores
'**/apps/svelte.dev/content/docs/kit/25-build-and-deploy/*adapter-*.md',
'**/apps/svelte.dev/content/docs/kit/25-build-and-deploy/99-writing-adapters.md',
'**/apps/svelte.dev/content/docs/kit/30-advanced/70-packaging.md',
'**/apps/svelte.dev/content/docs/kit/40-best-practices/05-performance.md',
'**/apps/svelte.dev/content/docs/kit/40-best-practices/10-accessibility.md', // May the a11y gods have mercy on our souls
'**/apps/svelte.dev/content/docs/kit/60-appendix/**/*.md',
'**/xx-*.md'
],
prompt: SVELTE_5_PROMPT,
minimize: {
removeLegacy: true,
Expand All @@ -44,17 +69,14 @@ export const presets: Record<string, PresetConfig> = {
normalizeWhitespace: true
}
},
'svelte-complete-small': {
title: '⭐️ Svelte + SvelteKit (Recommended - Small preset)',
description:
'Tutorial content and Svelte + Kit reference docs, excluding legacy, notes and migration docs',
'svelte-complete': {
title: 'Svelte + SvelteKit (Large preset)',
description: 'Complete Svelte + SvelteKit docs excluding legacy, notes and migration docs',
owner: 'sveltejs',
repo: 'svelte.dev',
glob: [
'**/apps/svelte.dev/content/tutorial/**/*.md',
'**/apps/svelte.dev/content/docs/svelte/02-runes/**/*.md',
'**/apps/svelte.dev/content/docs/svelte/98-reference/**/*.md',
'**/apps/svelte.dev/content/docs/kit/98-reference/**/*.md'
'**/apps/svelte.dev/content/docs/svelte/**/*.md',
'**/apps/svelte.dev/content/docs/kit/**/*.md'
],
ignore: [],
prompt: SVELTE_5_PROMPT,
Expand All @@ -67,8 +89,9 @@ export const presets: Record<string, PresetConfig> = {
normalizeWhitespace: true
}
},

'svelte-complete-tiny': {
title: '⭐️ Svelte + SvelteKit (Recommended - Tiny preset)',
title: 'Svelte + SvelteKit (Tiny preset)',
description: 'Tutorial content only',
owner: 'sveltejs',
repo: 'svelte.dev',
Expand Down
14 changes: 10 additions & 4 deletions src/routes/[preset]/+server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,18 @@ export const GET: RequestHandler = async ({ params }) => {
console.log(`Final combined response length: ${response.length}`)
}

const headers: HeadersInit = {
'Content-Type': 'text/plain; charset=utf-8'
}

// Serve as a download if not in development mode
if (!dev) {
headers['Content-Disposition'] = `attachment; filename="${presetNames.join('-')}.txt"`
}

return new Response(response, {
status: 200,
headers: {
'Content-Type': 'text/plain; charset=utf-8',
'Content-Disposition': `attachment; filename="${presetNames.join('-')}.txt"`
}
headers
})
} catch (e) {
console.error(`Error fetching documentation for presets [${presetNames.join(', ')}]:`, e)
Expand Down
4 changes: 2 additions & 2 deletions src/routes/[preset]/size/+server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ export const GET: RequestHandler = async ({ params }) => {
return sizeKb
}, {
// Cache size calculations for longer since they change less frequently
minTimeToStale: 24 * 60 * 60 * 1000, // 24 hours
maxTimeToLive: 7 * 24 * 60 * 60 * 1000 // 7 days
minTimeToStale: 0, // 24 hours
maxTimeToLive: 1 // 7 days
})

// Ensure the response is also strictly an integer
Expand Down

0 comments on commit ae5242a

Please sign in to comment.