${escapeHtml(incident.title)}
${escapeHtml(incident.impact)}${formatTimestamp(incident.started_at)}
`,
];
if (incident.message) {
- parts.push(`${escapeHtml(incident.message)}
`);
+ parts.push(`${escapeHtml(incident.message)}
`);
}
parts.push('');
return parts.join('');
@@ -194,13 +194,13 @@ function renderMaintenanceCard(
}
const parts: string[] = [
- `${escapeHtml(window.title)}
${formatTimestamp(window.starts_at)} - ${formatTimestamp(window.ends_at)}
`,
+ `${escapeHtml(window.title)}
${formatTimestamp(window.starts_at)} - ${formatTimestamp(window.ends_at)}
`,
];
if (affected.length > 0) {
- parts.push(`Affected: ${affected.join(', ')}
`);
+ parts.push(`Affected: ${affected.join(', ')}
`);
}
if (window.message) {
- parts.push(`${escapeHtml(window.message)}
`);
+ parts.push(`${escapeHtml(window.message)}
`);
}
parts.push('');
return parts.join('');
@@ -247,12 +247,12 @@ function renderPreload(
: 'Never checked';
monitorCardsParts.push(
- `${escapeHtml(monitor.name)}
${escapeHtml(monitor.type)}
${escapeHtml(uptimePct)}${statusLabel}
Availability (30d)
${buildUptimeStripSvg(monitor.uptime_day_strip)}
Recent checks
${buildHeartbeatStripSvg(monitor.heartbeat_strip)}
${lastCheckedLabel}
`,
+ `${escapeHtml(monitor.name)}
${escapeHtml(monitor.type)}
${escapeHtml(uptimePct)}${statusLabel}
Availability (30d)
${buildUptimeStripSvg(monitor.uptime_day_strip)}
Recent checks
${buildHeartbeatStripSvg(monitor.heartbeat_strip)}
${lastCheckedLabel}
`,
);
}
groupedMonitorsParts.push(
- `${escapeHtml(groupName)}
${groupMonitors.length}${monitorCardsParts.join('')}
`,
+ `${escapeHtml(groupName)}
${groupMonitors.length}${monitorCardsParts.join('')}
`,
);
}
@@ -274,7 +274,7 @@ function renderPreload(
}
}
- maintenanceSection = `Scheduled Maintenance
${activeCards.length > 0 ? `${activeCards.join('')}
` : ''}${upcomingCards.length > 0 ? `${upcomingCards.join('')}
` : ''}`;
+ maintenanceSection = `Scheduled Maintenance
${activeCards.length > 0 ? `${activeCards.join('')}
` : ''}${upcomingCards.length > 0 ? `${upcomingCards.join('')}
` : ''}`;
}
let incidentSection = '';
@@ -283,26 +283,26 @@ function renderPreload(
for (const incident of snapshot.active_incidents) {
incidentCards.push(renderIncidentCard(incident, formatTimestamp));
}
- incidentSection = `Active Incidents
${incidentCards.join('')}
`;
+ incidentSection = `Active Incidents
${incidentCards.join('')}
`;
}
const incidentHistory = snapshot.resolved_incident_preview
? renderIncidentCard(snapshot.resolved_incident_preview, formatTimestamp)
- : `No past incidents
`;
+ : 'No past incidents
';
const maintenanceHistory = snapshot.maintenance_history_preview
? monitorNames
? renderMaintenanceCard(snapshot.maintenance_history_preview, monitorNames, formatTimestamp)
- : `No past maintenance
`
- : `No past maintenance
`;
+ : 'No past maintenance
'
+ : 'No past maintenance
';
const descriptionHtml = siteDescription
- ? `${escapeHtml(siteDescription)}
`
+ ? `${escapeHtml(siteDescription)}
`
: '';
const hiddenMonitorMessage =
hiddenMonitorCount > 0
- ? `${hiddenMonitorCount} more services will appear after the app finishes loading.
`
+ ? `${hiddenMonitorCount} more services will appear after the app finishes loading.
`
: '';
- return `${escapeHtml(siteTitle)}
${descriptionHtml}
${escapeHtml(overall)}${escapeHtml(bannerTitle)}
Updated: ${formatTimestamp(generatedAt)}
${maintenanceSection}${incidentSection}Services
${groupedMonitorsParts.join('')}${hiddenMonitorMessage}Incident History
${incidentHistory}Maintenance History
${maintenanceHistory} `;
+ return `${escapeHtml(siteTitle)}
${descriptionHtml}
${escapeHtml(overall)}${escapeHtml(bannerTitle)}
Updated: ${formatTimestamp(generatedAt)}
${maintenanceSection}${incidentSection}Services
${groupedMonitorsParts.join('')}${hiddenMonitorMessage}Incident History
${incidentHistory}Maintenance History
${maintenanceHistory} `;
}
export function buildHomepageRenderArtifact(
@@ -315,14 +315,17 @@ export function buildHomepageRenderArtifact(
const allMonitorNames = needsMonitorNames
? new Map(snapshot.monitors.map((monitor) => [monitor.id, monitor.name]))
: undefined;
- const bootstrapSnapshot: PublicHomepageResponse =
+ const bootstrapSnapshot =
snapshot.bootstrap_mode === 'partial' || snapshot.monitors.length > MAX_BOOTSTRAP_MONITORS
? {
...snapshot,
bootstrap_mode: 'partial' as const,
monitors: snapshot.monitors.slice(0, MAX_BOOTSTRAP_MONITORS),
}
- : snapshot;
+ : {
+ ...snapshot,
+ bootstrap_mode: 'full' as const,
+ };
const metaTitle = normalizeSnapshotText(snapshot.site_title, 'Uptimer');
const fallbackDescription = normalizeSnapshotText(
snapshot.banner.title,
@@ -334,26 +337,13 @@ export function buildHomepageRenderArtifact(
return {
generated_at: snapshot.generated_at,
- preload_html: `${renderPreload(bootstrapSnapshot, allMonitorNames)}
`,
+ preload_html: `${renderPreload(bootstrapSnapshot, allMonitorNames)}
`,
snapshot: bootstrapSnapshot,
meta_title: metaTitle,
meta_description: metaDescription,
};
}
-function buildHomepageRenderArtifactBodyJson(opts: {
- fullSnapshot: PublicHomepageResponse;
- render: PublicHomepageRenderArtifact;
- snapshotBodyJson: string | null;
-}): string {
- const snapshotJson =
- opts.snapshotBodyJson && opts.render.snapshot === opts.fullSnapshot
- ? opts.snapshotBodyJson
- : JSON.stringify(opts.render.snapshot);
-
- return `{"generated_at":${opts.render.generated_at},"preload_html":${JSON.stringify(opts.render.preload_html)},"snapshot":${snapshotJson},"meta_title":${JSON.stringify(opts.render.meta_title)},"meta_description":${JSON.stringify(opts.render.meta_description)}}`;
-}
-
function looksLikeHomepagePayload(value: unknown): value is PublicHomepageResponse {
if (!isRecord(value)) return false;
return (
@@ -757,11 +747,7 @@ export async function writeHomepageSnapshot(
): Promise {
const render = buildHomepageRenderArtifact(payload);
const dataBodyJson = JSON.stringify(payload);
- const renderBodyJson = buildHomepageRenderArtifactBodyJson({
- fullSnapshot: payload,
- render,
- snapshotBodyJson: dataBodyJson,
- });
+ const renderBodyJson = JSON.stringify(render);
await db.batch([
homepageSnapshotUpsertStatement(db, SNAPSHOT_KEY, payload.generated_at, dataBodyJson, now),
@@ -781,11 +767,7 @@ export async function writeHomepageArtifactSnapshot(
payload: PublicHomepageResponse,
): Promise {
const render = buildHomepageRenderArtifact(payload);
- const renderBodyJson = buildHomepageRenderArtifactBodyJson({
- fullSnapshot: payload,
- render,
- snapshotBodyJson: null,
- });
+ const renderBodyJson = JSON.stringify(render);
await homepageSnapshotUpsertStatement(
db,