Skip to content

Commit

Permalink
🎆 Clean up extra image processing (#601)
Browse files Browse the repository at this point in the history
* 🎆 Eliminate some extra unwanted webp transforms

* 🎆 Only process thumbnails for site builds not static exports
  • Loading branch information
fwkoch committed Sep 15, 2023
1 parent ea19f62 commit 2743af5
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 19 deletions.
5 changes: 5 additions & 0 deletions .changeset/four-spoons-approve.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'myst-cli': patch
---

Only process thumbnails for site builds not static exports
5 changes: 5 additions & 0 deletions .changeset/many-masks-jam.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'myst-cli': patch
---

Eliminate some extra unwanted webp transforms
11 changes: 1 addition & 10 deletions packages/myst-cli/src/build/utils/getFileContent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { resolve } from 'node:path';
import { tic } from 'myst-cli-utils';
import type { LinkTransformer } from 'myst-transforms';
import type { ISession } from '../../session/types.js';
import type { TransformFn } from '../../process/index.js';
import {
selectPageReferenceStates,
loadFile,
Expand All @@ -13,8 +12,7 @@ import {
loadIntersphinx,
combineProjectCitationRenderers,
} from '../../process/index.js';
import { transformWebp } from '../../transforms/index.js';
import { ImageExtensions } from '../../utils/index.js';
import type { ImageExtensions } from '../../utils/index.js';

export async function getFileContent(
session: ISession,
Expand Down Expand Up @@ -55,13 +53,6 @@ export async function getFileContent(
// Consolidate all citations onto single project citation renderer
combineProjectCitationRenderers(session, projectPath);

const extraTransforms: TransformFn[] = [];
if (imageExtensions.includes(ImageExtensions.webp)) {
extraTransforms.push(transformWebp);
}
// if (opts?.extraTransforms) {
// extraTransforms.push(...opts.extraTransforms);
// }
await Promise.all(
allFiles.map(async (file) => {
const pageSlug = pages.find((page) => page.file === file)?.slug;
Expand Down
23 changes: 14 additions & 9 deletions packages/myst-cli/src/process/mdast.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ import {
reduceOutputs,
transformPlaceholderImages,
transformDeleteBase64UrlSource,
transformWebp,
} from '../transforms/index.js';
import type { ImageExtensions } from '../utils/index.js';
import { logMessagesFromVFile } from '../utils/index.js';
Expand Down Expand Up @@ -99,6 +100,7 @@ export async function transformMdast(
minifyMaxCharacters?: number;
index?: string;
simplifyFigures?: boolean;
processThumbnail?: boolean;
},
) {
const {
Expand All @@ -115,6 +117,7 @@ export async function transformMdast(
minifyMaxCharacters,
index,
simplifyFigures,
processThumbnail,
} = opts;
const toc = tic();
const { store, log } = session;
Expand Down Expand Up @@ -216,15 +219,17 @@ export async function transformMdast(
altOutputFolder: imageAltOutputFolder,
imageExtensions,
});
// Note, the thumbnail transform must be **after** images, as it may read the images
await transformThumbnail(session, mdast, file, frontmatter, imageWriteFolder, {
altOutputFolder: imageAltOutputFolder,
webp: !simplifyFigures,
});
await transformBanner(session, file, frontmatter, imageWriteFolder, {
altOutputFolder: imageAltOutputFolder,
webp: !simplifyFigures,
});
if (processThumbnail) {
// Note, the thumbnail transform must be **after** images, as it may read the images
await transformThumbnail(session, mdast, file, frontmatter, imageWriteFolder, {
altOutputFolder: imageAltOutputFolder,
webp: extraTransforms?.includes(transformWebp),
});
await transformBanner(session, file, frontmatter, imageWriteFolder, {
altOutputFolder: imageAltOutputFolder,
webp: extraTransforms?.includes(transformWebp),
});
}
}
await transformDeleteBase64UrlSource(mdast);
const sha256 = selectors.selectFileInfo(store.getState(), file).sha256 as string;
Expand Down
2 changes: 2 additions & 0 deletions packages/myst-cli/src/process/site.ts
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,7 @@ export async function fastProcessFile(
watchMode: true,
extraTransforms: [transformWebp, ...(extraTransforms ?? [])],
index: project.index,
processThumbnail: true,
});
const pageReferenceStates = selectPageReferenceStates(session, pages);
await postProcessMdast(session, {
Expand Down Expand Up @@ -324,6 +325,7 @@ export async function processProject(
watchMode,
extraTransforms,
index: project.index,
processThumbnail: true,
}),
),
);
Expand Down

0 comments on commit 2743af5

Please sign in to comment.