2023-12-30 05:29:53 +00:00
|
|
|
// https://vike.dev/onRenderHtml
|
2024-01-10 01:00:38 +00:00
|
|
|
import config from 'config';
|
2023-12-30 05:29:53 +00:00
|
|
|
import { renderToString as renderToString_ } from '@vue/server-renderer';
|
2024-01-10 01:00:38 +00:00
|
|
|
import { escapeInject, dangerouslySkipEscape } from 'vike/server'; /* eslint-disable-line import/extensions */
|
2023-12-30 05:29:53 +00:00
|
|
|
|
|
|
|
import { createApp } from './app.js';
|
2024-01-10 01:00:38 +00:00
|
|
|
|
|
|
|
function getTitle(location) {
|
|
|
|
if (!location) {
|
|
|
|
return config.title;
|
|
|
|
}
|
|
|
|
|
|
|
|
return `${config.title} - ${location.slice(0, 1).toUpperCase()}${location.slice(1)}`;
|
|
|
|
}
|
2023-12-30 05:29:53 +00:00
|
|
|
|
|
|
|
async function renderToString(app) {
|
|
|
|
let err;
|
|
|
|
// Workaround: renderToString_() swallows errors in production, see https://github.com/vuejs/core/issues/7876
|
|
|
|
|
|
|
|
app.config.errorHandler = (err_) => { // eslint-disable-line no-param-reassign
|
|
|
|
err = err_;
|
|
|
|
};
|
|
|
|
|
|
|
|
const appHtml = await renderToString_(app);
|
|
|
|
|
|
|
|
if (err) {
|
|
|
|
throw err;
|
|
|
|
}
|
|
|
|
|
|
|
|
return appHtml;
|
|
|
|
}
|
|
|
|
|
|
|
|
async function onRenderHtml(pageContext) {
|
|
|
|
const { Page, pageProps } = pageContext;
|
|
|
|
// This onRenderHtml() hook only supports SSR, see https://vike.dev/render-modes for how to modify
|
|
|
|
// onRenderHtml() to support SPA
|
|
|
|
|
|
|
|
if (!Page) {
|
|
|
|
throw new Error('My render() hook expects pageContext.Page to be defined');
|
|
|
|
}
|
|
|
|
|
|
|
|
const app = createApp(Page, pageProps, pageContext);
|
|
|
|
|
|
|
|
const appHtml = await renderToString(app);
|
|
|
|
|
|
|
|
// See https://vike.dev/head
|
|
|
|
const { documentProps } = pageContext.exports;
|
|
|
|
const title = getTitle(documentProps?.title || pageContext.title);
|
|
|
|
const desc = (documentProps && documentProps.description) || 'traxxx';
|
|
|
|
|
|
|
|
const documentHtml = escapeInject`<!DOCTYPE html>
|
|
|
|
<html lang="en">
|
|
|
|
<head>
|
|
|
|
<meta charset="UTF-8" />
|
|
|
|
|
|
|
|
<link rel="apple-touch-icon" sizes="180x180" href="/img/favicon/apple-touch-icon.png">
|
|
|
|
<link rel="icon" type="image/png" sizes="32x32" href="/img/favicon/favicon-32x32.png">
|
|
|
|
<link rel="icon" type="image/png" sizes="16x16" href="/img/favicon/favicon-16x16.png">
|
|
|
|
<link rel="manifest" href="/img/favicon/site.webmanifest">
|
|
|
|
<link rel="mask-icon" href="/img/favicon/safari-pinned-tab.svg" color="#5bbad5">
|
|
|
|
<link rel="shortcut icon" href="/img/favicon/favicon.ico">
|
2024-06-25 22:15:02 +00:00
|
|
|
|
2023-12-30 05:29:53 +00:00
|
|
|
<meta name="msapplication-TileColor" content="#b91d47">
|
|
|
|
<meta name="msapplication-config" content="/img/favicon/browserconfig.xml">
|
|
|
|
<meta name="theme-color" content="#f65596">
|
|
|
|
|
2024-06-25 22:19:34 +00:00
|
|
|
<meta property="og:title" content="traxxx" />
|
2024-06-25 22:15:02 +00:00
|
|
|
<meta property="og:image" content="https://traxxx.me/img/og_logo.png" />
|
|
|
|
|
2024-03-27 15:41:22 +00:00
|
|
|
<meta name="viewport" content="width=device-width,height=device-height,initial-scale=1.0,interactive-widget=resizes-content" />
|
2023-12-30 05:29:53 +00:00
|
|
|
<meta name="description" content="${desc}" />
|
|
|
|
|
2024-06-06 00:58:35 +00:00
|
|
|
${config.analytics.enabled ? dangerouslySkipEscape(`<script src="${config.analytics.address}" data-website-id="${config.analytics.siteId}" async></script>`) : ''}
|
|
|
|
|
2023-12-30 05:29:53 +00:00
|
|
|
<title>${title}</title>
|
|
|
|
</head>
|
|
|
|
<body>
|
|
|
|
<div id="app">${dangerouslySkipEscape(appHtml)}</div>
|
|
|
|
</body>
|
|
|
|
</html>`;
|
|
|
|
|
|
|
|
return {
|
|
|
|
documentHtml,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
export { onRenderHtml };
|