<commit_before>package app

import (
	"bytes"
	"fmt"
	htmpl "html/template"
	"log"
	"net/http"
	"net/url"
	"path/filepath"
	"strconv"
	"time"
)

var (
	// TemplateDir is the directory containing the html/template template files.
	TemplateDir = filepath.Join(defaultBase("github.com/sourcegraph/thesrc/app"), "tmpl")
)

func LoadTemplates() {
	err := parseHTMLTemplates([][]string{
		{"posts/show.html", "posts/common.html", "common.html", "layout.html"},
		{"posts/list.html", "posts/common.html", "common.html", "layout.html"},
		{"posts/submit_form.html", "common.html", "layout.html"},
		{"error.html", "common.html", "layout.html"},
	})
	if err != nil {
		log.Fatal(err)
	}
}

// templateCommon is data that is passed to (and available to) all templates.
type templateCommon struct {
	CurrentURL         *url.URL
	PageGenerationTime time.Duration
}

func renderTemplate(w http.ResponseWriter, r *http.Request, name string, status int, data interface{}) error {
	w.WriteHeader(status)
	if ct := w.Header().Get("content-type"); ct == "" {
		w.Header().Set("Content-Type", "text/html; charset=utf-8")
	}

	t := templates[name]
	if t == nil {
		return fmt.Errorf("Template %s not found", name)
	}

	// Write to a buffer to properly catch errors and avoid partial output written to the http.ResponseWriter
	var buf bytes.Buffer
	err := t.Execute(buf, data)
	if err != nil {
		return err
	}
	_, err = buf.WriteTo(w)
	return err
}

var templates = map[string]*htmpl.Template{}
<commit_msg>fix buf arg<commit_after>package app

import (
	"bytes"
	"fmt"
	htmpl "html/template"
	"log"
	"net/http"
	"net/url"
	"path/filepath"
	"strconv"
	"time"
)

var (
	// TemplateDir is the directory containing the html/template template files.
	TemplateDir = filepath.Join(defaultBase("github.com/sourcegraph/thesrc/app"), "tmpl")
)

func LoadTemplates() {
	err := parseHTMLTemplates([][]string{
		{"posts/show.html", "posts/common.html", "common.html", "layout.html"},
		{"posts/list.html", "posts/common.html", "common.html", "layout.html"},
		{"posts/submit_form.html", "common.html", "layout.html"},
		{"error.html", "common.html", "layout.html"},
	})
	if err != nil {
		log.Fatal(err)
	}
}

// templateCommon is data that is passed to (and available to) all templates.
type templateCommon struct {
	CurrentURL         *url.URL
	PageGenerationTime time.Duration
}

func renderTemplate(w http.ResponseWriter, r *http.Request, name string, status int, data interface{}) error {
	w.WriteHeader(status)
	if ct := w.Header().Get("content-type"); ct == "" {
		w.Header().Set("Content-Type", "text/html; charset=utf-8")
	}

	t := templates[name]
	if t == nil {
		return fmt.Errorf("Template %s not found", name)
	}

	// Write to a buffer to properly catch errors and avoid partial output written to the http.ResponseWriter
	var buf bytes.Buffer
	err := t.Execute(&buf, data)
	if err != nil {
		return err
	}
	_, err = buf.WriteTo(w)
	return err
}

var templates = map[string]*htmpl.Template{}

{'fraction_non_alphanumeric': 0.16122517670817907, 'fraction_numerical': 0.0006731740154830024, 'mean_word_length': 4.168695652173913, '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': '1494986', 'n_tokens_mistral': 1045, 'n_tokens_neox': 1012, 'n_words': 266}