mirror of
https://github.com/alam00000/bentopdf.git
synced 2026-11-07 00:28:39 +01:00
Merge pull request #853 from nipunrajk/fix/navigation-base-url
fix(navigation): respect BASE_URL in tool pages and navbar brand (Fixes #850)
This commit is contained in:
+1
-1
@@ -60,7 +60,7 @@
|
||||
class="h-8 w-8"
|
||||
/>
|
||||
<span class="text-white font-bold text-xl ml-2">
|
||||
<a href="/"
|
||||
<a href="{{baseUrl}}"
|
||||
>{{#if brandName}}{{brandName}}{{else}}BentoPDF{{/if}}</a
|
||||
>
|
||||
</span>
|
||||
|
||||
@@ -273,7 +273,7 @@ function initPage(): void {
|
||||
|
||||
if (backBtn) {
|
||||
backBtn.addEventListener('click', () => {
|
||||
window.location.href = '/';
|
||||
window.location.href = import.meta.env.BASE_URL;
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
});
|
||||
});
|
||||
|
||||
@@ -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;
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
@@ -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;
|
||||
});
|
||||
});
|
||||
|
||||
@@ -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;
|
||||
});
|
||||
});
|
||||
|
||||
@@ -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(
|
||||
/<a\b[^>]*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 }}');
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user