Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

optimise glob imports #29

Merged
merged 1 commit into from
Jun 18, 2024
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
10 changes: 6 additions & 4 deletions apps/svelte.dev/src/lib/server/content.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
import { read } from '$app/server';
import { create_index } from '@sveltejs/site-kit/server/content';

const documents = import.meta.glob<{ default: string }>('../../../content/**/*.md', {
const documents = import.meta.glob<string>('../../../content/**/*.md', {
eager: true,
query: '?url'
query: '?url',
import: 'default'
});

const assets = import.meta.glob<{ default: string }>('../../../content/**/+assets/**', {
const assets = import.meta.glob<string>('../../../content/**/+assets/**', {
eager: true,
query: '?url'
query: '?url',
import: 'default'
});

// https://github.com/vitejs/vite/issues/17453
Expand Down
4 changes: 2 additions & 2 deletions apps/svelte.dev/src/routes/docs/[...path]/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,14 @@
<span class:faded={!prev}>previous</span>

{#if prev}
<a href={prev.path}>{prev.title}</a>
<a href={prev.path}>{prev.metadata.title}</a>
{/if}
</div>

<div>
<span class:faded={!next}>next</span>
{#if next}
<a href={next.path}>{next.title}</a>
<a href={next.path}>{next.metadata.title}</a>
{/if}
</div>
</div>
Expand Down
8 changes: 4 additions & 4 deletions packages/site-kit/src/lib/server/content/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import { extract_frontmatter, slugify } from '$lib/markdown/utils';
import type { Document } from '../../types';

export async function create_index(
documents: Record<string, { default: string }>,
assets: Record<string, { default: string }>,
documents: Record<string, string>,
assets: Record<string, string>,
base: string,
read: (asset: string) => Response
) {
Expand All @@ -15,7 +15,7 @@ export async function create_index(
const file = key.slice(base.length + 1);
const slug = file.replace(/(^|\/)\d+-/g, '$1').replace(/(\/index)?\.md$/, '');

const text = await read(documents[key].default).text();
const text = await read(documents[key]).text();
const { metadata, body } = extract_frontmatter(text);

if (!metadata.title) {
Expand Down Expand Up @@ -59,7 +59,7 @@ export async function create_index(

const document = content[slug];

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

return content;
Expand Down
Loading