крымские наработки

This commit is contained in:
lost+skunk 2024-06-27 14:51:46 +03:00
parent aec0bfc438
commit a8633b828f
7 changed files with 211 additions and 4 deletions

View file

@ -62,6 +62,9 @@ func Router() {
skunky.Search()
case "dd":
skunky.DD()
case "group":
skunky.GRUser()
case "media":
skunky.Emojitar(url)
case "about":

89
app/util.go Normal file
View file

@ -0,0 +1,89 @@
package app
import (
"encoding/json"
"strings"
"git.macaw.me/skunky/devianter"
)
type text struct {
TXT string
from int
to int
}
func ParseDescription(dscr devianter.Text) string {
var parseddescription strings.Builder
TagBuilder := func(tag string, content string) string {
if tag != "" {
var htm strings.Builder
htm.WriteString("<")
htm.WriteString(tag)
htm.WriteString(">")
htm.WriteString(content)
htm.WriteString("</")
htm.WriteString(tag)
htm.WriteString(">")
return htm.String()
}
return content
}
if description, dl := dscr.Html.Markup, len(dscr.Html.Markup); dl != 0 &&
description[0] == '{' &&
description[dl-1] == '}' {
var descr struct {
Blocks []struct {
Key, Text, Type string
InlineStyleRanges []struct {
Offset, Length int
Style string
}
}
}
e := json.Unmarshal([]byte(description), &descr)
err(e)
for _, x := range descr.Blocks {
ranges := make(map[int]text)
for i, rngs := range x.InlineStyleRanges {
var tag string
switch rngs.Style {
case "BOLD":
tag = "b"
case "UNDERLINE":
tag = "u"
case "ITALIC":
tag = "i"
}
fromto := rngs.Offset + rngs.Length
ranges[i] = text{
TXT: TagBuilder(tag, x.Text[rngs.Offset:fromto]),
from: rngs.Offset,
to: fromto,
}
}
for _, r := range ranges {
var tag string
switch x.Type {
case "header-two":
tag = "h2"
case "unstyled":
tag = "p"
}
parseddescription.WriteString(r.TXT)
parseddescription.WriteString(TagBuilder(tag, x.Text[r.to:]))
}
}
} else if dl != 0 {
parseddescription.WriteString(description)
}
return parseddescription.String()
}

View file

@ -9,6 +9,7 @@ import (
"strconv"
"strings"
"text/template"
"time"
"git.macaw.me/skunky/devianter"
)
@ -117,6 +118,68 @@ func (s skunkyart) NavBase(c dlist) string {
return list.String()
}
func (s skunkyart) GRUser() {
var group struct {
GR devianter.GRuser
CreationDate string
About struct {
A devianter.About
DescriptionFormatted string
Interests string
Social string
BG devianter.Deviation
}
}
if len(s.Query) < 1 {
s.httperr(400)
return
}
var g devianter.Group
g.Name = s.Query
group.GR = g.GroupFunc()
if g := group.GR; !g.Owner.Group {
for _, x := range g.Gruser.Page.Modules {
var about = group.About.A
if x.ModuleData.About.RegDate != 0 {
about = x.ModuleData.About
}
group.About.DescriptionFormatted = ParseDescription(about.Description)
for _, val := range x.ModuleData.About.Interests {
var interest strings.Builder
interest.WriteString(val.Label)
interest.WriteString(": <b>")
interest.WriteString(val.Value)
interest.WriteString("</b><br>")
group.About.Interests += interest.String()
}
for _, val := range x.ModuleData.About.SocialLinks {
var social strings.Builder
social.WriteString(`<a target="_blank" href="`)
social.WriteString(val.Value)
social.WriteString(`">`)
social.WriteString(val.Value)
social.WriteString("</a><br>")
group.About.Social += social.String()
}
if rd := x.ModuleData.About.RegDate; rd != 0 {
group.CreationDate = time.Unix(time.Now().Unix()-rd, 0).UTC().String()
}
}
} else {
}
s.exe("html/gruser.htm", &group)
}
func (s skunkyart) DeviationList(devs []devianter.Deviation, content ...dlist) string {
var list strings.Builder
list.WriteString(`<div class="content">`)
@ -171,6 +234,7 @@ func (s skunkyart) Deviation(author, postname string) {
id := re[len(re)-1]
post.Post = devianter.DeviationFunc(id, author)
post.Post.Description = ParseDescription(post.Post.Deviation.TextContent)
// время публикации
post.StringTime = post.Post.Deviation.PublishedTime.UTC().String()
@ -218,6 +282,7 @@ func (s skunkyart) Deviation(author, postname string) {
cmmts.WriteString(`">`)
cmmts.WriteString(x.User.Username)
cmmts.WriteString("</b></a> ")
if x.Parent > 0 {
cmmts.WriteString(` In reply to <a href="#`)
cmmts.WriteString(strconv.Itoa(x.Parent))
@ -232,6 +297,7 @@ func (s skunkyart) Deviation(author, postname string) {
cmmts.WriteString(" [")
cmmts.WriteString(x.Posted.UTC().String())
cmmts.WriteString("]<p>")
cmmts.WriteString(x.Comment)
cmmts.WriteString("<p>👍: ")
cmmts.WriteString(strconv.Itoa(x.Likes))
@ -263,7 +329,8 @@ func (s skunkyart) DD() {
func (s skunkyart) Search() {
// тут всё и так понятно
if s.Type == 'a' || s.Type == 't' || s.Type == 'g' {
switch s.Type {
case 'a', 't', 'g':
var srch struct {
Search devianter.Search
List string
@ -278,7 +345,7 @@ func (s skunkyart) Search() {
})
s.exe("html/search.htm", &srch)
} else {
default:
s.httperr(400)
}
}