make logging cleaner, etag more
This commit is contained in:
parent
d0ff1b2d04
commit
7e6a1cbd58
|
@ -16,5 +16,5 @@ COPY ./blog /site/blog
|
|||
COPY ./css /site/css
|
||||
COPY ./app /app
|
||||
COPY ./app.json .
|
||||
HEALTHCHECK CMD wget --spider http://127.0.0.1:5000 || exit 1
|
||||
HEALTHCHECK CMD wget --spider http://127.0.0.1:5000/.within/health || exit 1
|
||||
CMD ./site
|
||||
|
|
|
@ -91,6 +91,17 @@ func (s *Site) showPost(w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
s.renderTemplatePage("blogpost.html", p).ServeHTTP(w, r)
|
||||
const dateFormat = `2006-01-02`
|
||||
s.renderTemplatePage("blogpost.html", struct {
|
||||
Title string
|
||||
Link string
|
||||
BodyHTML template.HTML
|
||||
Date string
|
||||
}{
|
||||
Title: p.Title,
|
||||
Link: p.Link,
|
||||
BodyHTML: p.BodyHTML,
|
||||
Date: p.Date.Format(dateFormat),
|
||||
}).ServeHTTP(w, r)
|
||||
postView.With(prometheus.Labels{"base": filepath.Base(p.Link)}).Inc()
|
||||
}
|
||||
|
|
|
@ -6,7 +6,6 @@ import (
|
|||
"io/ioutil"
|
||||
"net/http"
|
||||
"os"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"christine.website/internal/blog"
|
||||
|
@ -38,8 +37,14 @@ func main() {
|
|||
ln.FatalErr(context.Background(), err, ln.Action("Build"))
|
||||
}
|
||||
|
||||
mux := http.NewServeMux()
|
||||
mux.HandleFunc("/.within/health", func(w http.ResponseWriter, r *http.Request) {
|
||||
http.Error(w, "OK", http.StatusOK)
|
||||
})
|
||||
mux.Handle("/", s)
|
||||
|
||||
ln.Log(context.Background(), ln.F{"action": "http_listening", "port": port})
|
||||
http.ListenAndServe(":"+port, s)
|
||||
http.ListenAndServe(":"+port, mux)
|
||||
}
|
||||
|
||||
// Site is the parent object for https://christine.website's backend.
|
||||
|
@ -53,9 +58,6 @@ type Site struct {
|
|||
mux *http.ServeMux
|
||||
sitemap []byte
|
||||
xffmw *xff.XFF
|
||||
|
||||
templates map[string]*template.Template
|
||||
tlock sync.RWMutex
|
||||
}
|
||||
|
||||
func (s *Site) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
|
@ -169,9 +171,6 @@ func Build() (*Site, error) {
|
|||
|
||||
s.renderTemplatePage("index.html", nil).ServeHTTP(w, r)
|
||||
})
|
||||
s.mux.HandleFunc("/.within/health", func(w http.ResponseWriter, r *http.Request) {
|
||||
http.Error(w, "OK", http.StatusOK)
|
||||
})
|
||||
s.mux.Handle("/metrics", promhttp.Handler())
|
||||
s.mux.Handle("/resume", middleware.Metrics("resume", s.renderTemplatePage("resume.html", s.Resume)))
|
||||
s.mux.Handle("/blog", middleware.Metrics("blog", s.renderTemplatePage("blogindex.html", s.Posts)))
|
||||
|
|
|
@ -75,7 +75,6 @@ func (s *Site) createJSONFeed(w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
e := json.NewEncoder(w)
|
||||
e.SetIndent("", "\t")
|
||||
|
|
|
@ -15,12 +15,13 @@ import (
|
|||
|
||||
// Post is a single blogpost.
|
||||
type Post struct {
|
||||
Title string `json:"title"`
|
||||
Link string `json:"link"`
|
||||
Summary string `json:"summary,omitifempty"`
|
||||
Body string `json:"-"`
|
||||
BodyHTML template.HTML `json:"body"`
|
||||
Date time.Time `json:"date"`
|
||||
Title string `json:"title"`
|
||||
Link string `json:"link"`
|
||||
Summary string `json:"summary,omitifempty"`
|
||||
Body string `json:"-"`
|
||||
BodyHTML template.HTML `json:"body"`
|
||||
Date time.Time
|
||||
DateString string `json:"date"`
|
||||
}
|
||||
|
||||
// Posts implements sort.Interface for a slice of Post objects.
|
||||
|
@ -78,11 +79,12 @@ func LoadPosts(path string) (Posts, error) {
|
|||
}
|
||||
|
||||
p := Post{
|
||||
Title: fm.Title,
|
||||
Date: date,
|
||||
Link: strings.Split(path, ".")[0],
|
||||
Body: string(remaining),
|
||||
BodyHTML: template.HTML(output),
|
||||
Title: fm.Title,
|
||||
Date: date,
|
||||
DateString: fm.Date,
|
||||
Link: strings.Split(path, ".")[0],
|
||||
Body: string(remaining),
|
||||
BodyHTML: template.HTML(output),
|
||||
}
|
||||
result = append(result, p)
|
||||
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
<p>
|
||||
<ul>
|
||||
{{ range . }}
|
||||
<li>{{ .Date }} - <a href="{{ .Link }}">{{ .Title }}</a></li>
|
||||
<li>{{ .DateString }} - <a href="{{ .Link }}">{{ .Title }}</a></li>
|
||||
{{ end }}
|
||||
</ul>
|
||||
</p>
|
||||
|
|
Loading…
Reference in New Issue