@@ -120,14 +120,15 @@ export async function processNotebookEmbeds(
120120
121121 const nbAbsPath = join ( inputDir , notebookPath ) ;
122122 const htmlPreview = await renderHtmlView (
123+ inputDir ,
123124 nbAbsPath ,
124125 nbPreviewOptions ,
125126 format ,
126127 services ,
127128 ) ;
128129 return {
129130 title : htmlPreview . title ,
130- href : relative ( inputDir , htmlPreview . href ) ,
131+ href : htmlPreview . href ,
131132 } ;
132133 } else {
133134 return {
@@ -222,47 +223,54 @@ export async function processNotebookEmbeds(
222223 }
223224
224225 // Validate that there are no unused notebooks in the front matter
225- nbViewConfig . unused ( linkedNotebooks ) ;
226+ if ( nbViewConfig ) {
227+ nbViewConfig . unused ( linkedNotebooks ) ;
228+ }
226229 }
227230}
228231
229232function notebookViewConfig (
230233 notebookPublish ?: boolean | NotebookPublishOptions | NotebookPublishOptions [ ] ,
231234) {
232235 const nbOptions : Record < string , NotebookViewOptions > = { } ;
233- if ( notebookPublish && typeof ( notebookPublish ) !== "boolean" ) {
234- asArray ( notebookPublish ) . forEach ( ( pub ) => {
235- nbOptions [ pub . notebook ] = {
236- title : pub . title || basename ( pub . notebook ) ,
237- href : pub . url ,
238- } ;
239- } ) ;
240- }
241-
242- return {
243- options : ( notebook : string ) => {
244- return nbOptions [ notebook ] || { title : basename ( notebook ) } ;
245- } ,
246- unused : ( notebooks : string [ ] ) => {
247- Object . keys ( nbOptions ) . forEach ( ( nb ) => {
248- if ( ! notebooks . includes ( nb ) ) {
249- throw new Error (
250- `The notebook ${ nb } is included in 'notebook-view' but isn't used to embed content. Please remove it from 'notebook-view'.` ,
251- ) ;
252- }
236+ if ( notebookPublish ) {
237+ if ( typeof ( notebookPublish ) !== "boolean" ) {
238+ asArray ( notebookPublish ) . forEach ( ( pub ) => {
239+ nbOptions [ pub . notebook ] = {
240+ title : pub . title || basename ( pub . notebook ) ,
241+ href : pub . url ,
242+ } ;
253243 } ) ;
254- } ,
255- } ;
244+ }
245+ return {
246+ options : ( notebook : string ) => {
247+ return nbOptions [ notebook ] || { title : basename ( notebook ) } ;
248+ } ,
249+ unused : ( notebooks : string [ ] ) => {
250+ Object . keys ( nbOptions ) . forEach ( ( nb ) => {
251+ if ( ! notebooks . includes ( nb ) ) {
252+ throw new Error (
253+ `The notebook ${ nb } is included in 'notebook-view' but isn't used to embed content. Please remove it from 'notebook-view'.` ,
254+ ) ;
255+ }
256+ } ) ;
257+ } ,
258+ } ;
259+ } else {
260+ return undefined ;
261+ }
256262}
257263
258264// Renders an HTML preview of a notebook
259265async function renderHtmlView (
260- path : string ,
266+ inputDir : string ,
267+ nbAbsPath : string ,
261268 options : NotebookViewOptions ,
262269 format : Format ,
263270 services : RenderServices ,
264271) : Promise < NotebookView > {
265- const filename = basename ( path ) ;
272+ const filename = basename ( nbAbsPath ) ;
273+ const href = relative ( inputDir , nbAbsPath ) ;
266274
267275 if ( options . href === undefined ) {
268276 // Use the special `embed` template for this render
@@ -272,15 +280,15 @@ async function renderHtmlView(
272280 ) ;
273281 const embedTemplate = renderEjs ( embedHtmlEjs , {
274282 title : options . title ,
275- path,
283+ path : href ,
276284 filename,
277285 } ) ;
278286 const templatePath = services . temp . createFile ( { suffix : "html" } ) ;
279287 Deno . writeTextFileSync ( templatePath , embedTemplate ) ;
280288
281289 // Render the notebook and update the path
282290 const nbPreviewFile = `${ filename } .html` ;
283- await render ( path , {
291+ await render ( nbAbsPath , {
284292 services,
285293 flags : {
286294 metadata : {
@@ -295,7 +303,7 @@ async function renderHtmlView(
295303
296304 return {
297305 title : options . title ,
298- href : join ( dirname ( path ) , nbPreviewFile ) ,
306+ href : join ( dirname ( href ) , nbPreviewFile ) ,
299307 } ;
300308 } else {
301309 return {
0 commit comments