const router = require('express').Router()
const fs = require('fs')
const _ = require('lodash')
const mw = require('../server/middlewares')
const util = require('../server/util')

router.param('slug', mw.getPostBySlug)

router.get('/', mw.getBlogPosts, (req, res) => {
  res.render('blog', { title: 'Blog — yarmo.eu', nav1: 'blog', nav2: 'posts' })
})
router.get('/blog', mw.getBlogPosts, (req, res) => {
  res.render('blog', { title: 'Blog — yarmo.eu', nav1: 'blog', nav2: 'posts' })
})
router.get('/blog/:s', (req, res) => {
  res.redirect(`/post/${req.params.s}`)
})
router.get('/notes', mw.getNotes, (req, res) => {
  res.render('notes', { title: 'Notes — yarmo.eu', nav1: 'blog', nav2: 'notes' })
})
router.get('/notes/:s', (req, res) => {
  res.redirect(`/post/${req.params.s}`)
})
router.get('/post/:slug', (req, res) => {
  res.render('post', { title: `${res.locals.post.title} — yarmo.eu`, nav1: 'blog', nav2: '' })
})
router.get('/blogroll', (req, res) => {
  res.render('blogroll', { title: 'Blogroll — yarmo.eu', nav1: 'blog', nav2: 'blogroll' })
})
router.get('/feeds', (req, res) => {
  res.render('feeds', { title: 'Feeds — yarmo.eu', nav1: 'blog', nav2: 'feeds' })
})
router.get('/about', (req, res) => {
  res.render('about', { title: 'About me — yarmo.eu', nav1: 'about', nav2: 'about' })
})
router.get('/work', (req, res) => {
  res.render('work', { title: 'Work — yarmo.eu', nav1: 'about', nav2: 'work' })
})
router.get('/now', (req, res) => {
  res.render('now', { title: 'Now — yarmo.eu', nav1: 'about', nav2: 'now' })
})
router.get('/uses', (req, res) => {
  res.render('uses', { title: 'Uses — yarmo.eu', nav1: 'about', nav2: 'uses' })
})
router.get('/music', (req, res) => {
  res.render('music', { title: 'Music — yarmo.eu', nav1: 'about', nav2: 'music' })
})
router.get('/vinyl', mw.getVinyl, (req, res) => {
  res.render('vinyl', { title: 'Vinyl — yarmo.eu', nav1: 'about', nav2: 'music' })
})
router.get('/pgp', (req, res) => {
  res.render('pgp', { title: 'PGP — yarmo.eu', nav1: 'about', nav2: 'pgp' })
})
router.get('/contact', (req, res) => {
  res.render('contact', { title: 'Contact — yarmo.eu', nav1: 'contact', nav2: '' })
})

module.exports = router
