Closed pkra closed 11 months ago
A bit rough (eval!) but gets the job done:
import { parseHTML } from 'linkedom';
import fs from 'node:fs';
const {
window, document, customElements,
HTMLElement,
Event, CustomEvent
} = parseHTML(fs.readFileSync('./m522.html').toString());
document.querySelector('script').remove();
eval(fs.readFileSync('./customelements.js'))
console.log(document.toString())
no idea if the previous version ever worked but here's an updated one that does:
import { parseHTML } from 'linkedom';
import fs from 'node:fs';
const {
window, document, customElements,
HTMLElement,
Event, CustomEvent
} = parseHTML(fs.readFileSync('./m522.html').toString());
// make some globals so customelements.js can find it
globalThis.HTMLElement = HTMLElement;
globalThis.customElements = customElements;
globalThis.document = document;
// upgrade/render our elements
await import('./customelements.js');
// TODO: MathJax SSR
// add pagedjs
// document.querySelector('script[src="customelements.js"]').setAttribute('src', 'https://unpkg.com/pagedjs/dist/paged.polyfill.js');
// save
console.log(document.toString())
I added SSR demos. More work to be done but in another issue.
Let's add a demo/test to render server-side.