done

parent 6acc3951
const helpers = {
catchError: (res) => {
return (error) => {
res.locals.title = 'Error'
res.status(500).render('error', {
error
})
......
......@@ -206,3 +206,19 @@ nav a:last-child {
.posts-list .post-item-container .post-preview a {
font-size: 1rem;
}
.post-page header h1 {
font-size: 2.5rem;
margin-top: 1rem;
margin-bottom: 0;
}
.post-page header time {
font-size: 1rem;
color: var(--c-secondary);
text-transform: uppercase;
}
.post-page article {
font-size: 1.25rem;
}
const sprintf = require('sprintf-js').sprintf
const catchError = require('../helpers.js').catchError
const ObjectId = require('mongodb').ObjectID
module.exports = (app, db) => {
app.get('/', (req, res) => {
......@@ -19,6 +20,28 @@ module.exports = (app, db) => {
})
})
app.get('/posts/:id', (req, res) => {
const id = req.params.id
const col = db.collection('posts')
col.findOne({
_id: new ObjectId(id)
}).then((post) => {
res.locals.title = post.title;
const timestamp = post._id.getTimestamp()
const dates = {
raw: timestamp,
human: timestamp.toISOString().split("T")[0]
}
res.render('posts/view', {
dates,
post
})
}).catch(catchError(res))
})
app.post('/posts', (req, res) => {
let errors = [], post = {}
const fields = ['title', 'body']
......
<main class="post-page">
<nav>
<a href="/">&larr; Back</a>
</nav>
<header>
<h1>
{{ post.title }}
</h1>
<time datetime="{{ dates.raw }}">Posted on {{ dates.human }}</time>
</header>
<article>
<p>
{{ post.body }}
</p>
</article>
</main>
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment