menuserver/server/controllers/view.controller.js
Martin Donnelly 9e2c07ba38 init
2019-12-11 00:07:07 +00:00

49 lines
1.8 KiB
JavaScript

// Create and Save a new Note
const dbmanager = require('../lib/dbmanager');
const markdown = require( 'markdown' ).markdown;
function makeHtml(data) {
const md = data.md;
const html = markdown.toHTML( md );
return `<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>${data.name}</title>
<style>
@import url('https://fonts.googleapis.com/css?family=Roboto');:root {--primary-color: #64B5F6;--dark-color: #333333;--light-color: #f4f4f4;--danger-color: #dc3545;--success-color: #28a745;}* {box-sizing: border-box;margin: 0;padding: 0;}body {font-family: 'Roboto', sans-serif;font-size: 1rem;line-height: 1.6;background-color: #fff;color: #333;}a {color: var(--primary-color);text-decoration: none;}a:hover {color: #666;}ul {list-style: none;}img {width: 100%;}.container {max-width: 1100px;margin: auto;overflow: hidden;padding: 0 2rem;}@media (max-width: 700px) {.hide-sm {display: none;}.grid-2, .grid-3, .grid-4 {grid-template-columns: 1fr;}.x-large {font-size: 3rem;}.large {font-size: 2rem;}.lead {font-size: 1rem;}.navbar {display: block;text-align: center;}.navbar ul {text-align: center;justify-content: center;}}
</style>
</head>
<body>
<div class="container">
${html}
</div>
</body>
</html>`;
}
exports.findOne = (req, res) => {
console.log('>findOne req', req.params);
if(!req.params.recipeId)
return res.status(400).send({
'message': 'Recipe id missing'
});
const short = req.params.recipeId;
dbmanager.getOneShort(short)
.then((data) => {
res.send(makeHtml(data));
})
.catch((err) => {
res.status(500).send({
'message': err.message || 'Some error occurred while querying the database.'
});
});
};