@@ -4,20 +4,18 @@ import type { Document } from '../../types';
4
4
export async function create_index (
5
5
documents : Record < string , string > ,
6
6
assets : Record < string , string > ,
7
- base : string ,
8
7
read : ( asset : string ) => Response
9
8
) : Promise < Record < string , Document > > {
10
9
const content : Record < string , Document > = { } ;
11
10
12
11
const roots : Document [ ] = [ ] ;
13
12
14
- for ( const key in documents ) {
15
- if ( key . includes ( '+assets' ) ) continue ;
13
+ for ( const file in documents ) {
14
+ if ( file . includes ( '+assets' ) ) continue ;
16
15
17
- const file = key . slice ( base . length + 1 ) ;
18
16
const slug = file . replace ( / ( ^ | \/ ) [ \d - ] + - / g, '$1' ) . replace ( / ( \/ i n d e x ) ? \. m d $ / , '' ) ;
19
17
20
- const text = await read ( documents [ key ] ) . text ( ) ;
18
+ const text = await read ( documents [ file ] ) . text ( ) ;
21
19
let { metadata, body } = extract_frontmatter ( text ) ;
22
20
23
21
if ( ! metadata . title ) {
@@ -83,13 +81,12 @@ export async function create_index(
83
81
}
84
82
}
85
83
86
- for ( const key in assets ) {
87
- const path = key . slice ( base . length + 1 ) ;
84
+ for ( const path in assets ) {
88
85
const slug = path . slice ( 0 , path . indexOf ( '+assets' ) - 1 ) . replace ( / ( ^ | \/ ) \d + - / g, '$1' ) ;
89
86
const file = path . slice ( path . indexOf ( '+assets' ) + 8 ) ;
90
87
const document = content [ slug ] ;
91
88
92
- ( document . assets ??= { } ) [ file ] = assets [ key ] ;
89
+ ( document . assets ??= { } ) [ file ] = assets [ path ] ;
93
90
}
94
91
95
92
let prev : Document | null = null ;
0 commit comments