@@ -4,20 +4,18 @@ import type { Document } from '../../types';
44export 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 ( / ( \/ i n d e x ) ? \. m d $ / , '' ) ;
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