Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 37 additions & 1 deletion src/commands/build/features/output-html/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,15 @@ import {preprocess} from '@diplodoc/client/ssr';
import {isFileExists} from '@diplodoc/transform/lib/utilsFS';

import {Template} from '~/core/template';
import {fallbackLang, isExternalHref, normalizePath, own, setExt, zip} from '~/core/utils';
import {
fallbackLang,
isExternalHref,
isMediaLink,
normalizePath,
own,
setExt,
zip,
} from '~/core/utils';
import {getHooks as getBuildHooks} from '~/commands/build';
import {getHooks as getTocHooks} from '~/core/toc';
import {getHooks as getLeadingHooks} from '~/core/leading';
Expand Down Expand Up @@ -183,6 +191,34 @@ export class OutputHtml {
getBuildHooks(program)
.AfterRun.for('html')
.tapPromise('Html', async (run) => {
// Check asset sizes before copying
const copiedAssets = new Set<string>();

// Get all entries and check their assets
const entries = run.toc.entries;

for (const entry of entries) {
const markdownAssets = await run.markdown.assets(entry);

for (const {path, size} of markdownAssets) {
if (!isMediaLink(path)) {
continue;
}

if (copiedAssets.has(path)) {
continue;
}
copiedAssets.add(path);

if (typeof size === 'number' && size > run.config.content.maxAssetSize) {
run.logger.error(
'YFM013',
`${path}: YFM013 / File asset limit exceeded: ${size} (limit is ${run.config.content.maxAssetSize})`,
);
}
}
}

// TODO: we copy all files. Required to copy only used files.
// Look at the same copy process in output-md feature.
await run.copy(run.input, run.output, ['**/*.yaml', '**/*.md']);
Expand Down
5 changes: 4 additions & 1 deletion tests/e2e/errors.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,13 @@ describe('Errors', () => {

test(
'mocks/errors/max-asset-size',
({md}: TestResult) => {
({md, html}: TestResult) => {
expectErrors(md, [
'ERR YFM013 _images/large-image.png: YFM013 / File asset limit exceeded: 3057 (limit is 2048)',
]);
expectErrors(html, [
'ERR YFM013 _images/large-image.png: YFM013 / File asset limit exceeded: 3057 (limit is 2048)',
]);
},
['--max-asset-size', '2K'],
);
Expand Down
Loading