lion/src/utils/rewrite-links.mjs
2025-10-03 09:37:32 +02:00

25 lines
641 B
JavaScript

import fs from 'node:fs/promises';
import { globby } from 'globby';
// Get all HTML files from the output directory
const files = await globby(`./dist/**/*.html`);
let DEBUG = false;
await Promise.all(
files.map(async file => {
if (file.includes('next/index.html')) {
console.log('Processing file:', file);
DEBUG = true;
}
let html = await fs.readFile(file, 'utf-8');
const updatedHtml = html.replace(/href="(\/(?!next)[^"]*)"/g, (match, p1) => {
if (DEBUG) {
console.log('***', match, p1);
}
return `href="/next${p1}"`;
});
await fs.writeFile(file, updatedHtml);
}),
);