diff --git a/ArchiveState.go b/ArchiveState.go new file mode 100644 index 0000000..7ce0ee7 --- /dev/null +++ b/ArchiveState.go @@ -0,0 +1,172 @@ +package archive + +import ( + "fmt" + "html/template" + "net/http" +) + +type ArchiveState struct { + svr *ArchiveServer + log *LogSource + logBestSlug string + query string + queryIsRegex bool + nonce string + ym YearMonth + page int + highestPage int +} + +func NewArchiveState(svr *ArchiveServer, log *LogSource) (*ArchiveState, error) { + logBestSlug, err := svr.bestSlugFor(log) + if err != nil { + return nil, err + } + + return &ArchiveState{ + svr: svr, + log: log, + logBestSlug: logBestSlug, + }, nil +} + +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(` + + + + + ` + template.HTMLEscapeString(title) + ` + + + + + +
+ `)) + + // Header ends +} + +func (this *ArchiveState) renderTemplateFoot(w http.ResponseWriter) { + w.Write([]byte(` +
+ + + +`)) +} diff --git a/util.go b/util.go new file mode 100644 index 0000000..b1b035a --- /dev/null +++ b/util.go @@ -0,0 +1,9 @@ +package archive + +func attr(condition bool, whenMet string) string { + if condition { + return whenMet + } else { + return "" + } +}