Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion apps/svelte.dev/src/lib/server/content.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ const assets = import.meta.glob<string>(
import: 'default'
}
);
// we need a separate glob import for document assets because we need to use `read` so it needs the actual import, not `?url`
const documents_assets = import.meta.glob<string>(['../../../content/docs/**/+assets/**'], {
eager: true,
import: 'default'
});

const registry_docs = import.meta.glob<string>(
'../../../src/lib/server/generated/registry/*.json',
Expand All @@ -28,7 +33,13 @@ const registry_docs = import.meta.glob<string>(
);

// https://github.com/vitejs/vite/issues/17453
export const index = await create_index(documents, assets, '../../../content', read);
export const index = await create_index(
documents,
assets,
documents_assets,
'../../../content',
read
);

const months = 'Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec'.split(' ');

Expand Down
12 changes: 12 additions & 0 deletions apps/svelte.dev/src/routes/docs/[topic]/assets/[name]/+server.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { read } from '$app/server';
import { docs } from '$lib/server/content';
import { error } from '@sveltejs/kit';

export async function GET({ params: { name, topic } }) {
const assets = docs.topics[`docs/${topic}`].assets;
if (!assets) {
error(404, 'No assets found for this topic');
}

return read(assets[name]);
}
5 changes: 5 additions & 0 deletions packages/site-kit/src/lib/components/Text.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,11 @@
}
}

img {
max-width: 100%;
object-fit: contain;
}

h2 {
margin-top: 7rem;
}
Expand Down
10 changes: 10 additions & 0 deletions packages/site-kit/src/lib/server/content/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import type { Document } from '../../types';
export async function create_index(
documents: Record<string, string>,
assets: Record<string, string>,
documents_assets: Record<string, string>,
base: string,
read: (asset: string) => Response
): Promise<Record<string, Document>> {
Expand Down Expand Up @@ -99,6 +100,15 @@ export async function create_index(
(document.assets ??= {})[file] = assets[key];
}

for (const key in documents_assets) {
const path = key.slice(base.length + 1);
const slug = path.slice(0, path.indexOf('+assets') - 1).replace(/(^|\/)\d+-/g, '$1');
const file = path.slice(path.indexOf('+assets') + 8);
const document = content[slug];

(document.assets ??= {})[file] = documents_assets[key];
}

let prev: Document | null = null;

for (const document of roots) {
Expand Down