[Static]: quotes initial

This commit is contained in:
Denis Zheleztsov 2021-04-11 12:35:09 +03:00
parent bf2c3cd5b0
commit 425e447765
3 changed files with 56 additions and 1 deletions

View File

@ -597,6 +597,7 @@ func (es ESConf) GetThreadsYear(pageNum int, echoes ...string) (posts []i2es.ESD
} }
func (es ESConf) GetLatestPosts(sum int) []i2es.ESDoc { func (es ESConf) GetLatestPosts(sum int) []i2es.ESDoc {
log.Debug(sum)
query := fmt.Sprintf(`{"sort": [{"date": {"order": "desc"}}, {"_score": {"order": "desc" }}], "size": %d}`, sum) query := fmt.Sprintf(`{"sort": [{"date": {"order": "desc"}}, {"_score": {"order": "desc" }}], "size": %d}`, sum)
log.Debugf("Do %s request", query) log.Debugf("Do %s request", query)

View File

@ -3,6 +3,8 @@ package node
import ( import (
"encoding/json" "encoding/json"
"net/http" "net/http"
"regexp"
"strings"
"time" "time"
"strconv" "strconv"
@ -12,6 +14,10 @@ import (
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
) )
const (
quotesRE = `^(\w+)?>(.*)$`
)
type ssr struct { type ssr struct {
es ESConf es ESConf
templatesDir string templatesDir string
@ -48,6 +54,36 @@ func (p *PageData) Dec() int {
return p.PageNum - 1 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 := "<figure class=\"text-end\"><blockquote class=\"blockquote quote\"><small>" + author[0][2] + "</small></blockquote>"
if len(author) > 0 && author[0][1] != "" {
quote += `<figcaption class="blockquote-footer">` + author[0][1] + `</figcaption>`
}
quote += "</figure>"
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 { func (s *ssr) newPageData(page string, posts []i2es.ESDoc, num int, showPaginator bool) *PageData {
return &PageData{ return &PageData{
Echoes: s.es.GetEchoesList(), Echoes: s.es.GetEchoesList(),
@ -65,7 +101,12 @@ func (s *ssr) ssrRootHandler(w http.ResponseWriter, r *http.Request) {
return 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) log.Error(err)
} }
} }
@ -120,6 +161,10 @@ func (s *ssr) threadViewHandler(w http.ResponseWriter, r *http.Request) {
thread = posts[0].Subg 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 { if err := tpl.Execute(w, s.newPageData(thread, posts, 1, true)); err != nil {
log.Error(err) log.Error(err)
} }

View File

@ -92,6 +92,15 @@
background-color: #073642; 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) { @media only screen and (max-width: 1000px) {
.hideit { .hideit {
display: none; display: none;