Skip to content

Commit 5974ef4

Browse files
author
Bouwmeester, Kevin
committed
Attempt at fix of html loading
1 parent af76150 commit 5974ef4

File tree

1 file changed

+29
-10
lines changed

1 file changed

+29
-10
lines changed

app/knowledge-hub/ECS/page.tsx

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,39 @@ import Image from 'next/image';
33

44
import Navbar from '../../components/Navbar';
55
import Footer from '../../components/Footer';
6-
import html from '../../public/knowledge-hub/ECS/paper.html';
6+
7+
import fs from 'node:fs/promises';
8+
import path from 'node:path';
9+
import Script from 'next/script';
10+
711
import { KevinContact } from '@/app/person-constants';
12+
813
import ECSImage from '../../public/knowledge-hub/ECS/ECS.jpg'
914

10-
// const menuItems = [
11-
// { name: 'SEiGS 2025', route: '../seigs25' },
12-
// { name: 'Industrial Projects', route: '../industrial-projects' },
13-
// { name: 'Academic Projects', route: '../projects' },
14-
// { name: 'Positions', route: '../openings' },
15-
// { name: 'Contact us', route: '../contacts' }
16-
// ];
1715
import { MENU_ITEMS as menuItems } from '../../constants';
1816

19-
export default function Home() {
17+
18+
// Prefix for where the assets live under /public
19+
const PUBLIC_PREFIX = '/knowledge-hub/ECS';
20+
21+
async function loadHtml(): Promise<string> {
22+
// Read the prebuilt HTML from /public
23+
const filePath = path.join(process.cwd(), 'public', 'knowledge-hub', 'ECS', 'paper.html');
24+
let html = await fs.readFile(filePath, 'utf8');
25+
26+
// --- Rewrite relative asset URLs so they work when embedded ---
27+
// Matches src/href attributes that are relative (not starting with http(s)://, //, /, or #)
28+
html = html.replace(
29+
/\b(src|href)="'([^"']+)["']/gi,
30+
(_m, attr, url) => `${attr}="${PUBLIC_PREFIX}/${url}"`
31+
);
32+
33+
return html;
34+
}
35+
36+
37+
export default async function Home() {
38+
const HTML = await loadHtml();
2039
return (
2140
<div>
2241
<Navbar menuItems={menuItems} pageSelected="" />
@@ -36,7 +55,7 @@ export default function Home() {
3655
<a href="https://doi.org/10.1016/j.simpat.2020.102243"> Vico: An entity-component-system based co-simulation framework</a>
3756

3857
<main className="prose max-w-none">
39-
<article dangerouslySetInnerHTML={{ __html: html }} />
58+
<article dangerouslySetInnerHTML={{ __html: HTML }} />
4059
</main>
4160

4261
{/* Contact Section */}

0 commit comments

Comments
 (0)