крымские наработки
This commit is contained in:
parent
aec0bfc438
commit
a8633b828f
@ -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
89
app/util.go
Normal 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()
|
||||
}
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
@ -8,7 +8,7 @@ a {
|
||||
color: cadetblue;
|
||||
}
|
||||
a:hover {
|
||||
color: red;
|
||||
color: yellow;
|
||||
transition: 400ms;
|
||||
}
|
||||
header h1 {
|
||||
|
@ -34,7 +34,9 @@
|
||||
{{end}}
|
||||
<span>Published: <strong>{{.StringTime}}</strong>; Views: <strong>{{.Post.Deviation.Stats.Views}}</strong>; Favourites: <strong>{{.Post.Deviation.Stats.Favourites}}</strong>; Downloads: <strong>{{.Post.Deviation.Stats.Downloads}}</strong></span>
|
||||
{{if (ne .Post.Description "")}}
|
||||
<figcaption>
|
||||
{{.Post.Description}}
|
||||
</figcaption>
|
||||
{{end}}
|
||||
{{if (ne .Comments "")}}
|
||||
{{.Comments}}
|
||||
|
43
html/gruser.htm
Normal file
43
html/gruser.htm
Normal file
@ -0,0 +1,43 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>SkunkyArt | {{.GR.Owner.Username}}</title>
|
||||
<link rel="stylesheet" href="/gui/css/skunky.css">
|
||||
</head>
|
||||
<main>
|
||||
<header>
|
||||
<h1><a href="/">HOME</a> | <a href="/dd">DD</a></h1>
|
||||
<form method="get" action="/search">
|
||||
<input type="text" name="q" placeholder="Search for ..." autocomplete="off" autocapitalize="none" spellcheck="false">
|
||||
<select name="type">
|
||||
<option value="all">All</option>
|
||||
<option value="tag">Tag</option>
|
||||
</select>
|
||||
<button type="submit">Search!</button>
|
||||
</form>
|
||||
</header>
|
||||
<img src="/media/{{.GR.Owner.Username}}?type=a" width="30px" height="30px"> <b>{{.GR.Owner.Username}}</b>
|
||||
{{if (eq .About.A.Gender "male")}}
|
||||
♂️
|
||||
{{end}}
|
||||
{{if (eq .About.A.Gender "female")}}
|
||||
♀️
|
||||
{{end}}
|
||||
[<span title="UID">{{.GR.Gruser.ID}}</span>]
|
||||
[<span title="Registration date">{{.CreationDate}}</span>]
|
||||
<i title="User's Tag">"{{.GR.Extra.Tag}}"</i>
|
||||
|
||||
<h3 id="stats"><a href="#stats">#</a> Statistics</h3>
|
||||
<p>Favourites: <b>{{.GR.Extra.Stats.Favourites}}</b>; Deviations: <b>{{.GR.Extra.Stats.Deviations}}</b>; Watchers: <b>{{.GR.Extra.Stats.Watchers}}</b>
|
||||
<p>Watching: <b>{{.GR.Extra.Stats.Watching}}</b>; Pageviews: <b>{{.GR.Extra.Stats.Pageviews}}</b>; Comments Made: <b>{{.GR.Extra.Stats.CommentsMade}}</b>; Friends: <b>{{.GR.Extra.Stats.Friends}}</b></p>
|
||||
|
||||
<h3 id="interests"><a href="#interests">#</a> Interests</h3>
|
||||
{{.About.Interests}}
|
||||
|
||||
<h3 id="social"><a href="#social">#</a> Social Links</h3>
|
||||
{{.About.Social}}
|
||||
|
||||
<h3 id="about"><a href="#about">#</a> About me</h3>
|
||||
{{.About.DescriptionFormatted}}
|
||||
</main>
|
||||
</html>
|
Loading…
Reference in New Issue
Block a user