mirror of https://github.com/jlelse/GoBlog
Simplify
This commit is contained in:
parent
302e290ea2
commit
5e65fd6bd7
4
cache.go
4
cache.go
|
@ -137,7 +137,7 @@ func getCache(key string, next http.Handler, r *http.Request) (item *cacheItem)
|
|||
}
|
||||
if item == nil || item.expired() {
|
||||
// No cache available
|
||||
servertiming.FromContext(r.Context()).NewMetric("cacheMiss")
|
||||
servertiming.FromContext(r.Context()).NewMetric("cm")
|
||||
// Remove problematic headers
|
||||
r.Header.Del("If-Modified-Since")
|
||||
r.Header.Del("If-Unmodified-Since")
|
||||
|
@ -185,7 +185,7 @@ func getCache(key string, next http.Handler, r *http.Request) (item *cacheItem)
|
|||
cacheLru.Add(key, item)
|
||||
}
|
||||
} else {
|
||||
servertiming.FromContext(r.Context()).NewMetric("cache")
|
||||
servertiming.FromContext(r.Context()).NewMetric("c")
|
||||
}
|
||||
return item
|
||||
}
|
||||
|
|
32
render.go
32
render.go
|
@ -11,7 +11,6 @@ import (
|
|||
"os"
|
||||
"path"
|
||||
"path/filepath"
|
||||
"reflect"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
|
@ -47,9 +46,6 @@ var templateFunctions template.FuncMap
|
|||
|
||||
func initRendering() error {
|
||||
templateFunctions = template.FuncMap{
|
||||
"blog": func(blog string) *configBlog {
|
||||
return appConfig.Blogs[blog]
|
||||
},
|
||||
"menu": func(blog *configBlog, id string) *menu {
|
||||
return blog.Menus[id]
|
||||
},
|
||||
|
@ -133,36 +129,12 @@ func initRendering() error {
|
|||
nrd.Data = data[1]
|
||||
rd = &nrd
|
||||
}
|
||||
buf := new(bytes.Buffer)
|
||||
err := templates[templateName].ExecuteTemplate(buf, templateName, rd)
|
||||
var buf bytes.Buffer
|
||||
err := templates[templateName].ExecuteTemplate(&buf, templateName, rd)
|
||||
return template.HTML(buf.String()), err
|
||||
}
|
||||
return "", errors.New("wrong arguments")
|
||||
},
|
||||
"default": func(dflt interface{}, given ...interface{}) interface{} {
|
||||
if len(given) == 0 {
|
||||
return dflt
|
||||
}
|
||||
g := reflect.ValueOf(given[0])
|
||||
if !g.IsValid() {
|
||||
return dflt
|
||||
}
|
||||
set := false
|
||||
switch g.Kind() {
|
||||
case reflect.Bool:
|
||||
set = true
|
||||
case reflect.String, reflect.Array, reflect.Slice, reflect.Map:
|
||||
set = g.Len() != 0
|
||||
case reflect.Int:
|
||||
set = g.Int() != 0
|
||||
default:
|
||||
set = !g.IsNil()
|
||||
}
|
||||
if set {
|
||||
return given[0]
|
||||
}
|
||||
return dflt
|
||||
},
|
||||
"urlize": urlize,
|
||||
"sort": sortedStrings,
|
||||
"absolute": func(path string) string {
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
<div class="p-author h-card hide">
|
||||
{{ with .Picture }}<data class="u-photo" value="{{ . }}"></data>{{ end }}
|
||||
{{ if .Name }}
|
||||
<a href="{{ .Link | default "/" }}" class="p-name u-url" rel="me">{{ .Name }}</a>
|
||||
<a href="{{ with .Link }}{{ . }}{{ else }}/{{ end }}" class="p-name u-url" rel="me">{{ .Name }}</a>
|
||||
{{ end }}
|
||||
</div>
|
||||
{{ end }}
|
||||
|
|
|
@ -49,7 +49,7 @@ tags:
|
|||
<input type="hidden" name="editoraction" value="loadupdate">
|
||||
<select name="url" class="fw">
|
||||
{{ range $i, $draft := .Data.Drafts }}
|
||||
<option value="{{ absolute $draft.Path }}">{{ (title $draft) | default $draft.Path }}</option>
|
||||
<option value="{{ absolute $draft.Path }}">{{ with (title $draft) }}{{ . }}{{ else }}{{ $draft.Path }}{{ end }}</option>
|
||||
{{ end }}
|
||||
</select>
|
||||
<input class="fw" type="submit" value="{{ string .Blog.Lang "update" }}">
|
||||
|
|
|
@ -3,9 +3,9 @@
|
|||
{{ if .Data.Published }}<div>{{ string .Blog.Lang "publishedon" }} <time class="dt-published" datetime="{{ dateformat .Data.Published "2006-01-02T15:04:05Z07:00"}}">{{ isodate .Data.Published }}</time>{{ if $section }} in <a href="{{ blogrelative .Blog $section.Name }}">{{ $section.Title }}</a>{{ end }}</div>{{ end }}
|
||||
{{ if .Data.Updated }}<div>{{ string .Blog.Lang "updatedon" }} <time class="dt-updated" datetime="{{ dateformat .Data.Updated "2006-01-02T15:04:05Z07:00"}}">{{ isodate .Data.Updated }}</time></div>{{ end }}
|
||||
{{ if p .Data "replylink" }}
|
||||
<div>{{ string .Blog.Lang "replyto" }}: <a class="u-in-reply-to" href="{{ p .Data "replylink" }}" target="_blank" rel="noopener">{{ p .Data "replytitle" | default (p .Data "replylink") }}</a></div>
|
||||
<div>{{ string .Blog.Lang "replyto" }}: <a class="u-in-reply-to" href="{{ p .Data "replylink" }}" target="_blank" rel="noopener">{{ with (p .Data "replytitle") }}{{ . }}{{ else }}{{ p .Data "replylink" }}{{ end }}</a></div>
|
||||
{{ end }}
|
||||
{{ if p .Data "likelink" }}
|
||||
<div>{{ string .Blog.Lang "likeof" }}: <a class="u-like-of" href="{{ p .Data "likelink" }}" target="_blank" rel="noopener">{{ p .Data "liketitle" | default (p .Data "likelink") }}</a></div>
|
||||
<div>{{ string .Blog.Lang "likeof" }}: <a class="u-like-of" href="{{ p .Data "likelink" }}" target="_blank" rel="noopener">{{ with (p .Data "liketitle") }}{{ . }}{{ else }}{{ p .Data "likelink" }}{{ end }}</a></div>
|
||||
{{ end }}
|
||||
{{ end }}
|
Loading…
Reference in New Issue