Skip to content

Instantly share code, notes, and snippets.

@omar2205
Created October 8, 2022 05:26
Show Gist options
  • Save omar2205/30db9a52fa9362cfb05399bb269e2b94 to your computer and use it in GitHub Desktop.
Save omar2205/30db9a52fa9362cfb05399bb269e2b94 to your computer and use it in GitHub Desktop.
Deno simple render HTML function
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