aboutsummaryrefslogtreecommitdiff
path: root/index.go
blob: 10160ab12750f8572c98eae86635403a4ecafd51 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
package main

import (
	"io/ioutil"
	"net/http"
	"text/template"
)

func init() {
	http.HandleFunc("/index", indexHandler)
}

var indextmpl = template.Must(template.ParseFiles("tmpl/root", "tmpl/index"))

func indexHandler(w http.ResponseWriter, r *http.Request) {
	files, err := ioutil.ReadDir("data")
	if err != nil {
		http.Error(w, err.Error(), http.StatusInternalServerError)
		return
	}
	p := new(Page)
	for _, entry := range files {
		file := entry.Name()
		if !entry.IsDir() && file[0] != '.' {
			p.Pages = append(p.Pages, entry)
		}
	}
	p.render(w, indextmpl)
}