package Webserver

import (
	"log"
	"net/http"

	"PersonalWebsite/Database"
)

func ViewIndex(w http.ResponseWriter, r *http.Request) {
	var (
		v = make(map[string]interface{})
		e error
	)

	v["PageView"] = "index-intro.gohtml"
	v["Posts"], e = Database.GetPostsList(5, 0)
	if e != nil {
		log.Println(e)
		http.Redirect(w, r, "/error", 302)
	}

	ServeTemplate(w, r, "html/index.gohtml", v)
}

func ViewLinks(w http.ResponseWriter, r *http.Request) {
	var (
		v = make(map[string]interface{})
	)

	v["PageView"] = "index-links.gohtml"

	ServeTemplate(w, r, "html/index.gohtml", v)

}

func ViewError(w http.ResponseWriter, r *http.Request) {
	var (
		v = make(map[string]interface{})
	)

	v["PageView"] = "error.gohtml"

	ServeTemplate(w, r, "html/index.gohtml", v)

}
