feat: prerender crawlable portfolio artifacts

This commit is contained in:
2026-09-02 02:10:26 +03:00
parent 967a3d4d6c
commit 3dd4a818d0
13 changed files with 1167 additions and 12 deletions

View File

@@ -1,16 +1,25 @@
import { createApp } from './app';
import type { ProductionInputs } from './content/types';
declare global {
interface Window {
__PORTFOLIO_INPUTS__?: Readonly<ProductionInputs>;
export const readProductionInputsSnapshot = (source: Document): Readonly<ProductionInputs> => {
const snapshot = source.getElementById('portfolio-inputs');
if (
snapshot === null ||
snapshot.tagName !== 'SCRIPT' ||
snapshot.getAttribute('type') !== 'application/json'
) {
throw new Error('The inert portfolio input snapshot is unavailable.');
}
const serializedInputs = snapshot.textContent;
if (serializedInputs === null || serializedInputs.length === 0) {
throw new Error('The inert portfolio input snapshot is empty.');
}
return JSON.parse(serializedInputs) as Readonly<ProductionInputs>;
};
const appRoot = document.getElementById('app');
if (appRoot !== null) {
createApp(readProductionInputsSnapshot(document)).mount(appRoot);
}
const inputs = window.__PORTFOLIO_INPUTS__;
if (inputs === undefined) {
throw new Error('The serialized portfolio input snapshot is unavailable.');
}
createApp(inputs).mount('#app');