diff --git a/simple-index.html b/simple-index.html
index e74e1434..cd6140b6 100644
--- a/simple-index.html
+++ b/simple-index.html
@@ -60,7 +60,7 @@
class="h-8 w-8"
/>
- {{#if brandName}}{{brandName}}{{else}}BentoPDF{{/if}}
diff --git a/src/js/logic/deskew-pdf-page.ts b/src/js/logic/deskew-pdf-page.ts
index 0428d704..f5467770 100644
--- a/src/js/logic/deskew-pdf-page.ts
+++ b/src/js/logic/deskew-pdf-page.ts
@@ -273,7 +273,7 @@ function initPage(): void {
if (backBtn) {
backBtn.addEventListener('click', () => {
- window.location.href = '/';
+ window.location.href = import.meta.env.BASE_URL;
});
}
diff --git a/src/js/logic/form-filler-page.ts b/src/js/logic/form-filler-page.ts
index ae49b487..47772bdc 100644
--- a/src/js/logic/form-filler-page.ts
+++ b/src/js/logic/form-filler-page.ts
@@ -311,6 +311,6 @@ document.addEventListener('DOMContentLoaded', () => {
processBtn?.addEventListener('click', processAndDownloadForm);
backBtn?.addEventListener('click', () => {
- window.location.href = '../../index.html';
+ window.location.href = import.meta.env.BASE_URL;
});
});
diff --git a/src/js/logic/markdown-to-pdf-page.ts b/src/js/logic/markdown-to-pdf-page.ts
index e104c983..3282f4cd 100644
--- a/src/js/logic/markdown-to-pdf-page.ts
+++ b/src/js/logic/markdown-to-pdf-page.ts
@@ -1,21 +1,21 @@
import { MarkdownEditor } from '../utils/markdown-editor.js';
document.addEventListener('DOMContentLoaded', () => {
- const container = document.getElementById('markdown-editor-container');
+ const container = document.getElementById('markdown-editor-container');
- if (!container) {
- console.error('Markdown editor container not found');
- return;
- }
+ if (!container) {
+ console.error('Markdown editor container not found');
+ return;
+ }
- const editor = new MarkdownEditor(container, {});
+ const editor = new MarkdownEditor(container, {});
- console.log('Markdown editor initialized');
+ console.log('Markdown editor initialized');
- const backButton = document.getElementById('back-to-tools');
- if (backButton) {
- backButton.addEventListener('click', () => {
- window.location.href = '/';
- });
- }
+ const backButton = document.getElementById('back-to-tools');
+ if (backButton) {
+ backButton.addEventListener('click', () => {
+ window.location.href = import.meta.env.BASE_URL;
+ });
+ }
});
diff --git a/src/js/logic/remove-annotations-page.ts b/src/js/logic/remove-annotations-page.ts
index 715f51a7..e190eebd 100644
--- a/src/js/logic/remove-annotations-page.ts
+++ b/src/js/logic/remove-annotations-page.ts
@@ -194,6 +194,6 @@ document.addEventListener('DOMContentLoaded', () => {
processBtn?.addEventListener('click', processRemoveAnnotations);
backBtn?.addEventListener('click', () => {
- window.location.href = '../../index.html';
+ window.location.href = import.meta.env.BASE_URL;
});
});
diff --git a/src/js/logic/remove-blank-pages-page.ts b/src/js/logic/remove-blank-pages-page.ts
index 5b70b371..540e37c6 100644
--- a/src/js/logic/remove-blank-pages-page.ts
+++ b/src/js/logic/remove-blank-pages-page.ts
@@ -366,6 +366,6 @@ document.addEventListener('DOMContentLoaded', () => {
processBtn?.addEventListener('click', processRemoveBlankPages);
document.getElementById('back-to-tools')?.addEventListener('click', () => {
- window.location.href = '../../index.html';
+ window.location.href = import.meta.env.BASE_URL;
});
});
diff --git a/src/tests/navigation-base-url.test.ts b/src/tests/navigation-base-url.test.ts
new file mode 100644
index 00000000..a5e7ecc5
--- /dev/null
+++ b/src/tests/navigation-base-url.test.ts
@@ -0,0 +1,101 @@
+import { describe, it, expect } from 'vitest';
+import * as fs from 'fs';
+import * as path from 'path';
+
+describe('Navigation BASE_URL Consistency', () => {
+ const logicDir = path.resolve(__dirname, '../js/logic');
+ const pagesDir = path.resolve(__dirname, '../pages');
+ const rootDir = path.resolve(__dirname, '../../');
+
+ it('ensures tool navigation assignments strictly use import.meta.env.BASE_URL', () => {
+ const files = fs
+ .readdirSync(logicDir)
+ .filter(
+ (file) =>
+ (file.endsWith('.ts') || file.endsWith('.js')) &&
+ file !== 'shortcuts.ts'
+ );
+
+ const nonCompliantAssignments: Array<{ file: string; target: string }> = [];
+
+ for (const file of files) {
+ const content = fs.readFileSync(path.join(logicDir, file), 'utf-8');
+ const assignments = content.matchAll(
+ /window\.location\.href\s*=\s*([^;\n]+)/g
+ );
+
+ for (const match of assignments) {
+ const target = match[1].trim();
+ if (!target.includes('import.meta.env.BASE_URL')) {
+ nonCompliantAssignments.push({ file, target });
+ }
+ }
+ }
+
+ expect(
+ nonCompliantAssignments,
+ `The following files assign window.location.href without import.meta.env.BASE_URL: ${JSON.stringify(
+ nonCompliantAssignments,
+ null,
+ 2
+ )}`
+ ).toEqual([]);
+ });
+
+ it('ensures each affected back-button handler assigns import.meta.env.BASE_URL', () => {
+ const affectedFiles = [
+ 'deskew-pdf-page.ts',
+ 'markdown-to-pdf-page.ts',
+ 'remove-annotations-page.ts',
+ 'form-filler-page.ts',
+ 'remove-blank-pages-page.ts',
+ ];
+
+ for (const file of affectedFiles) {
+ const content = fs.readFileSync(path.join(logicDir, file), 'utf-8');
+ expect(
+ content,
+ `${file} must assign window.location.href to import.meta.env.BASE_URL`
+ ).toMatch(/window\.location\.href\s*=\s*import\.meta\.env\.BASE_URL/);
+ }
+ });
+
+ it('ensures brand anchor in standalone templates asserts href="{{baseUrl}}"', () => {
+ const standaloneTemplates = [
+ path.join(rootDir, 'simple-index.html'),
+ path.join(rootDir, 'src/partials/navbar-simple.html'),
+ ];
+
+ for (const filePath of standaloneTemplates) {
+ if (!fs.existsSync(filePath)) continue;
+
+ const content = fs.readFileSync(filePath, 'utf-8');
+ const anchors = [
+ ...content.matchAll(
+ /]*href=["']([^"']*)["'][^>]*>([\s\S]*?)<\/a\s*>/gi
+ ),
+ ];
+
+ const brandAnchor = anchors.find(([, , innerContent]) =>
+ /{{#if\s+brandName}}|BentoPDF/i.test(innerContent)
+ );
+
+ expect(
+ brandAnchor,
+ `Could not locate brand anchor in ${path.basename(filePath)}`
+ ).toBeDefined();
+
+ const href = brandAnchor?.[1];
+ expect(
+ href,
+ `Expected ${path.basename(filePath)} brand anchor href to be "{{baseUrl}}" but got "${href}"`
+ ).toBe('{{baseUrl}}');
+ }
+ });
+
+ it('ensures pdf-multi-tool uses standard navbar partial', () => {
+ const pdfMultiTool = path.join(pagesDir, 'pdf-multi-tool.html');
+ const content = fs.readFileSync(pdfMultiTool, 'utf-8');
+ expect(content).toContain('{{> navbar }}');
+ });
+});