<commit_before>package main

import (
	"flag"
	"log"
	"net/http"
	"path/filepath"
	"text/template"

	"github.com/lemmi/glubcms"
)

type handler struct {
	prefix string
	tmpl   *template.Template
}

func newhandler(prefix, templatepath string) handler {
	return handler{
		prefix: prefix,
		tmpl:   template.Must(template.ParseGlob(filepath.Join(templatepath, "*.tmpl"))),
	}
}

func (h handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
	log.Println(h.tmpl.DefinedTemplates())
	p := glubcms.PageFromDir(h.prefix, r.URL.Path)
	if err := h.tmpl.ExecuteTemplate(w, "main.tmpl", p); err != nil {
		log.Println(err)
	}
}

func main() {
	prefix := flag.String("prefix", "../example_page", "path to the root dir")
	tmplpath := flag.String("template", "../templates", "path to the template to use")
	addr := flag.String("bind", "localhost:8080", "address to bind to")
	flag.Parse()
	log.Fatal(http.ListenAndServe(*addr, newhandler(*prefix, *tmplpath)))
}<commit_msg>server: add routing for static content and templates<commit_after>package main

import (
	"flag"
	"log"
	"net/http"
	"path/filepath"
	"text/template"

	"github.com/lemmi/glubcms"
)

type handler struct {
	prefix     string
	pageprefix string
	tmpl       *template.Template
}

func newhandler(prefix string) handler {
	return handler{
		prefix:     prefix,
		pageprefix: filepath.Join(prefix, "pages"),
		tmpl:       template.Must(template.ParseGlob(filepath.Join(prefix, "templates", "*.tmpl"))),
	}
}

func (h handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
	p := glubcms.PageFromDir(h.pageprefix, r.URL.Path)
	if err := h.tmpl.ExecuteTemplate(w, "main.tmpl", p); err != nil {
		log.Println(err)
	}
}

func main() {
	prefix := flag.String("prefix", "../example_page", "path to the root dir")
	addr := flag.String("bind", "localhost:8080", "address to bind to")
	flag.Parse()
	http.Handle("/static/",
		http.StripPrefix("/static/",
			http.FileServer(http.Dir(
				filepath.Join(*prefix, "static")))))
	http.Handle("/", newhandler(*prefix))
	log.Fatal(http.ListenAndServe(*addr, nil))
}
{'fraction_non_alphanumeric': 0.1683599419448476, 'fraction_numerical': 0.0038703434929850023, 'mean_word_length': 4.544235924932976, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7099192', 'n_tokens_mistral': 770, 'n_tokens_neox': 741, 'n_words': 162}