Removes excessive logging

Removes console log statements used for debugging during development, resulting in cleaner output and improved performance in production.
This commit is contained in:
AlexKucera committed 2025-09-04 22:48:55 +02:00
1 parent 21fdfbf207
commit 6ff1a24773
5 files changed
+1 -44

No files matched your search

-16
View File
@@ -78,8 +78,6 @@ export class obsidianTypstPDFExport extends Plugin {
// Cache available fonts (async, don't await) // Cache available fonts (async, don't await)
this.cacheAvailableFonts(); this.cacheAvailableFonts();
console.log('Obsidian Typst PDF Export plugin loaded');
} }
/** /**
@@ -140,7 +138,6 @@ export class obsidianTypstPDFExport extends Plugin {
await this.app.vault.adapter.write('.obsidian/plugins/obsidian-typst-pdf-export/fonts-cache.json', await this.app.vault.adapter.write('.obsidian/plugins/obsidian-typst-pdf-export/fonts-cache.json',
JSON.stringify(cacheData, null, 2)); JSON.stringify(cacheData, null, 2));
console.log('Cached', fonts.length, 'fonts from typst');
} catch (error) { } catch (error) {
console.error('Failed to cache fonts from typst:', error); console.error('Failed to cache fonts from typst:', error);
@@ -501,14 +498,12 @@ export class obsidianTypstPDFExport extends Plugin {
// Process PDF embeds if any were found // Process PDF embeds if any were found
if (processedResult.metadata.pdfEmbeds && processedResult.metadata.pdfEmbeds.length > 0) { if (processedResult.metadata.pdfEmbeds && processedResult.metadata.pdfEmbeds.length > 0) {
console.log(`Export: Processing ${processedResult.metadata.pdfEmbeds.length} PDF embeds`);
const embedPdfFiles = config.embedPdfFiles ?? this.settings.behavior.embedPdfFiles; const embedPdfFiles = config.embedPdfFiles ?? this.settings.behavior.embedPdfFiles;
await this.processPdfEmbeds(processedResult, vaultPath, tempDir, file, embedPdfFiles); await this.processPdfEmbeds(processedResult, vaultPath, tempDir, file, embedPdfFiles);
} }
// Process image embeds if any were found // Process image embeds if any were found
if (processedResult.metadata.imageEmbeds && processedResult.metadata.imageEmbeds.length > 0) { if (processedResult.metadata.imageEmbeds && processedResult.metadata.imageEmbeds.length > 0) {
console.log(`Export: Processing ${processedResult.metadata.imageEmbeds.length} image embeds`);
await this.processImageEmbeds(processedResult, vaultPath, tempDir, file); await this.processImageEmbeds(processedResult, vaultPath, tempDir, file);
} }
@@ -725,10 +720,8 @@ ${dependencyResult.allAvailable
// Try each possible path until we find one that exists // Try each possible path until we find one that exists
for (const possiblePath of possiblePaths) { for (const possiblePath of possiblePaths) {
console.log(`Export: Checking path: ${possiblePath}`);
try { try {
await fs.promises.access(possiblePath); await fs.promises.access(possiblePath);
console.log(`Export: Found PDF at: ${possiblePath}`);
return possiblePath; return possiblePath;
} catch { } catch {
// File doesn't exist, continue to next path // File doesn't exist, continue to next path
@@ -819,13 +812,11 @@ ${dependencyResult.allAvailable
const pathModule = require('path'); const pathModule = require('path');
const fs = require('fs'); const fs = require('fs');
console.log(`Export: Processing ${processedResult.metadata.pdfEmbeds.length} PDF embeds`);
let updatedContent = processedResult.content; let updatedContent = processedResult.content;
for (const pdfEmbed of processedResult.metadata.pdfEmbeds) { for (const pdfEmbed of processedResult.metadata.pdfEmbeds) {
try { try {
console.log(`Export: Processing PDF embed: ${pdfEmbed.originalPath}`);
// Resolve PDF path using helper method // Resolve PDF path using helper method
const fullPdfPath = await this.resolvePdfPath(pdfEmbed.sanitizedPath, vaultBasePath, currentFile); const fullPdfPath = await this.resolvePdfPath(pdfEmbed.sanitizedPath, vaultBasePath, currentFile);
@@ -871,7 +862,6 @@ ${dependencyResult.allAvailable
// Replace the placeholder with the combined output // Replace the placeholder with the combined output
updatedContent = updatedContent.replace(pdfEmbed.marker, combinedOutput); updatedContent = updatedContent.replace(pdfEmbed.marker, combinedOutput);
console.log(`Export: Successfully processed PDF embed: ${pdfEmbed.baseName}`);
} else { } else {
console.warn(`Export: Failed to convert PDF to image: ${result.error}`); console.warn(`Export: Failed to convert PDF to image: ${result.error}`);
const relativePdfPath = pathModule.relative(vaultBasePath, fullPdfPath); const relativePdfPath = pathModule.relative(vaultBasePath, fullPdfPath);
@@ -911,13 +901,11 @@ ${dependencyResult.allAvailable
const pathModule = require('path'); const pathModule = require('path');
const fs = require('fs'); const fs = require('fs');
console.log(`Export: Processing ${processedResult.metadata.imageEmbeds.length} image embeds`);
let updatedContent = processedResult.content; let updatedContent = processedResult.content;
for (const imageEmbed of processedResult.metadata.imageEmbeds) { for (const imageEmbed of processedResult.metadata.imageEmbeds) {
try { try {
console.log(`Export: Processing image embed: ${imageEmbed.originalPath}`);
// Decode the URL-encoded sanitized path back to normal characters // Decode the URL-encoded sanitized path back to normal characters
const decodedPath = decodeURIComponent(imageEmbed.sanitizedPath); const decodedPath = decodeURIComponent(imageEmbed.sanitizedPath);
@@ -939,7 +927,6 @@ ${dependencyResult.allAvailable
try { try {
await fs.promises.access(possiblePath); await fs.promises.access(possiblePath);
fullImagePath = possiblePath; fullImagePath = possiblePath;
console.log(`Export: Found image at: ${fullImagePath}`);
break; break;
} catch { } catch {
// File doesn't exist, continue to next path // File doesn't exist, continue to next path
@@ -964,7 +951,6 @@ ${dependencyResult.allAvailable
updatedContent = updatedContent.replace(imageEmbed.marker, markdownImage); updatedContent = updatedContent.replace(imageEmbed.marker, markdownImage);
console.log(`Export: Successfully processed image embed: ${imageEmbed.originalPath}`);
} catch (error) { } catch (error) {
const { fallback } = ExportErrorHandler.handleProcessingError( const { fallback } = ExportErrorHandler.handleProcessingError(
'image embed', 'image embed',
@@ -1070,7 +1056,6 @@ ${dependencyResult.allAvailable
const result = cleanupManager.cleanupAllTempDirs(); const result = cleanupManager.cleanupAllTempDirs();
if (this.settings.behavior.debugMode) { if (this.settings.behavior.debugMode) {
console.log('Export: Startup cleanup completed', result);
} }
} catch (error) { } catch (error) {
console.warn('Export: Startup temp directory cleanup failed (non-critical):', error); console.warn('Export: Startup temp directory cleanup failed (non-critical):', error);
@@ -1093,7 +1078,6 @@ ${dependencyResult.allAvailable
console.warn('Export: Failed to clean up temp directories during unload:', error); console.warn('Export: Failed to clean up temp directories during unload:', error);
} }
console.log('Obsidian Typst PDF Export plugin unloaded');
} }
} }
+1 -7
View File
@@ -225,7 +225,6 @@ export class MarkdownPreprocessor {
if (this.noteTitle) { if (this.noteTitle) {
const yaml = require('js-yaml'); const yaml = require('js-yaml');
const titleFrontmatter = yaml.dump({ title: this.noteTitle }); const titleFrontmatter = yaml.dump({ title: this.noteTitle });
console.log('Replacing frontmatter with title:', titleFrontmatter);
processedContent = `---\n${titleFrontmatter}---\n${parsed.content}`; processedContent = `---\n${titleFrontmatter}---\n${parsed.content}`;
} else { } else {
processedContent = parsed.content; processedContent = parsed.content;
@@ -252,7 +251,6 @@ export class MarkdownPreprocessor {
if (this.noteTitle) { if (this.noteTitle) {
const yaml = require('js-yaml'); const yaml = require('js-yaml');
const titleFrontmatter = yaml.dump({ title: this.noteTitle }); const titleFrontmatter = yaml.dump({ title: this.noteTitle });
console.log('Adding title frontmatter:', titleFrontmatter);
return `---\n${titleFrontmatter}---\n${content}`; return `---\n${titleFrontmatter}---\n${content}`;
} else { } else {
return content; return content;
@@ -345,8 +343,6 @@ export class MarkdownPreprocessor {
return ''; return '';
} }
console.log('MarkdownPreprocessor: Formatting frontmatter for display:', frontmatter);
const lines: string[] = []; const lines: string[] = [];
lines.push('**Document Information**'); lines.push('**Document Information**');
lines.push(''); lines.push('');
@@ -415,13 +411,11 @@ export class MarkdownPreprocessor {
// Add a line break after the label for regular values // Add a line break after the label for regular values
lines.push(`**${formattedKey}:**\n${formattedValue}`); lines.push(`**${formattedKey}:**\n${formattedValue}`);
} }
console.log(`MarkdownPreprocessor: Formatted ${key} ->`, JSON.stringify(formattedValue)); }
}
} }
// Join with double newlines to ensure proper spacing between fields // Join with double newlines to ensure proper spacing between fields
const result = lines.join('\n\n'); const result = lines.join('\n\n');
console.log('MarkdownPreprocessor: Final formatted frontmatter:', JSON.stringify(result));
return result; return result;
} }
-13
View File
@@ -100,7 +100,6 @@ export class PandocTypstConverter {
await this.ensureTempDirectory(); await this.ensureTempDirectory();
const tempInputPath = path.join(this.tempDir!, `temp-${Date.now()}.md`); const tempInputPath = path.join(this.tempDir!, `temp-${Date.now()}.md`);
console.log('PandocTypstConverter: Writing markdown content to temp file:', JSON.stringify(content.substring(0, 1000)));
await fsPromises.writeFile(tempInputPath, content, 'utf-8'); await fsPromises.writeFile(tempInputPath, content, 'utf-8');
// Merge options // Merge options
@@ -149,7 +148,6 @@ export class PandocTypstConverter {
for (const pdfEmbed of processedResult.metadata.pdfEmbeds) { for (const pdfEmbed of processedResult.metadata.pdfEmbeds) {
try { try {
console.log(`Export: Processing PDF embed: ${pdfEmbed.originalPath}`);
// Resolve full path to the PDF // Resolve full path to the PDF
const fullPdfPath = path.resolve(vaultBasePath, pdfEmbed.sanitizedPath); const fullPdfPath = path.resolve(vaultBasePath, pdfEmbed.sanitizedPath);
@@ -198,7 +196,6 @@ export class PandocTypstConverter {
// Replace marker with output // Replace marker with output
processedResult.content = processedResult.content.replace(pdfEmbed.marker, combinedOutput); processedResult.content = processedResult.content.replace(pdfEmbed.marker, combinedOutput);
console.log(`Export: Successfully converted PDF: ${pdfEmbed.fileName} -> ${path.basename(conversionResult.imagePath)}`);
} else { } else {
console.error(`Export: PDF conversion failed: ${conversionResult.error}`); console.error(`Export: PDF conversion failed: ${conversionResult.error}`);
@@ -311,7 +308,6 @@ export class PandocTypstConverter {
for (const attachPath of commonAttachmentPaths) { for (const attachPath of commonAttachmentPaths) {
if (fs.existsSync(attachPath)) { if (fs.existsSync(attachPath)) {
args.push('--resource-path', attachPath); args.push('--resource-path', attachPath);
console.log('Added resource path:', attachPath);
} }
} }
@@ -326,7 +322,6 @@ export class PandocTypstConverter {
// Use cached resource paths // Use cached resource paths
for (const cachedPath of this.resourcePathCache) { for (const cachedPath of this.resourcePathCache) {
args.push('--resource-path', cachedPath); args.push('--resource-path', cachedPath);
console.log('Added cached resource path:', cachedPath);
} }
} else { } else {
// Cache is invalid or expired, perform fresh scan // Cache is invalid or expired, perform fresh scan
@@ -356,7 +351,6 @@ export class PandocTypstConverter {
if (hasImages) { if (hasImages) {
foundResourcePaths.push(itemPath); foundResourcePaths.push(itemPath);
args.push('--resource-path', itemPath); args.push('--resource-path', itemPath);
console.log('Added note-specific resource path:', itemPath);
} }
} catch (e) { } catch (e) {
// Ignore directories we can't read // Ignore directories we can't read
@@ -368,7 +362,6 @@ export class PandocTypstConverter {
this.resourcePathCache = foundResourcePaths; this.resourcePathCache = foundResourcePaths;
this.resourcePathCacheTimestamp = now; this.resourcePathCacheTimestamp = now;
this.resourcePathCacheVaultPath = this.pandocOptions.vaultBasePath; this.resourcePathCacheVaultPath = this.pandocOptions.vaultBasePath;
console.log(`Export: Cached ${foundResourcePaths.length} resource paths for future use`);
} catch (e) { } catch (e) {
console.warn('Could not scan vault for attachment directories:', e); console.warn('Could not scan vault for attachment directories:', e);
} }
@@ -381,7 +374,6 @@ export class PandocTypstConverter {
const fs = require('fs'); const fs = require('fs');
const absolutePluginDir = this.pandocOptions.pluginDir || ''; const absolutePluginDir = this.pandocOptions.pluginDir || '';
const wrapperPath = path.resolve(absolutePluginDir, 'templates', 'universal-wrapper.pandoc.typ'); const wrapperPath = path.resolve(absolutePluginDir, 'templates', 'universal-wrapper.pandoc.typ');
console.log('Universal wrapper path:', wrapperPath);
// Verify wrapper exists // Verify wrapper exists
if (!fs.existsSync(wrapperPath)) { if (!fs.existsSync(wrapperPath)) {
@@ -560,7 +552,6 @@ export class PandocTypstConverter {
const timeout = this.pandocOptions.timeout || 60000; const timeout = this.pandocOptions.timeout || 60000;
// Log the exact command being executed for debugging // Log the exact command being executed for debugging
console.log('Executing Pandoc command:', pandocPath, args.join(' '));
progressCallback?.('Starting Pandoc process...', 40); progressCallback?.('Starting Pandoc process...', 40);
@@ -569,12 +560,10 @@ export class PandocTypstConverter {
if (this.pandocOptions.vaultBasePath) { if (this.pandocOptions.vaultBasePath) {
workingDir = this.pandocOptions.vaultBasePath; workingDir = this.pandocOptions.vaultBasePath;
console.log('Pandoc working directory (vault):', workingDir);
} else { } else {
// Fallback to plugin directory // Fallback to plugin directory
const pluginDir = this.pandocOptions.pluginDir || process.cwd(); const pluginDir = this.pandocOptions.pluginDir || process.cwd();
workingDir = pluginDir; workingDir = pluginDir;
console.log('Pandoc working directory (plugin fallback):', workingDir);
} }
// Augment PATH to include common binary locations // Augment PATH to include common binary locations
@@ -615,7 +604,6 @@ export class PandocTypstConverter {
pandocProcess.stderr?.on('data', (data: Buffer) => { pandocProcess.stderr?.on('data', (data: Buffer) => {
const output = data.toString(); const output = data.toString();
stderr += output; stderr += output;
console.log('Pandoc stderr:', output);
// Parse progress information from stderr if available // Parse progress information from stderr if available
this.parseProgressFromOutput(output, progressCallback); this.parseProgressFromOutput(output, progressCallback);
@@ -649,7 +637,6 @@ export class PandocTypstConverter {
// Handle process errors // Handle process errors
pandocProcess.on('error', (error: Error) => { pandocProcess.on('error', (error: Error) => {
clearTimeout(timeoutHandle); clearTimeout(timeoutHandle);
console.log('Pandoc process error:', error);
resolve({ resolve({
success: false, success: false,
error: `Failed to start Pandoc process: ${error.message}`, error: `Failed to start Pandoc process: ${error.message}`,
-7
View File
@@ -149,8 +149,6 @@ export class PdfToImageConverter {
const pdf2imgPath = path.join(pluginDir, 'node_modules', '.bin', 'pdf2img'); const pdf2imgPath = path.join(pluginDir, 'node_modules', '.bin', 'pdf2img');
console.log(`Plugin directory: ${pluginDir}`);
console.log(`PDF2IMG path: ${pdf2imgPath}`);
// Check if the binary exists // Check if the binary exists
const fs2 = require('fs'); const fs2 = require('fs');
@@ -173,7 +171,6 @@ export class PdfToImageConverter {
'--pages', '1' // Only convert the first page '--pages', '1' // Only convert the first page
].join(' '); ].join(' ');
console.log(`PDF conversion command: ${cliCommand}`);
try { try {
// Set environment variables to ensure node can be found // Set environment variables to ensure node can be found
@@ -191,7 +188,6 @@ export class PdfToImageConverter {
const result = await execAsync(cliCommand, { const result = await execAsync(cliCommand, {
env env
}); });
console.log(`PDF conversion stdout: ${result.stdout}`);
if (result.stderr) { if (result.stderr) {
console.warn(`PDF conversion stderr: ${result.stderr}`); console.warn(`PDF conversion stderr: ${result.stderr}`);
} }
@@ -214,12 +210,10 @@ export class PdfToImageConverter {
// Debug: List what files are actually in the output directory // Debug: List what files are actually in the output directory
try { try {
const files = await fs.readdir(outputDir); const files = await fs.readdir(outputDir);
console.log(`Files in output directory (${outputDir}):`, files);
// Look for any PNG files that might match // Look for any PNG files that might match
const pngFiles = files.filter(f => f.endsWith('.png')); const pngFiles = files.filter(f => f.endsWith('.png'));
if (pngFiles.length > 0) { if (pngFiles.length > 0) {
console.log(`Found PNG files:`, pngFiles);
// Try to find a file that matches the pattern (with or without exact name) // Try to find a file that matches the pattern (with or without exact name)
// pdf2img might sanitize filenames differently // pdf2img might sanitize filenames differently
@@ -234,7 +228,6 @@ export class PdfToImageConverter {
if (matchingFile) { if (matchingFile) {
actualOutputPath = path.join(outputDir, matchingFile); actualOutputPath = path.join(outputDir, matchingFile);
console.log(`Using found PNG file: ${actualOutputPath}`);
} }
} }
} catch (listError) { } catch (listError) {
-1
View File
@@ -62,7 +62,6 @@ export class TempDirectoryManager {
for (const file of files) { for (const file of files) {
this.fs.unlinkSync(this.path.join(tempDir, file)); this.fs.unlinkSync(this.path.join(tempDir, file));
} }
console.log(`Export: Cleaned up ${type === 'images' ? 'temp-images' : 'temp-pandoc'} directory`);
return true; return true;
} }
} catch (error) { } catch (error) {