mirror of https://github.com/jlelse/GoBlog
Fix taxonomies, post order etc.
This commit is contained in:
parent
f38e8e5a20
commit
bba5eaa078
4
posts.go
4
posts.go
|
@ -186,7 +186,7 @@ func getPosts(context context.Context, config *postsRequestConfig) (posts []*Pos
|
|||
defaultSelection := "select p.path, coalesce(content, ''), coalesce(published, ''), coalesce(updated, ''), coalesce(parameter, ''), coalesce(value, '') "
|
||||
postsTable := "posts"
|
||||
if config.taxonomy != nil && len(config.taxonomyValue) > 0 {
|
||||
postsTable = "(select distinct p.* from " + postsTable + " p left outer join post_parameters pp on p.path = pp.path where pp.parameter = '" + config.taxonomy.Name + "' and pp.value = '" + config.taxonomyValue + "')"
|
||||
postsTable = "(select distinct p.* from " + postsTable + " p left outer join post_parameters pp on p.path = pp.path where pp.parameter = '" + config.taxonomy.Name + "' and lower(pp.value) = lower('" + config.taxonomyValue + "'))"
|
||||
}
|
||||
if len(config.sections) > 0 {
|
||||
postsTable = "(select * from " + postsTable + " where"
|
||||
|
@ -199,7 +199,7 @@ func getPosts(context context.Context, config *postsRequestConfig) (posts []*Pos
|
|||
postsTable += ")"
|
||||
}
|
||||
defaultTables := " from " + postsTable + " p left outer join post_parameters pp on p.path = pp.path "
|
||||
defaultSorting := " order by coalesce(p.updated, p.published) desc "
|
||||
defaultSorting := " order by p.published desc "
|
||||
if config.path != "" {
|
||||
query := defaultSelection + defaultTables + " where p.path=?" + defaultSorting
|
||||
rows, err = appDb.QueryContext(context, query, config.path)
|
||||
|
|
|
@ -70,6 +70,7 @@ func initRendering() {
|
|||
return template.HTML(buf.String()), err
|
||||
},
|
||||
"urlize": urlize,
|
||||
"sort": sortedStrings,
|
||||
}
|
||||
|
||||
templates = make(map[string]*template.Template)
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
{{ define "summary" }}
|
||||
<article>
|
||||
{{ with p . "title" }}<h2>{{ . }}</h2>{{ end }}
|
||||
{{ with .Published }}<p>{{ dateformat . "02. Jan 2006" }}</p>{{ end }}
|
||||
<p>{{ summary . }}</p>
|
||||
<a href="{{ .Path }}">View</a>
|
||||
</article>
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
{{ with .Taxonomy.Description }}{{ md . }}{{ end }}
|
||||
<ul>
|
||||
{{ $taxonomy := .Taxonomy.Name }}
|
||||
{{ range $i, $value := .TaxonomyValues }}
|
||||
{{ range $i, $value := (sort .TaxonomyValues) }}
|
||||
<li><a href="/{{ $taxonomy }}/{{ urlize . }}">{{ . }}</a></li>
|
||||
{{ end }}
|
||||
</ul>
|
||||
|
|
8
utils.go
8
utils.go
|
@ -1,6 +1,7 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"sort"
|
||||
"strings"
|
||||
)
|
||||
|
||||
|
@ -38,3 +39,10 @@ func firstSentences(value string, count int) string {
|
|||
}
|
||||
return value
|
||||
}
|
||||
|
||||
func sortedStrings(s []string) []string {
|
||||
sort.Slice(s, func(i, j int) bool {
|
||||
return strings.ToLower(s[i]) < strings.ToLower(s[j])
|
||||
})
|
||||
return s
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue