diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 80deb14..2a1c09c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -17,6 +17,8 @@ jobs: - name: Build run: npm run build + env: + BUILD: production - name: Test run: npm run test \ No newline at end of file diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index c067ae1..ebb40d2 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -16,6 +16,8 @@ jobs: - name: Build run: npm run build + env: + BUILD: production - name: Create release id: create_release diff --git a/rollup.config.js b/rollup.config.js index 2651549..bf6e95d 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -4,18 +4,18 @@ import commonjs from '@rollup/plugin-commonjs'; import svelte from "rollup-plugin-svelte"; import autoPreprocess from "svelte-preprocess"; import copy from "rollup-plugin-copy"; -import { env } from "process"; export default { input: 'src/index.ts', output: { file: 'dist/main.js', format: 'cjs', - exports: 'default' + exports: 'default', + sourcemap: process.env.BUILD === "development" ? "inline" : false }, - external: ['obsidian', "path"], + external: ['obsidian'], plugins: [ - typescript({ sourceMap: env.env === "DEV" }), + typescript({ sourceMap: process.env.BUILD === "development" }), resolve({ browser: true, dedupe: ["svelte"], diff --git a/src/fileDoc.ts b/src/fileDoc.ts index 6ed64b0..edbf9f6 100644 --- a/src/fileDoc.ts +++ b/src/fileDoc.ts @@ -44,7 +44,7 @@ export class FileDoc { } public filePath(): string { - return this.fsHandler.normalizePath(`${this.fsHandler.getBasePath()}/${this.sanitizeName()}.md`); + return this.fsHandler.normalizePath(`${this.sanitizeName()}.md`); } public sanitizeName(): string { diff --git a/src/fileSystem/handler.ts b/src/fileSystem/handler.ts index b96e432..f618163 100644 --- a/src/fileSystem/handler.ts +++ b/src/fileSystem/handler.ts @@ -8,10 +8,6 @@ export class FileSystemHandler implements IFileSystemHandler { this.adapter = adapter; } - public getBasePath(): string { - return this.adapter.getBasePath(); - } - public normalizePath(path: string): string { return obsidian.normalizePath(path); } diff --git a/src/fileSystem/interface.ts b/src/fileSystem/interface.ts index 1853d40..cc1527c 100644 --- a/src/fileSystem/interface.ts +++ b/src/fileSystem/interface.ts @@ -1,6 +1,4 @@ export interface IFileSystemHandler { - getBasePath(): string; - normalizePath(path: string): string; read(path: string): Promise; diff --git a/src/template/loader.ts b/src/template/loader.ts index 1c4a435..b1b5322 100644 --- a/src/template/loader.ts +++ b/src/template/loader.ts @@ -21,7 +21,9 @@ export class TemplateLoader { async load(): Promise { let content = await this.selectTemplate(); - return nunjucks.compile(content); + let env = nunjucks.configure({ autoescape: false }); + + return nunjucks.compile(content, env); } async selectTemplate(): Promise { diff --git a/tests/fileDoc.ts b/tests/fileDoc.ts index 9683072..6822b91 100644 --- a/tests/fileDoc.ts +++ b/tests/fileDoc.ts @@ -73,7 +73,7 @@ describe("File Doc", () => { }); it("generates the fileDoc path", () => { - assert.equal(fileDoc.filePath(), "/base/Hello World.md"); + assert.equal(fileDoc.filePath(), "Hello World.md"); }); }); }); \ No newline at end of file diff --git a/tests/helpers.ts b/tests/helpers.ts index 17491aa..82e74f7 100644 --- a/tests/helpers.ts +++ b/tests/helpers.ts @@ -7,7 +7,6 @@ const path = require('path'); export function fileSystemHandler(): IFileSystemHandler { return { - getBasePath: () => "/base", normalizePath: (path: string) => path, read: async (path: string) => { return fs.readFileSync(path).toString(); diff --git a/tests/templates.ts b/tests/templates.ts index ee1fe43..00e86cb 100644 --- a/tests/templates.ts +++ b/tests/templates.ts @@ -123,29 +123,29 @@ describe("HighlightTemplateRenderer", () => { highlight = new Highlight({ id: 10, book_id: 5, - text: 'Looks important', - note: 'It really looks important', + text: "Looks important. It's super ", + note: "It really looks important. Can't wait for it", url: 'https://readwise.io', location: 1, }); }); it('renders default template with doc', async () => { - assert.equal(await templateRenderer.render(highlight), `Looks important %% highlight_id: 10 %% -Note: It really looks important + assert.equal(await templateRenderer.render(highlight), `Looks important. It's super %% highlight_id: 10 %% +Note: It really looks important. Can't wait for it `); }); it('renders custom template with doc', async () => { - assert.equal(await customTemplateRenderer.render(highlight), `Looks important \`highlight_id: 10\` %% location: 1 %% -Note: It really looks important + assert.equal(await customTemplateRenderer.render(highlight), `Looks important. It's super \`highlight_id: 10\` %% location: 1 %% +Note: It really looks important. Can't wait for it `); }); it('adds highlight_id if not present on template', async () => { let customTemplateWithoutIdRenderer = await HighlightTemplateRenderer.create(resolvePathToData('Readwise Note Highlight Missing Id'), handler); - assert.equal(await customTemplateWithoutIdRenderer.render(highlight), `Looks important %% location: 1 %% -Note: It really looks important + assert.equal(await customTemplateWithoutIdRenderer.render(highlight), `Looks important. It's super %% location: 1 %% +Note: It really looks important. Can't wait for it %% highlight_id: 10 %% `); });