@@ -10,7 +10,11 @@ import { basename, join } from "path/mod.ts";
1010
1111import * as ld from "../../../core/lodash.ts" ;
1212
13- import { ensureTrailingSlash , safeExistsSync } from "../../../core/path.ts" ;
13+ import {
14+ ensureTrailingSlash ,
15+ pathWithForwardSlashes ,
16+ safeExistsSync ,
17+ } from "../../../core/path.ts" ;
1418import { FormatLanguage , Metadata } from "../../../config/types.ts" ;
1519
1620import {
@@ -90,6 +94,7 @@ import {
9094 NavigationItemObject ,
9195 PageFooterRegion ,
9296} from "../../../resources/types/schema-types.ts" ;
97+ import { projectType } from "../project-types.ts" ;
9398
9499export const kBookChapters = "chapters" ;
95100export const kBookAppendix = "appendices" ;
@@ -455,7 +460,7 @@ function downloadTools(
455460 config : ProjectConfig ,
456461) : SidebarTool [ ] | undefined {
457462 // Filter the user actions to the set that are single file books
458- const downloadActions = websiteConfigActions ( "downloads" , kBook , config ) ;
463+ const downloadActions = websiteConfigActions ( kBookDownloads , kBook , config ) ;
459464 const filteredActions = downloadActions . filter ( ( action ) => {
460465 const format = defaultWriterFormat ( action ) ;
461466 if ( format ) {
@@ -467,19 +472,32 @@ function downloadTools(
467472
468473 // Map the action into sidebar items
469474 const outputStem = bookOutputStem ( projectDir , config ) ;
475+ const projType = projectType ( config . project . type ) ;
470476 const downloads = filteredActions . map ( ( action ) => {
471477 const format = defaultWriterFormat ( action ) ;
478+ const outputDir = projType . formatOutputDirectory
479+ ? projType . formatOutputDirectory ( format ) || ""
480+ : "" ;
481+
472482 const downloadItem = kDownloadableItems [ action ] ;
473483 if ( downloadItem ) {
474484 return {
475485 icon : downloadItem . icon ,
476486 text : `Download ${ downloadItem . name } ` ,
477- href : `/${ outputStem } .${ format . render [ kOutputExt ] } ` ,
487+ href : pathWithForwardSlashes ( join (
488+ "/" ,
489+ outputDir ,
490+ `/${ outputStem } .${ format . render [ kOutputExt ] } ` ,
491+ ) ) ,
478492 } ;
479493 } else {
480494 return {
481495 text : `Download action}` ,
482- href : `/${ outputStem } .${ format . render [ kOutputExt ] } ` ,
496+ href : pathWithForwardSlashes ( join (
497+ "/" ,
498+ outputDir ,
499+ `${ outputStem } .${ format . render [ kOutputExt ] } ` ,
500+ ) ) ,
483501 } ;
484502 }
485503 } ) ;
0 commit comments