diff --git a/node/elastic.go b/node/elastic.go index 5e1b6f5..430ca1a 100644 --- a/node/elastic.go +++ b/node/elastic.go @@ -597,6 +597,7 @@ func (es ESConf) GetThreadsYear(pageNum int, echoes ...string) (posts []i2es.ESD } func (es ESConf) GetLatestPosts(sum int) []i2es.ESDoc { + log.Debug(sum) query := fmt.Sprintf(`{"sort": [{"date": {"order": "desc"}}, {"_score": {"order": "desc" }}], "size": %d}`, sum) log.Debugf("Do %s request", query) diff --git a/node/ssr.go b/node/ssr.go index 3836521..a5092ec 100644 --- a/node/ssr.go +++ b/node/ssr.go @@ -3,6 +3,8 @@ package node import ( "encoding/json" "net/http" + "regexp" + "strings" "time" "strconv" @@ -12,6 +14,10 @@ import ( log "github.com/sirupsen/logrus" ) +const ( + quotesRE = `^(\w+)?>(.*)$` +) + type ssr struct { es ESConf templatesDir string @@ -48,6 +54,36 @@ func (p *PageData) Dec() int { return p.PageNum - 1 } +func (p *PageData) RenderMessage(message string) (msg string) { + return parseQuotes(message) +} + +func parseQuotes(message string) string { + var parsed []string + r, err := regexp.Compile(quotesRE) + if err != nil { + log.Error(err) + return message + } + + for _, line := range strings.Split(message, "\n") { + if r.MatchString(line) { + author := r.FindAllStringSubmatch(line, 1) + quote := "
" + author[0][2] + "
" + if len(author) > 0 && author[0][1] != "" { + quote += `` + } + quote += "
" + + parsed = append(parsed, quote) + } else { + parsed = append(parsed, line) + } + } + + return strings.Join(parsed, "\n") +} + func (s *ssr) newPageData(page string, posts []i2es.ESDoc, num int, showPaginator bool) *PageData { return &PageData{ Echoes: s.es.GetEchoesList(), @@ -65,7 +101,12 @@ func (s *ssr) ssrRootHandler(w http.ResponseWriter, r *http.Request) { return } - if err := tpl.Execute(w, s.newPageData("feed", s.es.GetLatestPosts(50), 1, true)); err != nil { + posts := s.es.GetLatestPosts(50) + for i := range posts { + posts[i].Message = parseQuotes(posts[i].Message) + } + + if err := tpl.Execute(w, s.newPageData("feed", posts, 1, true)); err != nil { log.Error(err) } } @@ -120,6 +161,10 @@ func (s *ssr) threadViewHandler(w http.ResponseWriter, r *http.Request) { thread = posts[0].Subg } + for i := range posts { + posts[i].Message = parseQuotes(posts[i].Message) + } + if err := tpl.Execute(w, s.newPageData(thread, posts, 1, true)); err != nil { log.Error(err) } diff --git a/templates/common/style.html b/templates/common/style.html index 25ef569..906997f 100644 --- a/templates/common/style.html +++ b/templates/common/style.html @@ -92,6 +92,15 @@ background-color: #073642; } + .quote { + color: green; + border: 0; + border-right: 1px; + border-style: solid; + border-color: grey; + padding-right: 0.5em; + } + @media only screen and (max-width: 1000px) { .hideit { display: none;