1.0.1 • Published 2 years ago

lit-html-template v1.0.1

Weekly downloads
-
License
ISC
Repository
-
Last release
2 years ago

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))
    })