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 { favIconPngUrl, favIconUrl } from "../../shared/config";
6 import { ILemmyConfig, IsoDataOptionalSite } from "../../shared/interfaces";
7 import { fetchIconPng } from "./fetch-icon-png";
9 const customHtmlHeader = process.env["LEMMY_UI_CUSTOM_HTML_HEADER"] || "";
11 let appleTouchIcon: string | undefined = undefined;
13 export async function createSsrHtml(
15 isoData: IsoDataOptionalSite
17 const site = isoData.site_res;
19 if (!appleTouchIcon) {
20 appleTouchIcon = site?.site_view.site.icon
21 ? `data:image/png;base64,${sharp(
22 await fetchIconPng(site.site_view.site.icon)
30 background: "#222222",
34 .then(buf => buf.toString("base64"))}`
39 process.env["LEMMY_UI_DEBUG"] === "true"
42 <script src="//cdn.jsdelivr.net/npm/eruda"></script>
43 <script>eruda.init();</script>
48 const helmet = Helmet.renderStatic();
50 const config: ILemmyConfig = { wsHost: process.env.LEMMY_UI_LEMMY_WS_HOST };
54 <html ${helmet.htmlAttributes.toString()}>
56 <script>window.isoData = ${serialize(isoData)}</script>
57 <script>window.lemmyConfig = ${serialize(config)}</script>
59 <!-- A remote debugging utility for mobile -->
62 <!-- Custom injected script -->
65 ${helmet.title.toString()}
66 ${helmet.meta.toString()}
68 <!-- Required meta tags -->
69 <meta name="Description" content="Lemmy">
70 <meta charset="utf-8">
71 <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no, user-scalable=no">
76 href=${site?.site_view.site.icon ?? favIconUrl}
79 <!-- Web app manifest -->
80 <link rel="manifest" href="/manifest.webmanifest" />
81 <link rel="apple-touch-icon" href=${appleTouchIcon} />
82 <link rel="apple-touch-startup-image" href=${appleTouchIcon} />
85 <link rel="stylesheet" type="text/css" href="/static/styles/styles.css" />
87 <!-- Current theme and more -->
88 ${helmet.link.toString()}
92 <body ${helmet.bodyAttributes.toString()}>
94 <div class="alert alert-danger rounded-0" role="alert">
95 <b>Javascript is disabled. Actions will not work.</b>
99 <div id='root'>${root}</div>
100 <script defer src='/static/js/client.js'></script>