Created
October 8, 2022 05:26
-
-
Save omar2205/30db9a52fa9362cfb05399bb269e2b94 to your computer and use it in GitHub Desktop.
Deno simple render HTML function
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export type RenderOptions = { | |
title?: string | |
body?: string | |
headTag?: string | |
headers?: HeadersInit | |
} | |
export default function(opts: RenderOptions) { | |
const html = ` | |
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
<meta http-equiv="X-UA-Compatible" content="ie=edge"> | |
<title>${opts.title || 'Home' }</title> | |
<style> | |
body { | |
margin: 0; padding: 0; | |
font-family: helvetica, arial, sans-serif; | |
} | |
</style> | |
</head> | |
<body> | |
${opts.body || '<h1>not found</h1>'} | |
</body> | |
</html> | |
` | |
const res = new Response(html, { | |
headers: { | |
...opts.headers, | |
'Content-Type': 'text/html; charset=utf-8', | |
} | |
}) | |
return res | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment