mirror of
https://github.com/r-ca/md2pdf-meow.git
synced 2025-12-03 12:40:47 +00:00
chore: adjust asset/meta logging
This commit is contained in:
parent
6706af5f8e
commit
4926162649
@ -15,6 +15,7 @@ async function runPipeline() {
|
||||
await prepareWorkspace();
|
||||
const assetManager = new AssetManager();
|
||||
const { outputPath: markdownPath, orderedFiles } = await concatMarkdown(assetManager);
|
||||
assetManager.report();
|
||||
await injectToc(markdownPath);
|
||||
await renderMarkdownToHtml(markdownPath, WORK_MARKDOWN_HTML, assetManager, orderedFiles);
|
||||
const meta = await loadMeta();
|
||||
|
||||
@ -61,7 +61,7 @@ function extractImageSources(tokens: Token[]) {
|
||||
|
||||
export class AssetManager {
|
||||
private assetMap = new Map<string, string>();
|
||||
private copiedTargets = new Set<string>();
|
||||
private copiedCount = 0;
|
||||
|
||||
private key(filePath: string, src: string) {
|
||||
return `${filePath}::${src}`;
|
||||
@ -99,13 +99,12 @@ export class AssetManager {
|
||||
|
||||
const segments = splitSegments(relativeFromDocuments);
|
||||
const { targetRelativePosix, targetPath } = buildTarget(segments);
|
||||
const targetRelativePath = path.relative('.', targetPath);
|
||||
|
||||
if (!this.copiedTargets.has(targetPath)) {
|
||||
logAssetCopyStart(relativeFromDocuments, targetRelativePath);
|
||||
await ensureDir(path.dirname(targetPath));
|
||||
await fs.copyFile(absoluteSource, targetPath);
|
||||
this.copiedTargets.add(targetPath);
|
||||
logger.succ(`画像をコピー: ${path.relative('.', targetPath)} (元: ${relativeFromDocuments})`);
|
||||
}
|
||||
this.copiedCount++;
|
||||
|
||||
this.assetMap.set(this.key(filePath, rawSource), targetRelativePosix);
|
||||
if (rawSource !== normalized) {
|
||||
@ -119,4 +118,14 @@ export class AssetManager {
|
||||
this.assetMap.get(this.key(filePath, normalizeSource(src)))
|
||||
);
|
||||
}
|
||||
|
||||
report() {
|
||||
logger.succ(`asset copy total: ${this.copiedCount} file(s)`);
|
||||
}
|
||||
}
|
||||
|
||||
function logAssetCopyStart(source: string, target: string) {
|
||||
logger.info('├─ asset copy');
|
||||
logger.info(`│ ├─ src: ${abbreviate(source)}`);
|
||||
logger.info(`│ └─ dst: ${abbreviate(target)}`);
|
||||
}
|
||||
|
||||
@ -11,6 +11,7 @@ export interface DocumentMetaSection {
|
||||
published?: string;
|
||||
pubDate?: string;
|
||||
copyright?: string;
|
||||
description?: string;
|
||||
}
|
||||
|
||||
export interface DocumentMeta {
|
||||
@ -59,12 +60,14 @@ function buildSection(value: unknown): DocumentMetaSection | undefined {
|
||||
const published = pickString(record.published);
|
||||
const pubDate = pickString(record.pubDate);
|
||||
const copyright = pickString(record.copyright);
|
||||
const description = pickString(record.description);
|
||||
|
||||
if (title) section.title = title;
|
||||
if (author) section.author = author;
|
||||
if (published) section.published = published;
|
||||
if (pubDate) section.pubDate = pubDate;
|
||||
if (copyright) section.copyright = copyright;
|
||||
if (description) section.description = description;
|
||||
|
||||
return Object.keys(section).length > 0 ? section : undefined;
|
||||
}
|
||||
@ -102,21 +105,38 @@ export async function loadMeta(): Promise<DocumentMeta> {
|
||||
logger.info(`メタ情報ファイル ${filename} を読み込みます`);
|
||||
const meta = await loadYamlMeta(fullPath);
|
||||
logMetaInfo(meta, filename);
|
||||
logger.succ('メタ情報の読み込みが完了しました');
|
||||
return meta;
|
||||
}
|
||||
}
|
||||
logger.info('メタ情報ファイルが見つからなかったため、テンプレートのデフォルト値を使用します');
|
||||
logMetaInfo(DEFAULT_META, 'default');
|
||||
logger.succ('メタ情報の読み込みが完了しました');
|
||||
return DEFAULT_META;
|
||||
}
|
||||
|
||||
function logMetaInfo(meta: DocumentMeta, source: string) {
|
||||
logger.info(`\tsource: ${source}`);
|
||||
logger.info(`\ttitle: ${meta.title}`);
|
||||
logger.info(`\tauthor: ${meta.author}`);
|
||||
logger.info(`\tpublished: ${meta.published}`);
|
||||
logger.info(`├─ meta source: ${source}`);
|
||||
logger.info(`│ ├─ title: ${meta.title}`);
|
||||
logger.info(`│ ├─ author: ${meta.author}`);
|
||||
logger.info(`│ ├─ published: ${meta.published}`);
|
||||
if (meta.description) {
|
||||
logger.info(`\tdescription: ${meta.description}`);
|
||||
logger.info(`│ ├─ description: ${meta.description}`);
|
||||
}
|
||||
logger.info(`\tcopyright: ${meta.copyright}`);
|
||||
logger.info(`│ └─ copyright: ${meta.copyright}`);
|
||||
logSection('frontCover', meta.frontCover);
|
||||
logSection('backCover', meta.backCover);
|
||||
}
|
||||
|
||||
function logSection(label: string, section?: DocumentMetaSection) {
|
||||
if (!section) {
|
||||
return;
|
||||
}
|
||||
logger.info(`├─ ${label}:`);
|
||||
if (section.title) logger.info(`│ ├─ title: ${section.title}`);
|
||||
if (section.author) logger.info(`│ ├─ author: ${section.author}`);
|
||||
if (section.published) logger.info(`│ ├─ published: ${section.published}`);
|
||||
if (section.pubDate) logger.info(`│ ├─ pubDate: ${section.pubDate}`);
|
||||
if (section.description) logger.info(`│ ├─ description: ${section.description}`);
|
||||
if (section.copyright) logger.info(`│ └─ copyright: ${section.copyright}`);
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user