Skip to content

Commit

Permalink
temporary wall off of manuscript reuse of qmd notebooks (everything s…
Browse files Browse the repository at this point in the history
…till works, just less efficient)
  • Loading branch information
dragonstyle committed Jul 12, 2023
1 parent fc43119 commit c7d2ad7
Showing 1 changed file with 59 additions and 51 deletions.
110 changes: 59 additions & 51 deletions src/project/types/manuscript/manuscript-render.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ import { kNotebookViewStyle, kOutputFile } from "../../../config/constants.ts";
import { dirAndStem } from "../../../core/path.ts";
import { basename } from "../../../vendor/deno.land/std@0.185.0/path/win32.ts";
import { readBaseInputIndex } from "../../project-index.ts";
import { isQmdFile } from "../../../execute/qmd.ts";

interface ManuscriptCompletion {
completion: PandocRenderCompletion;
Expand Down Expand Up @@ -97,67 +98,74 @@ export const manuscriptRenderer = (
completion: await renderPandoc(resolvedExecutedFile, true),
cleanup: !isArticle,
}];
} else if (isHtmlOutput(executedFile.context.format.pandoc, true)) {
} else if (
isHtmlOutput(executedFile.context.format.pandoc, true)
) {
const result = [];
if (!isQmdFile(input)) {
// Use the executed file to render the output ipynb
const notebook = nbContext.get(input, context);
let downloadHref;
if (!notebook || !notebook[kRenderedIPynb]) {
progressMessage("Rendering output notebook");
const ipynbExecutedFile = nbContext.resolve(
input,
kRenderedIPynb,
executedFile,
);
const [_dir, stem] = dirAndStem(input);
downloadHref = `${stem}.out.ipynb`;
result.push({
completion: await renderPandoc(ipynbExecutedFile, true),
cleanup: !isArticle,
});
}
progressMessage("Rendering HTML preview");

// Use the executed file to render the output ipynb
const notebook = nbContext.get(input, context);
let downloadHref;
if (!notebook || !notebook[kRenderedIPynb]) {
progressMessage("Rendering output notebook");
const ipynbExecutedFile = nbContext.resolve(
// Find the title of this notebook
let title;
const nbDescriptor = notebookDescriptor(
input,
kRenderedIPynb,
executedFile,
manuscriptConfig,
context,
);
const [_dir, stem] = dirAndStem(input);
downloadHref = `${stem}.out.ipynb`;
result.push({
completion: await renderPandoc(ipynbExecutedFile, true),
cleanup: !isArticle,
});
}
progressMessage("Rendering HTML preview");

// Find the title of this notebook
let title;
const nbDescriptor = notebookDescriptor(input, manuscriptConfig, context);
if (nbDescriptor) {
title = nbDescriptor.title;
downloadHref = nbDescriptor["download-url"];
}
if (nbDescriptor) {
title = nbDescriptor.title;
downloadHref = nbDescriptor["download-url"];
}

if (!title) {
const inputIndex = await readBaseInputIndex(input, context);
if (inputIndex) {
title = inputIndex.title;
if (!title) {
const inputIndex = await readBaseInputIndex(input, context);
if (inputIndex) {
title = inputIndex.title;
}
}
}

// Compute the back href
const dirOffset = relative(dirname(input), context.dir);
const index = join(dirOffset, "index.html");
// Compute the back href
const dirOffset = relative(dirname(input), context.dir);
const index = join(dirOffset, "index.html");

// Compute the notebook metadata
const notebookMetadata = {
title: title || basename(input),
filename: basename(input),
backHref: parentOutputFiles["html"] || index,
downloadHref: downloadHref || basename(input),
downloadFile: basename(input),
};
// Compute the notebook metadata
const notebookMetadata = {
title: title || basename(input),
filename: basename(input),
backHref: parentOutputFiles["html"] || index,
downloadHref: downloadHref || basename(input),
downloadFile: basename(input),
};

const resolvedExecutedFile = nbContext.resolve(
input,
kHtmlPreview,
executedFile,
notebookMetadata,
);
const resolvedExecutedFile = nbContext.resolve(
input,
kHtmlPreview,
executedFile,
notebookMetadata,
);

result.push({
completion: await renderPandoc(resolvedExecutedFile, true),
cleanup: !isArticle,
});
result.push({
completion: await renderPandoc(resolvedExecutedFile, true),
cleanup: !isArticle,
});
}
return result;
}
};
Expand Down

0 comments on commit c7d2ad7

Please sign in to comment.