feat: Add subdirectory hosting support and fix asset path resolution

- Update README with comprehensive subdirectory hosting instructions and BASE_URL configuration guide
- Convert absolute asset paths to relative paths in index.html for proper subdirectory deployment
- Update all worker script imports to use relative paths instead of absolute paths
- Fix favicon and image references to work correctly when hosted in nested directories
- Normalize whitespace and formatting across worker files for consistency
- Update vite.config.ts to properly handle BASE_URL configuration for subdirectory deployments
- Ensure all tool pages and logic files maintain compatibility with subdirectory hosting
- Enable BentoPDF to be deployed at any URL path (e.g., example.com/tools/bentopdf/) without breaking asset loading
This commit is contained in:
abdullahalam123
2025-12-04 23:53:00 +05:30
parent 19425d98f9
commit b279c05281
39 changed files with 206 additions and 181 deletions

View File

@@ -1,9 +1,9 @@
self.importScripts('/coherentpdf.browser.min.js');
self.importScripts('../coherentpdf.browser.min.js');
function getAttachmentsFromPDFInWorker(fileBuffer, fileName) {
try {
const uint8Array = new Uint8Array(fileBuffer);
let pdf;
try {
pdf = coherentpdf.fromMemory(uint8Array, '');
@@ -40,8 +40,8 @@ function getAttachmentsFromPDFInWorker(fileBuffer, fileName) {
attachments.push({
index: i,
name: String(name),
page: Number(page),
name: String(name),
page: Number(page),
data: buffer
});
} catch (error) {
@@ -73,7 +73,7 @@ function getAttachmentsFromPDFInWorker(fileBuffer, fileName) {
function editAttachmentsInPDFInWorker(fileBuffer, fileName, attachmentsToRemove) {
try {
const uint8Array = new Uint8Array(fileBuffer);
let pdf;
try {
pdf = coherentpdf.fromMemory(uint8Array, '');
@@ -89,28 +89,28 @@ function editAttachmentsInPDFInWorker(fileBuffer, fileName, attachmentsToRemove)
coherentpdf.startGetAttachments(pdf);
const attachmentCount = coherentpdf.numberGetAttachments();
const attachmentsToKeep = [];
for (let i = 0; i < attachmentCount; i++) {
if (!attachmentsToRemove.includes(i)) {
const name = coherentpdf.getAttachmentName(i);
const page = coherentpdf.getAttachmentPage(i);
const data = coherentpdf.getAttachmentData(i);
const dataCopy = new Uint8Array(data.length);
dataCopy.set(new Uint8Array(data));
attachmentsToKeep.push({
name: String(name),
page: Number(page),
data: dataCopy
attachmentsToKeep.push({
name: String(name),
page: Number(page),
data: dataCopy
});
}
}
coherentpdf.endGetAttachments();
coherentpdf.removeAttachedFiles(pdf);
for (const attachment of attachmentsToKeep) {
if (attachment.page === 0) {
coherentpdf.attachFileFromMemory(attachment.data, attachment.name, pdf);
@@ -119,7 +119,7 @@ function editAttachmentsInPDFInWorker(fileBuffer, fileName, attachmentsToRemove)
}
}
}
const modifiedBytes = coherentpdf.toMemory(pdf, false, true);
coherentpdf.deletePdf(pdf);