feat: prerender crawlable portfolio artifacts
This commit is contained in:
@@ -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');
|
||||
|
||||
Reference in New Issue
Block a user