package archive import ( "fmt" "html/template" "net/http" ) type ArchiveState struct { svr *ArchiveServer log *LogSource logBestSlug string query string queryIsRegex bool ym YearMonth page int highestPage int } func NewArchiveState(svr *ArchiveServer) *ArchiveState { return &ArchiveState{svr: svr} } func (this *ArchiveState) selectSource(log *LogSource) error { logBestSlug, err := this.svr.bestSlugFor(log) if err != nil { return err } this.log = log this.logBestSlug = logBestSlug return nil } func (this *ArchiveState) renderError(w http.ResponseWriter, msg string) { this.renderTemplate(w, []byte(template.HTMLEscapeString(msg))) } func (this *ArchiveState) renderTemplate(w http.ResponseWriter, body []byte) { this.renderTemplateHead(w) w.Write(body) this.renderTemplateFoot(w) } func (this *ArchiveState) renderTemplateHead(w http.ResponseWriter) { w.Header().Set(`Content-Type`, `text/html; charset=UTF-8`) w.Header().Set(`X-UA-Compatible`, `IE=Edge`) w.WriteHeader(200) title := `Archives` if this.log != nil { title = this.log.Description + ` Archives` } showPageURLs := (this.log != nil && len(this.query) == 0) w.Write([]byte(`