refactor: restore asset log abbreviation

This commit is contained in:
rca 2025-12-01 16:56:52 +09:00
parent 4926162649
commit d10c4e5e85

View File

@ -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)}`);
} }