@@ -29,7 +29,7 @@ export default {
2929 * @param {Partial<GeneratorOptions> } options
3030 * @returns {Promise<Output> }
3131 */
32- async generate ( input , { output } ) {
32+ async generate ( input , { output, index } ) {
3333 /**
3434 * The consolidated output object that will contain
3535 * combined data from all sections in the input.
@@ -49,8 +49,26 @@ export default {
4949 */
5050 const propertiesToCopy = Object . keys ( generatedValue ) ;
5151
52+ // Create a map of api name to index position for sorting
53+ const indexOrder = new Map (
54+ index ?. map ( ( { api } , position ) => [ `doc/api/${ api } .md` , position ] ) ?? [ ]
55+ ) ;
56+
57+ // Sort input by index order (documents not in index go to the end)
58+ const sortedInput = input . toSorted ( ( a , b ) => {
59+ const aOrder = indexOrder . get ( a . source ) ?? Infinity ;
60+ const bOrder = indexOrder . get ( b . source ) ?? Infinity ;
61+
62+ return aOrder - bOrder ;
63+ } ) ;
64+
5265 // Aggregate all sections into the output
53- for ( const section of input ) {
66+ for ( const section of sortedInput ) {
67+ // Skip index.json - it has no useful content, just navigation
68+ if ( section . api === 'index' ) {
69+ continue ;
70+ }
71+
5472 for ( const property of propertiesToCopy ) {
5573 const items = section [ property ] ;
5674
0 commit comments