mirror of
https://github.com/r-ca/md2pdf-meow.git
synced 2025-12-03 12:40:47 +00:00
refactor: restore asset log abbreviation
This commit is contained in:
parent
4926162649
commit
d10c4e5e85
@ -8,6 +8,7 @@ import { logger } from '../logger.js';
|
|||||||
import { ensureDir, pathExists } from '../utils/fs.js';
|
import { ensureDir, pathExists } from '../utils/fs.js';
|
||||||
|
|
||||||
const scanner = new MarkdownIt({ html: true });
|
const scanner = new MarkdownIt({ html: true });
|
||||||
|
const LOG_PATH_MAX = 80;
|
||||||
|
|
||||||
function isExternalSource(value: string) {
|
function isExternalSource(value: string) {
|
||||||
return /^[a-zA-Z][\w+.-]*:/.test(value);
|
return /^[a-zA-Z][\w+.-]*:/.test(value);
|
||||||
@ -42,6 +43,14 @@ function buildTarget(relativeSegments: string[]) {
|
|||||||
return { targetRelativePosix, targetPath };
|
return { targetRelativePosix, targetPath };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function abbreviatePath(value: string) {
|
||||||
|
if (value.length <= LOG_PATH_MAX) {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
const keep = Math.floor((LOG_PATH_MAX - 3) / 2);
|
||||||
|
return `${value.slice(0, keep)}...${value.slice(-keep)}`;
|
||||||
|
}
|
||||||
|
|
||||||
function extractImageSources(tokens: Token[]) {
|
function extractImageSources(tokens: Token[]) {
|
||||||
const sources: string[] = [];
|
const sources: string[] = [];
|
||||||
for (const token of tokens) {
|
for (const token of tokens) {
|
||||||
@ -126,6 +135,6 @@ export class AssetManager {
|
|||||||
|
|
||||||
function logAssetCopyStart(source: string, target: string) {
|
function logAssetCopyStart(source: string, target: string) {
|
||||||
logger.info('├─ asset copy');
|
logger.info('├─ asset copy');
|
||||||
logger.info(`│ ├─ src: ${abbreviate(source)}`);
|
logger.info(`│ ├─ src: ${abbreviatePath(source)}`);
|
||||||
logger.info(`│ └─ dst: ${abbreviate(target)}`);
|
logger.info(`│ └─ dst: ${abbreviatePath(target)}`);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user