lit-html-template
v1.0.4
Published
Example:
Downloads
199
Readme
Example:
post.html.js
const html = require('lit-html-template');
const post = function (data) {
return html`
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>${data.title}</title>
</head>
<body>
<h2>
<a href="/">首页</a>
</h2>
<div>
${data.content}
</div>
</body>
</html>
`;
}
module.exports = post;
post.controller.js
app.get('/:slug/', async (request, reply) => {
const res = await db.get(`SELECT * FROM posts WHERE slug=? LIMIT 1`, [request.params.slug]);
reply
.code(200)
.header('Content-Type', 'text/html; charset=utf-8')
.send(view.post(res))
})