Replaces manual conversion of absolute paths to vault-relative paths with a utility method to improve code readability and maintainability across various modules. Removes redundant code and streamlines path handling operations.
This refactoring helps ensure consistent path management and reduces potential errors related to path conversion.
Relates to obsidian-bot-review
Introduces toVaultRelativePath method to centralize path conversions,
reducing code duplication and improving maintainability. Extracts
image download completion logic into handleDownloadComplete for clarity.
Relates to obsidian-bot-review
Resolves critical bugs where directories and files were being created with
doubled paths (e.g., /vault/vault/path) due to incorrect handling of absolute
vs vault-relative paths when using Obsidian's vault adapter.
## Root Cause
The vault.adapter methods (mkdir, write, readBinary, etc.) expect vault-relative
paths, but many parts of the codebase were passing absolute filesystem paths.
This caused the adapter to prepend the vault path again, resulting in doubled
paths like: /Users/user/vault/Users/user/vault/exports
## Changes
### Core Path Handling
- **TempDirectoryManager**: Switched to Node's fs module for temp directory
operations since external tools (pdf2img, ImageMagick, Pandoc) require
absolute filesystem paths and cannot use vault adapter
- **PathUtils.ensureDir()**: Enhanced error messages to provide context about
missing parent directories and permission issues
### Path Conversion Pattern
Implemented consistent pattern throughout codebase: convert absolute paths to
vault-relative before vault.adapter operations by:
1. Checking if path starts with vault base path
2. Stripping vault base path
3. Removing leading slash/backslash
4. Passing vault-relative path to vault.adapter
### Fixed Locations
- **ImageOptimizer**: Convert paths before vault.adapter operations (3 locations)
- **EmbedProcessor**:
- downloadRemoteImage(): path conversion for writeBinary
- copyImageToVaultTemp(): path conversion for vault.adapter operations
- processImageEmbeds(): WebP conversion temp directory
- **PandocTypstConverter**: Use fs module for temp markdown file operations
- **PathResolver**: Convert output folder paths before ensureDir
- **PdfToImageConverter**: Convert output directory path before ensureDir
- **EmbeddedTemplateManager**: Convert template directory paths (2 locations)
### Additional Improvements
- **PathResolver**: Added validation for empty/missing output folder with
clear error message guiding users to plugin settings
- **ESLint**: Changed sentence-case rule from error to warning to reduce
linter noise during development
## Impact
- Fixes directories being created in wrong locations with doubled paths
- Ensures temp directories are accessible by external CLI tools
- Improves error messages for directory creation failures
- Maintains compatibility with both Obsidian's vault adapter and Node's fs
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
Corrects capitalization inconsistencies in UI and documentation,
improving clarity and professionalism. Enhances error handling
in the image download function by properly rejecting promises
on errors, thus increasing reliability and maintainability.
Relates to obsidian-bot-review branch tasks.
Applies linting rules to the codebase and resolves identified issues.
Addresses:
- Renamed headings in settings tabs to improve UI consistency and style.
- Resolved require() style imports
- Added void operator to ensure correct promise handling.
- Replaced deprecated Obsidian API calls.
- Enforces sentence case to enhance UI text consistency.
Ensures correct protocol (HTTP/HTTPS) is used when downloading
remote images by using the parsed URL object for the request.
This fixes potential issues where the protocol might be incorrectly
determined, especially when dealing with case-insensitive URL schemes.
Ensures that relative redirect URLs are resolved against the original image URL.
This prevents issues when downloading remote images from servers that return
relative redirect paths.
Ensures images without file extensions are properly handled by appending ".png" to the filename, preventing potential issues with image processing or display.
Preserves existing extensions for other image types (e.g., svg, ico, avif) without forcing a ".png" extension.
Consolidates local path resolution logic into a dedicated
`resolveLocalPath` method for improved code reuse and readability.
Improves image downloading by using the vault adapter to write
binary data, preventing potential data corruption.
This change addresses issues with image embed resolution,
especially for attachments in non-standard locations, and fixes
file overwriting during image downloads.
Addresses issues with path construction on Windows by using `path.isAbsolute()` to correctly handle absolute paths. Improves cross-platform compatibility in temp directory management and binary location.
Adds support for downloading and embedding remote images (http/https URLs) in markdown, enhancing content integration. Provides fallback mechanism with placeholder text upon download failure.
- Replaced fs.promises.access with PathUtils.fileExists() for file existence checks
- Replaced fs.promises.mkdir with PathUtils.ensureDir() for directory creation
- Replaced fs.promises.copyFile with vault.adapter readBinary/writeBinary operations
- Replaced path.join with PathUtils.joinPath() for consistent path normalization
- Updated all file resolution methods to use proper Obsidian API methods
- Removed fs import and all direct filesystem operations
- Enhanced copyImageToVaultTemp to use vault.adapter for binary file operations
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>
- Add missing ExportErrorHandler import in SettingsTab.ts
- Add customEnvironmentVariables property to settings interface
- Fix undefined metadata access with optional chaining in EmbedProcessor.ts
- Update ModalState.ts to use new nested settings structure
- Simplify ExportConfigModal.ts to use full settings object
- Add null safety checks for templateDropdown in GeneralSection.ts
- Replace all 'any' types with proper TypeScript types throughout codebase
- Fix processedResult parameters to use PreprocessingResult interface
- Update UI modal types: app parameter (App), pluginDefaults (obsidianTypstPDFExportSettings)
- Fix dropdown components to use DropdownComponent from Obsidian API
- Replace plugin 'any' types with obsidianTypstPDFExport throughout converters
- Fix margins parameter to use proper interface structure
- Update fs parameter to use proper Node.js fs module type
- Improve error handling with proper unknown type and type guards
- Remove unused PdfEmbedProcessor and clean up imports
Achieves complete type safety with zero remaining 'any' types across src/ directory.
Provides better IDE support, compile-time error detection, and maintainability.
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>
- Extract embed processing logic from MarkdownPreprocessor to new EmbedProcessor module
- Fix WebP image conversion that was broken during refactoring:
- Update ImageMagick command from deprecated 'convert' to modern 'magick'
- Fix field name mismatch: use 'sizeOrAlt' instead of 'alt' in plugin/EmbedProcessor
- Use PathResolver for proper ImageMagick executable path resolution
- Restore comprehensive embed processing including images, PDFs, and files
- Add proper error handling and fallback for WebP conversion failures
- Maintain size parameter parsing (e.g., "400x300") vs alt text differentiation
Resolves WebP conversion issues and completes Step 2.3 of refactoring plan.
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>
- Add app.metadataCache.getFirstLinkpathDest() as primary resolution strategy
- Fix path resolution issues after folder/note renames
- Update both resolvePdfPath and resolveFilePath methods consistently
- Maintain filesystem fallbacks for backward compatibility
- Resolves "PDF not found" errors when attachment folders are renamed
- Now uses Obsidian's native link resolution algorithm
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>