Fix taxonomies, post order etc.

This commit is contained in:
Jan-Lukas Else 2020-09-19 14:56:31 +02:00
parent f38e8e5a20
commit bba5eaa078
5 changed files with 13 additions and 3 deletions

View File

@ -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)

View File

@ -70,6 +70,7 @@ func initRendering() {
return template.HTML(buf.String()), err
},
"urlize": urlize,
"sort": sortedStrings,
}
templates = make(map[string]*template.Template)

View File

@ -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>

View File

@ -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>

View File

@ -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
}