1 import { Helmet } from "inferno-helmet";
2 import { renderToString } from "inferno-server";
3 import serialize from "serialize-javascript";
4 import sharp from "sharp";
5 import { ILemmyConfig, IsoDataOptionalSite } from "../../shared/interfaces";
6 import { favIconPngUrl, favIconUrl } from "../../shared/utils";
7 import { fetchIconPng } from "./fetch-icon-png";
8 import { generateManifestBase64 } from "./generate-manifest-base64";
10 const customHtmlHeader = process.env["LEMMY_UI_CUSTOM_HTML_HEADER"] || "";
12 export async function createSsrHtml(
14 isoData: IsoDataOptionalSite
16 const site = isoData.site_res;
18 const appleTouchIcon = site?.site_view.site.icon
19 ? `data:image/png;base64,${sharp(
20 await fetchIconPng(site.site_view.site.icon)
28 background: "#222222",
32 .then(buf => buf.toString("base64"))}`
36 process.env["LEMMY_UI_DEBUG"] === "true"
39 <script src="//cdn.jsdelivr.net/npm/eruda"></script>
40 <script>eruda.init();</script>
45 const helmet = Helmet.renderStatic();
47 const config: ILemmyConfig = { wsHost: process.env.LEMMY_UI_LEMMY_WS_HOST };
51 <html ${helmet.htmlAttributes.toString()}>
53 <script>window.isoData = ${serialize(isoData)}</script>
54 <script>window.lemmyConfig = ${serialize(config)}</script>
56 <!-- A remote debugging utility for mobile -->
59 <!-- Custom injected script -->
62 ${helmet.title.toString()}
63 ${helmet.meta.toString()}
65 <!-- Required meta tags -->
66 <meta name="Description" content="Lemmy">
67 <meta charset="utf-8">
68 <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no, user-scalable=no">
73 href=${site?.site_view.site.icon ?? favIconUrl}
76 <!-- Web app manifest -->
81 href=${`data:application/manifest+json;base64,${await generateManifestBase64(
86 <link rel="apple-touch-icon" href=${appleTouchIcon} />
87 <link rel="apple-touch-startup-image" href=${appleTouchIcon} />
90 <link rel="stylesheet" type="text/css" href="/static/styles/styles.css" />
92 <!-- Current theme and more -->
93 ${helmet.link.toString()}
97 <body ${helmet.bodyAttributes.toString()}>
99 <div class="alert alert-danger rounded-0" role="alert">
100 <b>Javascript is disabled. Actions will not work.</b>
104 <div id='root'>${root}</div>
105 <script defer src='/static/js/client.js'></script>