@@ -157,12 +157,12 @@ export const manuscriptProjectType: ProjectType = {
157
157
const article = computeProjectArticleFile ( projectDir , manuscriptConfig ) ;
158
158
159
159
// Go through project inputs and use any of these as notebooks
160
- const notebooks : Record < string , NotebookPreviewDescriptor > = { } ;
160
+ const notebooks : NotebookPreviewDescriptor [ ] = [ ] ;
161
161
162
162
const explicitNotebooks = manuscriptConfig [ kNotebooks ] ;
163
163
if ( explicitNotebooks ) {
164
- resolveNotebookDescriptors ( explicitNotebooks ) . forEach ( ( nb ) => {
165
- notebooks [ nb . notebook ] = nb ;
164
+ resolveNotebookDescriptors ( explicitNotebooks , true ) . forEach ( ( nb ) => {
165
+ notebooks . push ( nb ) ;
166
166
} ) ;
167
167
} else {
168
168
const inputNotebooks = inputs . files . map ( ( input ) => {
@@ -191,7 +191,7 @@ export const manuscriptProjectType: ProjectType = {
191
191
192
192
if ( inputNotebooks ) {
193
193
resolveNotebookDescriptors ( inputNotebooks ) . forEach ( ( nb ) => {
194
- notebooks [ nb . notebook ] = nb ;
194
+ notebooks . push ( nb ) ;
195
195
} ) ;
196
196
}
197
197
}
@@ -219,10 +219,17 @@ export const manuscriptProjectType: ProjectType = {
219
219
// If there are computations in the main article, the add
220
220
// it as a notebook to be rendered with computations intact
221
221
if ( await hasComputations ( join ( projectDir , article ) ) ) {
222
- notebooks [ article ] = {
223
- notebook : article ,
224
- title : language [ kArticleNotebookLabel ] ,
225
- } ;
222
+ if (
223
+ ! notebooks . find ( ( nb ) => {
224
+ return nb . notebook === article ;
225
+ } )
226
+ ) {
227
+ notebooks . unshift ( {
228
+ notebook : article ,
229
+ title : language [ kArticleNotebookLabel ] ,
230
+ order : 9999 ,
231
+ } ) ;
232
+ }
226
233
jatsNotebooks . unshift ( {
227
234
input : join ( projectDir , article ) ,
228
235
token : `nb-article` ,
@@ -232,6 +239,7 @@ export const manuscriptProjectType: ProjectType = {
232
239
233
240
// Determine the notebooks that are being declared explicitly in
234
241
// in the manuscript configuration
242
+ /*
235
243
if (manuscriptConfig.notebooks !== undefined) {
236
244
const specifiedNotebooks = Array.isArray(manuscriptConfig.notebooks)
237
245
? manuscriptConfig.notebooks
@@ -240,6 +248,7 @@ export const manuscriptProjectType: ProjectType = {
240
248
notebooks[nb.notebook] = nb;
241
249
});
242
250
}
251
+ */
243
252
244
253
// Note JATS subarticles for the JATS format
245
254
config [ kQuartoInternal ] = {
@@ -263,7 +272,7 @@ export const manuscriptProjectType: ProjectType = {
263
272
const resolvedManuscriptOptions : ResolvedManuscriptConfig = {
264
273
...manuscriptConfig ,
265
274
article,
266
- notebooks : Object . values ( notebooks ) ,
275
+ notebooks : notebooks ,
267
276
mecaFile : mecaFileOutput ,
268
277
[ kEnvironmentFiles ] : environmentFiles ,
269
278
} ;
@@ -505,8 +514,8 @@ export const manuscriptProjectType: ProjectType = {
505
514
// If the user isn't explicitly providing a notebook list
506
515
// then automatically create notebooks for the other items in
507
516
// the project
508
- const outputNbs : Record < string , NotebookPreviewDescriptor > = { } ;
509
517
const notebooks = manuscriptConfig . notebooks || [ ] ;
518
+ const orderedNbs : NotebookPreviewDescriptor [ ] = [ ] ;
510
519
for ( const notebook of notebooks ) {
511
520
// Use the input to create a title for the notebook
512
521
// if needed
@@ -521,12 +530,12 @@ export const manuscriptProjectType: ProjectType = {
521
530
}
522
531
} ;
523
532
524
- outputNbs [ notebook . notebook ] = {
533
+ orderedNbs . push ( {
525
534
...notebook ,
526
535
title : notebook . title || await createTitle ( ) ,
527
- } ;
536
+ } ) ;
528
537
}
529
- extras [ kNotebooks ] = Object . values ( outputNbs ) ;
538
+ extras [ kNotebooks ] = orderedNbs ;
530
539
} else if ( isArticle && isLatexOutput ( format . pandoc ) ) {
531
540
if ( isLatexOutput ( format . pandoc ) ) {
532
541
// By default, keep tex and clean things up ourselves
@@ -687,19 +696,25 @@ const hasComputations = async (file: string) => {
687
696
688
697
const resolveNotebookDescriptor = (
689
698
nb : string | NotebookPreviewDescriptor ,
699
+ order ?: number ,
690
700
) : NotebookPreviewDescriptor => {
691
701
if ( typeof nb === "string" ) {
692
- nb = { notebook : nb } ;
702
+ nb = { notebook : nb , order } ;
693
703
}
694
704
return nb ;
695
705
} ;
696
706
697
707
const resolveNotebookDescriptors = (
698
708
nbs : Array < string | NotebookPreviewDescriptor > ,
709
+ orderNotebooks = false ,
699
710
) => {
700
711
const resolvedNbs : NotebookPreviewDescriptor [ ] = [ ] ;
712
+ let order = 0 ;
701
713
for ( const nb of nbs ) {
702
- resolvedNbs . push ( resolveNotebookDescriptor ( nb ) ) ;
714
+ resolvedNbs . push (
715
+ resolveNotebookDescriptor ( nb , orderNotebooks ? order : undefined ) ,
716
+ ) ;
717
+ order ++ ;
703
718
}
704
719
return resolvedNbs ;
705
720
} ;
0 commit comments