forked from cadey/xesite
fix build
This commit is contained in:
parent
3a21ef1926
commit
9003cd5b93
7
html.go
7
html.go
|
@ -1,6 +1,7 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"html/template"
|
"html/template"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
@ -11,7 +12,7 @@ import (
|
||||||
|
|
||||||
func logTemplateTime(name string, from time.Time) {
|
func logTemplateTime(name string, from time.Time) {
|
||||||
now := time.Now()
|
now := time.Now()
|
||||||
ln.Log(ln.F{"action": "template_rendered", "dur": now.Sub(from).String(), "name": name})
|
ln.Log(context.Background(), ln.F{"action": "template_rendered", "dur": now.Sub(from).String(), "name": name})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Site) renderTemplatePage(templateFname string, data interface{}) http.Handler {
|
func (s *Site) renderTemplatePage(templateFname string, data interface{}) http.Handler {
|
||||||
|
@ -27,11 +28,11 @@ func (s *Site) renderTemplatePage(templateFname string, data interface{}) http.H
|
||||||
t, err = template.ParseFiles("templates/base.html", "templates/"+templateFname)
|
t, err = template.ParseFiles("templates/base.html", "templates/"+templateFname)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
w.WriteHeader(http.StatusInternalServerError)
|
w.WriteHeader(http.StatusInternalServerError)
|
||||||
ln.Error(err, ln.F{"action": "renderTemplatePage", "page": templateFname})
|
ln.Error(context.Background(), err, ln.F{"action": "renderTemplatePage", "page": templateFname})
|
||||||
fmt.Fprintf(w, "error: %v", err)
|
fmt.Fprintf(w, "error: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
ln.Log(ln.F{"action": "loaded_new_template", "fname": templateFname})
|
ln.Log(context.Background(), ln.F{"action": "loaded_new_template", "fname": templateFname})
|
||||||
|
|
||||||
s.tlock.RUnlock()
|
s.tlock.RUnlock()
|
||||||
s.tlock.Lock()
|
s.tlock.Lock()
|
||||||
|
|
13
main.go
13
main.go
|
@ -1,6 +1,7 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"html/template"
|
"html/template"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
@ -15,7 +16,7 @@ import (
|
||||||
"github.com/Xe/jsonfeed"
|
"github.com/Xe/jsonfeed"
|
||||||
"github.com/Xe/ln"
|
"github.com/Xe/ln"
|
||||||
"github.com/gorilla/feeds"
|
"github.com/gorilla/feeds"
|
||||||
"github.com/russross/blackfriday"
|
blackfriday "github.com/russross/blackfriday"
|
||||||
"github.com/tj/front"
|
"github.com/tj/front"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -28,10 +29,10 @@ func main() {
|
||||||
|
|
||||||
s, err := Build()
|
s, err := Build()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ln.Fatal(ln.F{"err": err, "action": "Build"})
|
ln.FatalErr(context.Background(), err, ln.Action("Build"))
|
||||||
}
|
}
|
||||||
|
|
||||||
ln.Log(ln.F{"action": "http_listening", "port": port})
|
ln.Log(context.Background(), ln.F{"action": "http_listening", "port": port})
|
||||||
http.ListenAndServe(":"+port, s)
|
http.ListenAndServe(":"+port, s)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -50,7 +51,7 @@ type Site struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Site) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
func (s *Site) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||||
ln.Log(ln.F{"action": "Site.ServeHTTP", "user_ip_address": r.RemoteAddr, "path": r.RequestURI})
|
ln.Log(r.Context(), ln.F{"action": "Site.ServeHTTP", "user_ip_address": r.RemoteAddr, "path": r.RequestURI})
|
||||||
s.mux.ServeHTTP(w, r)
|
s.mux.ServeHTTP(w, r)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -114,7 +115,7 @@ func Build() (*Site, error) {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
output := blackfriday.MarkdownCommon(remaining)
|
output := blackfriday.Run(remaining)
|
||||||
|
|
||||||
p := &Post{
|
p := &Post{
|
||||||
Title: fm.Title,
|
Title: fm.Title,
|
||||||
|
@ -144,7 +145,7 @@ func Build() (*Site, error) {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
s.Resume = template.HTML(blackfriday.MarkdownCommon(sb.MustBytes("resume/resume.md")))
|
s.Resume = template.HTML(blackfriday.Run(sb.MustBytes("resume/resume.md")))
|
||||||
|
|
||||||
for _, item := range s.Posts {
|
for _, item := range s.Posts {
|
||||||
itime, _ := time.Parse("2006-01-02", item.Date)
|
itime, _ := time.Parse("2006-01-02", item.Date)
|
||||||
|
|
6
rss.go
6
rss.go
|
@ -20,7 +20,7 @@ func (s *Site) createFeed(w http.ResponseWriter, r *http.Request) {
|
||||||
err := s.rssFeed.WriteRss(w)
|
err := s.rssFeed.WriteRss(w)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
http.Error(w, "Internal server error", http.StatusInternalServerError)
|
http.Error(w, "Internal server error", http.StatusInternalServerError)
|
||||||
ln.Error(err, ln.F{
|
ln.Error(r.Context(), err, ln.F{
|
||||||
"remote_addr": r.RemoteAddr,
|
"remote_addr": r.RemoteAddr,
|
||||||
"action": "generating_rss",
|
"action": "generating_rss",
|
||||||
"uri": r.RequestURI,
|
"uri": r.RequestURI,
|
||||||
|
@ -36,7 +36,7 @@ func (s *Site) createAtom(w http.ResponseWriter, r *http.Request) {
|
||||||
err := s.rssFeed.WriteAtom(w)
|
err := s.rssFeed.WriteAtom(w)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
http.Error(w, "Internal server error", http.StatusInternalServerError)
|
http.Error(w, "Internal server error", http.StatusInternalServerError)
|
||||||
ln.Error(err, ln.F{
|
ln.Error(r.Context(), err, ln.F{
|
||||||
"remote_addr": r.RemoteAddr,
|
"remote_addr": r.RemoteAddr,
|
||||||
"action": "generating_atom",
|
"action": "generating_atom",
|
||||||
"uri": r.RequestURI,
|
"uri": r.RequestURI,
|
||||||
|
@ -54,7 +54,7 @@ func (s *Site) createJsonFeed(w http.ResponseWriter, r *http.Request) {
|
||||||
err := e.Encode(s.jsonFeed)
|
err := e.Encode(s.jsonFeed)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
http.Error(w, "Internal server error", http.StatusInternalServerError)
|
http.Error(w, "Internal server error", http.StatusInternalServerError)
|
||||||
ln.Error(err, ln.F{
|
ln.Error(r.Context(), err, ln.F{
|
||||||
"remote_addr": r.RemoteAddr,
|
"remote_addr": r.RemoteAddr,
|
||||||
"action": "generating_jsonfeed",
|
"action": "generating_jsonfeed",
|
||||||
"uri": r.RequestURI,
|
"uri": r.RequestURI,
|
||||||
|
|
Loading…
Reference in New Issue