diff --git a/README.md b/README.md index 7ba63b4..4f32656 100644 --- a/README.md +++ b/README.md @@ -59,11 +59,11 @@ Typst offers several advantages over standard PDF export: **⚠️ Important**: This plugin requires template files to function. Always use the complete ZIP package. 1. Go to [GitHub Releases](https://github.com/akucera/obsidian-typst-pdf-export/releases) -2. Download the **complete ZIP package** (`obsidian-typst-pdf-export.zip`) - **NOT just main.js** -3. Extract the entire contents to `{VaultFolder}/.obsidian/plugins/obsidian-typst-pdf-export/` +2. Download the **complete ZIP package** (`typst-pdf-export.zip`) - **NOT just main.js** +3. Extract the entire contents to `{VaultFolder}/.obsidian/plugins/typst-pdf-export/` 4. Ensure the `templates/` directory is included with all `.typ` files: ``` - .obsidian/plugins/obsidian-typst-pdf-export/ + .obsidian/plugins/typst-pdf-export/ ├── main.js ├── manifest.json ├── styles.css @@ -90,8 +90,8 @@ For development or the latest changes: 1. Clone the repository to your vault's plugins folder: ```bash cd {VaultFolder}/.obsidian/plugins/ - git clone https://github.com/akucera/obsidian-typst-pdf-export.git - cd obsidian-typst-pdf-export + git clone https://github.com/akucera/obsidian-typst-pdf-export.git typst-pdf-export + cd typst-pdf-export ``` 2. Install dependencies and build: ```bash @@ -268,8 +268,8 @@ JB ```bash # Clone the repository -git clone https://github.com/akucera/obsidian-typst-pdf-export.git -cd obsidian-typst-pdf-export +git clone https://github.com/akucera/obsidian-typst-pdf-export.git typst-pdf-export +cd typst-pdf-export # Install dependencies npm install @@ -281,7 +281,7 @@ npm run dev ### Project Structure ``` -obsidian-typst-pdf-export/ +typst-pdf-export/ ├── src/ │ ├── core/ # Core system components │ ├── converters/ # Conversion pipeline diff --git a/main.ts b/main.ts index b3c77db..ca0d402 100644 --- a/main.ts +++ b/main.ts @@ -155,7 +155,8 @@ export class obsidianTypstPDFExport extends Plugin { typstPath: typstPath }; - await this.app.vault.adapter.write('.obsidian/plugins/typst-pdf-export/fonts-cache.json', + const fontsCachePath = path.join(this.manifest.dir!, 'fonts-cache.json'); + await this.app.vault.adapter.write(fontsCachePath, JSON.stringify(cacheData, null, 2)); } catch (error) { console.error('Failed to cache fonts from typst:', error); @@ -178,7 +179,8 @@ export class obsidianTypstPDFExport extends Plugin { error: error.message }; - await this.app.vault.adapter.write('.obsidian/plugins/typst-pdf-export/fonts-cache.json', + const fontsCachePath = path.join(this.manifest.dir!, 'fonts-cache.json'); + await this.app.vault.adapter.write(fontsCachePath, JSON.stringify(cacheData, null, 2)); } } @@ -188,7 +190,8 @@ export class obsidianTypstPDFExport extends Plugin { */ async getCachedFonts(): Promise { try { - const cacheContent = await this.app.vault.adapter.read('.obsidian/plugins/typst-pdf-export/fonts-cache.json'); + const fontsCachePath = path.join(this.manifest.dir!, 'fonts-cache.json'); + const cacheContent = await this.app.vault.adapter.read(fontsCachePath); const cacheData = JSON.parse(cacheContent); // Check if cache is older than 24 hours or typst path changed @@ -776,7 +779,7 @@ ${dependencyResult.allAvailable const fs = require('fs'); // Copy image to vault temp directory for access - const vaultTempImagesDir = pathModule.join(vaultBasePath, '.obsidian', 'plugins', 'typst-pdf-export', 'temp-images'); + const vaultTempImagesDir = pathModule.join(vaultBasePath, this.manifest.dir!, 'temp-images'); await fs.promises.mkdir(vaultTempImagesDir, { recursive: true }); // Sanitize the basename for use in filename - replace problematic characters diff --git a/src/converters/PdfToImageConverter.ts b/src/converters/PdfToImageConverter.ts index a383c33..9576b1a 100644 --- a/src/converters/PdfToImageConverter.ts +++ b/src/converters/PdfToImageConverter.ts @@ -128,13 +128,14 @@ export class PdfToImageConverter { let pluginDir: string; // Try multiple strategies to find the plugin directory + const pluginDirName = this.plugin?.manifest?.dir || 'typst-pdf-export'; const possiblePluginDirs = [ // Strategy 1: From process.cwd() if it's in the vault - path.join(process.cwd(), '.obsidian', 'plugins', 'typst-pdf-export'), + path.join(process.cwd(), '.obsidian', 'plugins', pluginDirName), // Strategy 2: Assuming we're running from vault root - path.join('.obsidian', 'plugins', 'typst-pdf-export'), - // Strategy 3: Direct path if running in development - '/Users/alex/Obsidian/Dev/.obsidian/plugins/typst-pdf-export' + path.join('.obsidian', 'plugins', pluginDirName), + // Strategy 3: From vault base path if plugin is available + ...(this.plugin ? [path.join((this.plugin.app.vault.adapter as any).basePath, this.plugin.manifest.dir!)] : []) ]; // Find the first directory that exists and has node_modules diff --git a/src/templates/TemplateManager.ts b/src/templates/TemplateManager.ts index 7c13827..ca4ffa0 100644 --- a/src/templates/TemplateManager.ts +++ b/src/templates/TemplateManager.ts @@ -16,7 +16,8 @@ export class TemplateManager { // Templates are stored in the plugin directory this.templatesPath = path.join( (this.plugin.app.vault.adapter as any).basePath, - '.obsidian/plugins/typst-pdf-export/templates' + this.plugin.manifest.dir!, + 'templates' ); }