Skip to content

Commit 19c5a69

Browse files
committed
support output-file without extension in project index
1 parent 615c4b0 commit 19c5a69

File tree

3 files changed

+16
-5
lines changed

3 files changed

+16
-5
lines changed

src/command/render/output.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import {
3030
contextPdfOutputRecipe,
3131
useContextPdfOutputRecipe,
3232
} from "./output-tex.ts";
33+
import { formatOutputFile } from "../../core/render.ts";
3334

3435
// render commands imply the --output argument for pandoc and the final
3536
// output file to create for the user, but we need a 'recipe' to go from
@@ -50,11 +51,8 @@ export function outputRecipe(
5051
// could be within metadata)
5152
let output = options.flags?.output;
5253
if (!output) {
53-
let outputFile = format.pandoc[kOutputFile];
54+
const outputFile = formatOutputFile(format);
5455
if (outputFile) {
55-
if (!outputFile.match(/\..+$/) && format.render[kOutputExt]) {
56-
outputFile = `${outputFile}.${format.render[kOutputExt]}`;
57-
}
5856
if (isAbsolute(outputFile)) {
5957
output = outputFile;
6058
} else {

src/core/render.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
*
66
*/
77

8+
import { kOutputExt, kOutputFile } from "../config/constants.ts";
9+
import { Format } from "../config/types.ts";
810
import { dirAndStem } from "./path.ts";
911

1012
export function inputFilesDir(input: string) {
@@ -21,3 +23,13 @@ export function figuresDir(pandocTo?: string) {
2123
pandocTo = (pandocTo || "html").replace(/[\+\-].*$/, "");
2224
return "figure-" + pandocTo;
2325
}
26+
27+
export function formatOutputFile(format: Format) {
28+
let outputFile = format.pandoc[kOutputFile];
29+
if (outputFile) {
30+
if (!outputFile.match(/\..+$/) && format.render[kOutputExt]) {
31+
outputFile = `${outputFile}.${format.render[kOutputExt]}`;
32+
}
33+
}
34+
return outputFile;
35+
}

src/project/project-index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ import {
3434
normalizeWebsiteFormat,
3535
} from "./types/website/website-config.ts";
3636
import { kDefaultProjectFileContents } from "./types/project-default.ts";
37+
import { formatOutputFile } from "../core/render.ts";
3738

3839
export interface InputTargetIndex extends Metadata {
3940
title?: string;
@@ -167,7 +168,7 @@ export async function resolveInputTarget(
167168
const formats = formatsPreferHtml(index.formats) as Record<string, Format>;
168169
const format = Object.values(formats)[0];
169170
const [hrefDir, hrefStem] = dirAndStem(href);
170-
const outputFile = format.pandoc[kOutputFile] || `${hrefStem}.html`;
171+
const outputFile = formatOutputFile(format) || `${hrefStem}.html`;
171172
const outputHref = pathWithForwardSlashes(
172173
(absolute ? "/" : "") + join(hrefDir, outputFile),
173174
);

0 commit comments

Comments
 (0)