mirror of
https://github.com/naturalcrit/homebrewery.git
synced 2026-03-22 08:58:11 +00:00
dev base (kinda stable)
This commit is contained in:
12
client/entry-client-admin.jsx
Normal file
12
client/entry-client-admin.jsx
Normal file
@@ -0,0 +1,12 @@
|
||||
import React from 'react'
|
||||
import { hydrateRoot } from 'react-dom/client';
|
||||
import Admin from './admin.jsx';
|
||||
|
||||
import './admin/admin.less'
|
||||
|
||||
window.start_app = (props) => {
|
||||
hydrateRoot(
|
||||
document.getElementById('reactRoot'),
|
||||
<Admin {...props} />
|
||||
)
|
||||
}
|
||||
13
client/entry-client-homebrew.jsx
Normal file
13
client/entry-client-homebrew.jsx
Normal file
@@ -0,0 +1,13 @@
|
||||
import React from 'react'
|
||||
import { hydrateRoot } from 'react-dom/client'
|
||||
import Homebrew from './homebrew/homebrew.jsx'
|
||||
|
||||
// CSS MUST be imported here
|
||||
import './homebrew/homebrew.less' // or wherever your CSS lives
|
||||
|
||||
window.start_app = (props) => {
|
||||
hydrateRoot(
|
||||
document.getElementById('reactRoot'),
|
||||
<Homebrew {...props} />
|
||||
)
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
import { renderToString } from 'react-dom/server';
|
||||
import Admin from './admin.jsx';
|
||||
import Admin from './admin/admin.jsx';
|
||||
|
||||
export default (props) => renderToString(<Admin {...props} />);
|
||||
@@ -1,33 +1,66 @@
|
||||
const template = async function(name, title='', props = {}){
|
||||
import fs from "fs";
|
||||
|
||||
const isProd = process.env.NODE_ENV === "production";
|
||||
|
||||
const template = async function ({ vite, url }, name, title = "", props = {}) {
|
||||
const ogTags = [];
|
||||
const ogMeta = props.ogMeta ?? {};
|
||||
Object.entries(ogMeta).forEach(([key, value])=>{
|
||||
if(!value) return;
|
||||
const tag = `<meta property="og:${key}" content="${value}">`;
|
||||
ogTags.push(tag);
|
||||
|
||||
Object.entries(ogMeta).forEach(([key, value]) => {
|
||||
if (!value) return;
|
||||
ogTags.push(`<meta property="og:${key}" content="${value}">`);
|
||||
});
|
||||
const ogMetaTags = ogTags.join('\n');
|
||||
|
||||
const ssrModule = await import(`../build/entry-server-${name}/bundle.js`);
|
||||
const ogMetaTags = ogTags.join("\n");
|
||||
|
||||
return `<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1, height=device-height, interactive-widget=resizes-visual" />
|
||||
<link href="//fonts.googleapis.com/css?family=Open+Sans:400,300,600,700" rel="stylesheet" type="text/css" />
|
||||
<link href=${`/${name}/bundle.css`} type="text/css" rel='stylesheet' />
|
||||
<link rel="icon" href="/assets/favicon.ico" type="image/x-icon" />
|
||||
${ogMetaTags}
|
||||
<meta name="twitter:card" content="summary">
|
||||
<title>${title.length ? `${title} - The Homebrewery`: 'The Homebrewery - NaturalCrit'}</title>
|
||||
</head>
|
||||
<body>
|
||||
<main id="reactRoot">${ssrModule.default(props)}</main>
|
||||
<script src=${`/${name}/bundle.js`}></script>
|
||||
<script>start_app(${JSON.stringify(props)})</script>
|
||||
</body>
|
||||
</html>
|
||||
`;
|
||||
// ----------------
|
||||
// PROD
|
||||
// ----------------
|
||||
if (isProd) {
|
||||
const ssrModule = await import(`../build/entry-server-${name}/bundle.js`);
|
||||
|
||||
return `<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1, height=device-height, interactive-widget=resizes-visual" />
|
||||
<link href="//fonts.googleapis.com/css?family=Open+Sans:400,300,600,700" rel="stylesheet" type="text/css" />
|
||||
<link href="/${name}/bundle.css" rel="stylesheet" />
|
||||
<link rel="icon" href="/assets/favicon.ico" type="image/x-icon" />
|
||||
${ogMetaTags}
|
||||
<meta name="twitter:card" content="summary">
|
||||
<title>${title.length ? `${title} - The Homebrewery` : "The Homebrewery - NaturalCrit"}</title>
|
||||
</head>
|
||||
<body>
|
||||
<main id="reactRoot">${ssrModule.default(props)}</main>
|
||||
<script src="/${name}/bundle.js"></script>
|
||||
<script>start_app(${JSON.stringify(props)})</script>
|
||||
</body>
|
||||
</html>`;
|
||||
}
|
||||
|
||||
// ----------------
|
||||
// DEV
|
||||
// ----------------
|
||||
const { default: render } = await vite.ssrLoadModule(`/client/entry-server-${name}.jsx`);
|
||||
|
||||
let html = `<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1, height=device-height, interactive-widget=resizes-visual" />
|
||||
${ogMetaTags}
|
||||
<title>${title.length ? `${title} - The Homebrewery` : "The Homebrewery - NaturalCrit"}</title>
|
||||
</head>
|
||||
<body>
|
||||
<main id="reactRoot">${render(props)}</main>
|
||||
|
||||
<script type="module" src="/@vite/client"></script>
|
||||
<script type="module" src="/client/entry-client-${name}.jsx"></script>
|
||||
|
||||
</body>
|
||||
|
||||
</html>`;
|
||||
|
||||
return vite.transformIndexHtml(url, html);
|
||||
};
|
||||
|
||||
export default template;
|
||||
export default template;
|
||||
|
||||
Reference in New Issue
Block a user