Skip to content

Commit 7ae144e

Browse files
committed
chore: use new base option for import.meta.glob
1 parent 1efc7ee commit 7ae144e

File tree

2 files changed

+14
-19
lines changed

2 files changed

+14
-19
lines changed

apps/svelte.dev/src/lib/server/content.ts

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,21 @@ import { read } from '$app/server';
22
import type { Document, DocumentSummary } from '@sveltejs/site-kit';
33
import { create_index } from '@sveltejs/site-kit/server/content';
44

5-
const documents = import.meta.glob<string>('../../../content/**/*.md', {
5+
const documents = import.meta.glob<string>('**/*.md', {
6+
base: '../../../content',
67
eager: true,
78
query: '?url',
89
import: 'default'
910
});
1011

11-
const assets = import.meta.glob<string>(
12-
['../../../content/**/+assets/**', '../../../content/**/+assets/**/.env'],
13-
{
14-
eager: true,
15-
query: '?url',
16-
import: 'default'
17-
}
18-
);
12+
const assets = import.meta.glob<string>(['**/+assets/**', '**/+assets/**/.env'], {
13+
base: '../../../content',
14+
eager: true,
15+
query: '?url',
16+
import: 'default'
17+
});
1918

20-
// https://github.com/vitejs/vite/issues/17453
21-
export const index = await create_index(documents, assets, '../../../content', read);
19+
export const index = await create_index(documents, assets, read);
2220

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

packages/site-kit/src/lib/server/content/index.ts

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,18 @@ import type { Document } from '../../types';
44
export async function create_index(
55
documents: Record<string, string>,
66
assets: Record<string, string>,
7-
base: string,
87
read: (asset: string) => Response
98
): Promise<Record<string, Document>> {
109
const content: Record<string, Document> = {};
1110

1211
const roots: Document[] = [];
1312

14-
for (const key in documents) {
15-
if (key.includes('+assets')) continue;
13+
for (const file in documents) {
14+
if (file.includes('+assets')) continue;
1615

17-
const file = key.slice(base.length + 1);
1816
const slug = file.replace(/(^|\/)[\d-]+-/g, '$1').replace(/(\/index)?\.md$/, '');
1917

20-
const text = await read(documents[key]).text();
18+
const text = await read(documents[file]).text();
2119
let { metadata, body } = extract_frontmatter(text);
2220

2321
if (!metadata.title) {
@@ -83,13 +81,12 @@ export async function create_index(
8381
}
8482
}
8583

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

92-
(document.assets ??= {})[file] = assets[key];
89+
(document.assets ??= {})[file] = assets[path];
9390
}
9491

9592
let prev: Document | null = null;

0 commit comments

Comments
 (0)