feat: Support setting <html> in _app template (#1617)

This commit is contained in:
Marvin Hagemeister
2023-08-11 18:40:20 +02:00
committed by GitHub
parent d601f4cef4
commit 86f92114d8
27 changed files with 414 additions and 95 deletions
+29
View File
@@ -1,4 +1,5 @@
import {
basename,
dirname,
existsSync,
extname,
@@ -230,6 +231,34 @@ await start(manifest, { plugins: [twindPlugin(twindConfig)] });\n`;
}
}
// Add default _app.tsx if not present
const routes = Array.from(Deno.readDirSync(join(srcDirectory, "routes")));
if (!routes.find((entry) => entry.isFile && entry.name.startsWith("_app."))) {
const APP_TSX = `import { AppProps } from "$fresh/server.ts";
export default function App({ Component }: AppProps) {
return (
<html>
<head>
<meta charSet="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>${basename(resolvedDirectory)}</title>
</head>
<body>
<Component />
</body>
</html>
);
}`;
await Deno.writeTextFile(
join(srcDirectory, "routes", "_app.tsx"),
APP_TSX,
);
}
console.log(routes);
// await Deno.writeTextFile(MAIN_TS_PATH, MAIN_TS);
const manifest = await collect(srcDirectory);
await generate(srcDirectory, manifest);